mirror of git://sourceware.org/git/glibc.git
atomic: Use builtin atomics with USE_ATOMIC_COMPILER_BUILTINS
Use builtin atomics for atomic_compare_and_exchange_* and atomic_exchange_and_add if USE_ATOMIC_COMPILER_BUILTINS is enabled. This allows removing target atomic-machine.h headers. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
This commit is contained in:
parent
5c522d7a58
commit
2a035debbb
|
|
@ -82,6 +82,36 @@
|
||||||
__atg2_result; \
|
__atg2_result; \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
#if USE_ATOMIC_COMPILER_BUILTINS
|
||||||
|
|
||||||
|
# undef atomic_compare_and_exchange_val_acq
|
||||||
|
# define atomic_compare_and_exchange_val_acq(mem, newval, oldval) \
|
||||||
|
({ \
|
||||||
|
__typeof (*(mem)) __atg3_old = (oldval); \
|
||||||
|
atomic_compare_exchange_acquire (mem, (void*)&__atg3_old, newval); \
|
||||||
|
__atg3_old; \
|
||||||
|
})
|
||||||
|
|
||||||
|
# undef atomic_compare_and_exchange_val_rel
|
||||||
|
# define atomic_compare_and_exchange_val_rel(mem, newval, oldval) \
|
||||||
|
({ \
|
||||||
|
__typeof (*(mem)) __atg3_old = (oldval); \
|
||||||
|
atomic_compare_exchange_release (mem, (void*)&__atg3_old, newval); \
|
||||||
|
__atg3_old; \
|
||||||
|
})
|
||||||
|
|
||||||
|
# undef atomic_compare_and_exchange_bool_acq
|
||||||
|
# define atomic_compare_and_exchange_bool_acq(mem, newval, oldval) \
|
||||||
|
({ \
|
||||||
|
__typeof (*(mem)) __atg3_old = (oldval); \
|
||||||
|
!atomic_compare_exchange_acquire (mem, (void*)&__atg3_old, newval); \
|
||||||
|
})
|
||||||
|
|
||||||
|
# undef atomic_exchange_and_add
|
||||||
|
# define atomic_exchange_and_add(mem, val) atomic_fetch_add_relaxed(mem,val)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Atomically store NEWVAL in *MEM if *MEM is equal to OLDVAL.
|
/* Atomically store NEWVAL in *MEM if *MEM is equal to OLDVAL.
|
||||||
Return the old *MEM value. */
|
Return the old *MEM value. */
|
||||||
|
|
@ -603,6 +633,19 @@ void __atomic_link_error (void);
|
||||||
__atomic_compare_exchange_n ((mem), (expected), (desired), 1, \
|
__atomic_compare_exchange_n ((mem), (expected), (desired), 1, \
|
||||||
__ATOMIC_RELEASE, __ATOMIC_RELAXED); })
|
__ATOMIC_RELEASE, __ATOMIC_RELAXED); })
|
||||||
|
|
||||||
|
# define atomic_compare_exchange_relaxed(mem, expected, desired) \
|
||||||
|
({ __atomic_check_size((mem)); \
|
||||||
|
__atomic_compare_exchange_n ((mem), (expected), (desired), 0, \
|
||||||
|
__ATOMIC_RELAXED, __ATOMIC_RELAXED); })
|
||||||
|
# define atomic_compare_exchange_acquire(mem, expected, desired) \
|
||||||
|
({ __atomic_check_size((mem)); \
|
||||||
|
__atomic_compare_exchange_n ((mem), (expected), (desired), 0, \
|
||||||
|
__ATOMIC_ACQUIRE, __ATOMIC_RELAXED); })
|
||||||
|
# define atomic_compare_exchange_release(mem, expected, desired) \
|
||||||
|
({ __atomic_check_size((mem)); \
|
||||||
|
__atomic_compare_exchange_n ((mem), (expected), (desired), 0, \
|
||||||
|
__ATOMIC_RELEASE, __ATOMIC_RELAXED); })
|
||||||
|
|
||||||
# define atomic_exchange_relaxed(mem, desired) \
|
# define atomic_exchange_relaxed(mem, desired) \
|
||||||
({ __atomic_check_size((mem)); \
|
({ __atomic_check_size((mem)); \
|
||||||
__atomic_exchange_n ((mem), (desired), __ATOMIC_RELAXED); })
|
__atomic_exchange_n ((mem), (desired), __ATOMIC_RELAXED); })
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue