Skip to content

Commit 2383ab6

Browse files
committed
Replace atomic_or with atomic_add
1 parent d90737a commit 2383ab6

File tree

1 file changed

+7
-7
lines changed
  • src/backend/storage/file

1 file changed

+7
-7
lines changed

src/backend/storage/file/cfs.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -628,13 +628,12 @@ cfs_get_lock(char const* file_path)
628628
static void
629629
cfs_gc_lock(pg_atomic_uint32* lock)
630630
{
631-
uint32 count = pg_atomic_fetch_or_u32(lock, CFS_GC_LOCK);
631+
uint32 count = pg_atomic_fetch_add_u32(lock, CFS_GC_LOCK);
632632
long delay = CFS_LOCK_MIN_TIMEOUT;
633633

634-
while ((count & ~CFS_GC_LOCK) != 1)
634+
while ((count & (CFS_GC_LOCK-1)) != 1)
635635
{
636636
pg_usleep(delay);
637-
CHECK_FOR_INTERRUPTS();
638637
count = pg_atomic_read_u32(lock);
639638
if (delay < CFS_LOCK_MAX_TIMEOUT)
640639
{
@@ -650,7 +649,7 @@ cfs_gc_lock(pg_atomic_uint32* lock)
650649
static void cfs_gc_unlock(pg_atomic_uint32* lock)
651650
{
652651
pg_write_barrier();
653-
pg_atomic_fetch_and_u32(lock, ~CFS_GC_LOCK);
652+
pg_atomic_fetch_sub_u32(lock, CFS_GC_LOCK);
654653
}
655654

656655
/*
@@ -813,6 +812,7 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
813812
exit(1);
814813

815814
ResetLatch(MyLatch);
815+
CHECK_FOR_INTERRUPTS();
816816

817817
pg_atomic_fetch_add_u32(&cfs_state->n_active_gc, 1);
818818
}
@@ -1106,8 +1106,6 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
11061106
pg_atomic_write_u32(&newMap->hdr.physSize, newSize);
11071107
pg_atomic_write_u32(&newMap->hdr.virtSize, virtSize);
11081108

1109-
pg_atomic_write_u32(&newMap->gc_active, true); /* Indicate start of GC */
1110-
11111109
/* Persist copy of map file */
11121110
if (!cfs_write_file(md2, &newMap->hdr, sizeof(newMap->hdr)))
11131111
{
@@ -1132,9 +1130,11 @@ static bool cfs_gc_file(char* map_path, GC_CALL_KIND background)
11321130
md2 = -1;
11331131

11341132
/*
1135-
* Persist map with CFS_GC_LOCK set:
1133+
* Persist map with gc_active set:
11361134
* in case of crash we will know that map may be changed by GC
11371135
*/
1136+
pg_atomic_write_u32(&map->gc_active, true); /* Indicate start of GC */
1137+
11381138
if (cfs_msync(map) < 0)
11391139
{
11401140
elog(WARNING, "CFS failed to sync map %s: %m", map_path);

0 commit comments

Comments
 (0)