Use __atomic builtins only where they are supported

Use the newer __atomic builtins only with GCC >= 4.7. The older __sync
builtins are used elsewhere.
This commit is contained in:
Markus Mäkelä
2017-04-28 11:47:46 +03:00
parent 6a3d99afe5
commit 601976dede
2 changed files with 56 additions and 3 deletions

View File

@ -20,6 +20,17 @@
MXS_BEGIN_DECLS
/**
* Pre 4.7 GCC doesn't support the __atomic builtin functions. The older __sync
* builtins don't have proper store/load functionality so we use a somewhat ugly
* hack to emulate the store/load.
*/
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)
#ifndef MXS_USE_ATOMIC_BUILTINS
#define MXS_USE_ATOMIC_BUILTINS 1
#endif
#endif
/**
* Implementation of an atomic add operations for the GCC environment.
*
@ -76,7 +87,13 @@ void atomic_store_uint64(uint64_t *variable, uint64_t value);
static inline void atomic_synchronize()
{
#ifdef __GNUC__
#ifdef MXS_USE_ATOMIC_BUILTINS
__atomic_thread_fence(__ATOMIC_SEQ_CST);
#else
__sync_synchronize(); /* Memory barrier. */
#endif
#else
#error "No GNUC atomics available."
#endif