atomic: drop __sync builtins

The correctness of the stdatomic.h emulation via the __sync builtins is
questionable, and we've been relying on exact stdatomic semantics for a
while, so just get rid of it. Compilers which support __sync but not
stdatomic.h will use to the slow mutex fallback.

Not sure about the __atomic builtins. It doesn't seem to harm either, so
leave it for now.
This commit is contained in:
wm4 2017-01-27 09:15:32 +01:00
parent 70411f2709
commit c3205d294e
2 changed files with 1 additions and 28 deletions

View File

@ -61,25 +61,6 @@ typedef struct { volatile unsigned long long v; } atomic_ullong;
__atomic_compare_exchange_n(&(a)->v, b, c, 0, __ATOMIC_SEQ_CST, \
__ATOMIC_SEQ_CST)
#elif HAVE_SYNC_BUILTINS
#define atomic_load(p) \
__sync_fetch_and_add(&(p)->v, 0)
#define atomic_store(p, val) \
(__sync_synchronize(), (p)->v = (val), __sync_synchronize())
#define atomic_fetch_add(a, b) \
__sync_fetch_and_add(&(a)->v, b)
#define atomic_fetch_and(a, b) \
__sync_fetch_and_and(&(a)->v, b)
#define atomic_fetch_or(a, b) \
__sync_fetch_and_or(&(a)->v, b)
// Assumes __sync_val_compare_and_swap is "strong" (using the C11 meaning).
#define atomic_compare_exchange_strong(p, old, new) \
({ __typeof__((p)->v) val_ = __sync_val_compare_and_swap(&(p)->v, *(old), new); \
bool ok_ = val_ == *(old); \
if (!ok_) *(old) = val_; \
ok_; })
#elif defined(__GNUC__)
#include <pthread.h>

10
wscript
View File

@ -178,20 +178,12 @@ main_dependencies = [
'int64_t test = 0;'
'test = __atomic_add_fetch(&test, 1, __ATOMIC_SEQ_CST)')),
'deps_neg': [ 'stdatomic' ],
}, {
'name': 'sync-builtins',
'desc': 'compiler support for __sync built-ins',
'func': check_statement('stdint.h',
'int64_t test = 0;'
'__typeof__(test) x = ({int a = 1; a;});'
'test = __sync_add_and_fetch(&test, 1)'),
'deps_neg': [ 'stdatomic', 'atomic-builtins' ],
}, {
'name': 'atomics',
'desc': 'stdatomic.h support or emulation',
'func': check_true,
'req': True,
'deps_any': ['stdatomic', 'atomic-builtins', 'sync-builtins', 'gnuc'],
'deps_any': ['stdatomic', 'atomic-builtins', 'gnuc'],
}, {
'name': 'c11-tls',
'desc': 'C11 TLS support',