@@ -628,13 +628,12 @@ cfs_get_lock(char const* file_path)
628
628
static void
629
629
cfs_gc_lock (pg_atomic_uint32 * lock )
630
630
{
631
- uint32 count = pg_atomic_fetch_or_u32 (lock , CFS_GC_LOCK );
631
+ uint32 count = pg_atomic_fetch_add_u32 (lock , CFS_GC_LOCK );
632
632
long delay = CFS_LOCK_MIN_TIMEOUT ;
633
633
634
- while ((count & ~ CFS_GC_LOCK ) != 1 )
634
+ while ((count & ( CFS_GC_LOCK - 1 ) ) != 1 )
635
635
{
636
636
pg_usleep (delay );
637
- CHECK_FOR_INTERRUPTS ();
638
637
count = pg_atomic_read_u32 (lock );
639
638
if (delay < CFS_LOCK_MAX_TIMEOUT )
640
639
{
@@ -650,7 +649,7 @@ cfs_gc_lock(pg_atomic_uint32* lock)
650
649
static void cfs_gc_unlock (pg_atomic_uint32 * lock )
651
650
{
652
651
pg_write_barrier ();
653
- pg_atomic_fetch_and_u32 (lock , ~ CFS_GC_LOCK );
652
+ pg_atomic_fetch_sub_u32 (lock , CFS_GC_LOCK );
654
653
}
655
654
656
655
/*
@@ -813,6 +812,7 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
813
812
exit (1 );
814
813
815
814
ResetLatch (MyLatch );
815
+ CHECK_FOR_INTERRUPTS ();
816
816
817
817
pg_atomic_fetch_add_u32 (& cfs_state -> n_active_gc , 1 );
818
818
}
@@ -1106,8 +1106,6 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
1106
1106
pg_atomic_write_u32 (& newMap -> hdr .physSize , newSize );
1107
1107
pg_atomic_write_u32 (& newMap -> hdr .virtSize , virtSize );
1108
1108
1109
- pg_atomic_write_u32 (& newMap -> gc_active , true); /* Indicate start of GC */
1110
-
1111
1109
/* Persist copy of map file */
1112
1110
if (!cfs_write_file (md2 , & newMap -> hdr , sizeof (newMap -> hdr )))
1113
1111
{
@@ -1132,9 +1130,11 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
1132
1130
md2 = -1 ;
1133
1131
1134
1132
/*
1135
- * Persist map with CFS_GC_LOCK set:
1133
+ * Persist map with gc_active set:
1136
1134
* in case of crash we will know that map may be changed by GC
1137
1135
*/
1136
+ pg_atomic_write_u32 (& map -> gc_active , true); /* Indicate start of GC */
1137
+
1138
1138
if (cfs_msync (map ) < 0 )
1139
1139
{
1140
1140
elog (WARNING , "CFS failed to sync map %s: %m" , map_path );
0 commit comments