Skip to content

Commit f3273e0

Browse files
committedJul 3, 2021
list-move: Use __atomic builtins
1 parent adcd020 commit f3273e0

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed
 

‎list-move/lockfree.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ typedef struct {
1616
void *freelist[QSBR_N_EPOCHS][QSBR_FREELIST_SIZE];
1717
} qsbr_pthread_data_t;
1818

19-
/* TODO: write with C11 Atomics */
20-
#define CAS(addr, oldv, newv) \
21-
__sync_bool_compare_and_swap((addr), (oldv), (newv))
22-
#define FETCH_AND_ADD(addr, v) __sync_fetch_and_add((addr), (v))
19+
#define CAS(addr, oldv, newv) \
20+
__atomic_compare_exchange((addr), &(oldv), &(newv), 0, __ATOMIC_RELAXED, \
21+
__ATOMIC_RELAXED)
22+
#define FETCH_AND_ADD(addr, v) __atomic_fetch_add((addr), (v), __ATOMIC_RELAXED)
2323
#define MEM_BARRIER() __sync_synchronize()
2424

2525
static long n_threads = 0;
@@ -285,7 +285,8 @@ static int lf_list_write_cs_exit(lf_list_pthread_data_t *lf_list_data)
285285
it_rec->epoch = epoch;
286286
}
287287

288-
if (CAS(&it_rec->rec_next, NULL, new_rec)) {
288+
const void *nullptr = NULL;
289+
if (CAS(&it_rec->rec_next, nullptr, new_rec)) {
289290
new_rec->epoch = epoch;
290291
new_rec->slots[0]->epoch = epoch;
291292
new_rec->slots[1]->epoch = epoch;

0 commit comments

Comments
 (0)
Please sign in to comment.