43 lines
1.7 KiB
Diff
43 lines
1.7 KiB
Diff
Use C11 style atomic builtins instead of the legacy __sync primitives
|
|
|
|
This is because unlike legacy __sync stuff, __atomic_* can make use of
|
|
libatomic on any arbitrary platform, while on e.g. ppc32 and mips,
|
|
__sync_val_compare_and_swap_8 and so on are not available at all.
|
|
|
|
--- a/src/sb_ck_pr.h
|
|
+++ b/src/sb_ck_pr.h
|
|
@@ -118,7 +118,8 @@ CK_PR_LOAD_S(64, uint64_t)
|
|
ck_pr_cas_##S(M *target, T compare, T set) \
|
|
{ \
|
|
bool z; \
|
|
- z = __sync_bool_compare_and_swap((T *)target, compare, set); \
|
|
+ z = __atomic_compare_exchange((T *)target, &compare, &set, \
|
|
+ false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \
|
|
return z; \
|
|
}
|
|
|
|
@@ -133,9 +134,11 @@ CK_PR_CAS_S(64, uint64_t)
|
|
CK_CC_INLINE static bool \
|
|
ck_pr_cas_##S##_value(T *target, T compare, T set, T *v) \
|
|
{ \
|
|
- set = __sync_val_compare_and_swap(target, compare, set);\
|
|
- *v = set; \
|
|
- return (set == compare); \
|
|
+ bool z; \
|
|
+ z = __atomic_compare_exchange(target, &compare, &set, false, \
|
|
+ __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \
|
|
+ *v = compare; \
|
|
+ return z; \
|
|
}
|
|
|
|
CK_PR_CAS_O(64, uint64_t)
|
|
@@ -149,7 +152,7 @@ CK_PR_CAS_O(64, uint64_t)
|
|
CK_CC_INLINE static void \
|
|
ck_pr_##K##_##S(M *target, T d) \
|
|
{ \
|
|
- d = __sync_fetch_and_##K((T *)target, d); \
|
|
+ d = __atomic_fetch_##K((T *)target, d, __ATOMIC_SEQ_CST); \
|
|
return; \
|
|
}
|
|
|