builtin_24_atomic_lock_free.c (736B)
1 /* Lock-free atomics are sized against the native word, not a fixed 64 bits: 2 * an 8-byte atomic is lock-free on a 64-bit target but not on rv32 (which has 3 * no 64-bit AMO). Drive the size checks from the pointer width (the native 4 * atomic word: 4 on ilp32, 8 on lp64) so the same .expected holds on both. A 5 * width strictly wider than the word is never lock-free anywhere. */ 6 int test_main(void) { 7 int x = 0; 8 int score = 0; 9 if (__atomic_always_lock_free(1, &x)) score += 1; 10 if (__atomic_always_lock_free(2, &x)) score += 2; 11 if (__atomic_always_lock_free(4, &x)) score += 4; 12 if (__atomic_is_lock_free(sizeof(void*), &x)) score += 8; 13 if (!__atomic_always_lock_free(2 * sizeof(void*), &x)) score += 27; 14 return score; 15 }