mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-13 15:56:23 +01:00
gthread: Port native mutex to Clang
And other toolchains that support stdatomic.
This commit is contained in:
parent
01b77666bc
commit
f1a1e84dda
@ -72,8 +72,8 @@
|
|||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* clang defines __ATOMIC_SEQ_CST but doesn't support the GCC extension */
|
#if defined(HAVE_FUTEX) && \
|
||||||
#if defined(HAVE_FUTEX) && defined(__ATOMIC_SEQ_CST) && !defined(__clang__)
|
(defined(HAVE_STDATOMIC_H) || defined(__ATOMIC_SEQ_CST))
|
||||||
#define USE_NATIVE_MUTEX
|
#define USE_NATIVE_MUTEX
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1401,6 +1401,23 @@ g_system_thread_set_name (const gchar *name)
|
|||||||
* purposes...
|
* purposes...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_STDATOMIC_H
|
||||||
|
|
||||||
|
#include <stdatomic.h>
|
||||||
|
|
||||||
|
#define exchange_acquire(ptr, new) \
|
||||||
|
atomic_exchange_explicit((atomic_uint *) (ptr), (new), __ATOMIC_ACQUIRE)
|
||||||
|
#define compare_exchange_acquire(ptr, old, new) \
|
||||||
|
atomic_compare_exchange_strong_explicit((atomic_uint *) (ptr), (old), (new), \
|
||||||
|
__ATOMIC_ACQUIRE, __ATOMIC_RELAXED)
|
||||||
|
|
||||||
|
#define exchange_release(ptr, new) \
|
||||||
|
atomic_exchange_explicit((atomic_uint *) (ptr), (new), __ATOMIC_RELEASE)
|
||||||
|
#define store_release(ptr, new) \
|
||||||
|
atomic_store_explicit((atomic_uint *) (ptr), (new), __ATOMIC_RELEASE)
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
#define exchange_acquire(ptr, new) \
|
#define exchange_acquire(ptr, new) \
|
||||||
__atomic_exchange_4((ptr), (new), __ATOMIC_ACQUIRE)
|
__atomic_exchange_4((ptr), (new), __ATOMIC_ACQUIRE)
|
||||||
#define compare_exchange_acquire(ptr, old, new) \
|
#define compare_exchange_acquire(ptr, old, new) \
|
||||||
@ -1411,6 +1428,8 @@ g_system_thread_set_name (const gchar *name)
|
|||||||
#define store_release(ptr, new) \
|
#define store_release(ptr, new) \
|
||||||
__atomic_store_4((ptr), (new), __ATOMIC_RELEASE)
|
__atomic_store_4((ptr), (new), __ATOMIC_RELEASE)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Our strategy for the mutex is pretty simple:
|
/* Our strategy for the mutex is pretty simple:
|
||||||
*
|
*
|
||||||
* 0: not in use
|
* 0: not in use
|
||||||
|
@ -275,6 +275,7 @@ headers = [
|
|||||||
'pwd.h',
|
'pwd.h',
|
||||||
'sched.h',
|
'sched.h',
|
||||||
'spawn.h',
|
'spawn.h',
|
||||||
|
'stdatomic.h',
|
||||||
'stdint.h',
|
'stdint.h',
|
||||||
'stdlib.h',
|
'stdlib.h',
|
||||||
'string.h',
|
'string.h',
|
||||||
|
Loading…
Reference in New Issue
Block a user