mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
Merge branch '1843-tsan-atomic-clang-fix' into 'master'
gatomic: Fix false positive with Clang+TSAN Closes #1843 See merge request GNOME/glib!1006
This commit is contained in:
commit
3ad375a629
@ -96,15 +96,6 @@
|
||||
|
||||
#if defined (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
|
||||
|
||||
#if defined(__ATOMIC_SEQ_CST) && !defined(__clang__)
|
||||
/* The implementation used in this code path in gatomic.h assumes
|
||||
* 4-byte int */
|
||||
G_STATIC_ASSERT (sizeof (gint) == 4);
|
||||
|
||||
/* The implementations in gatomic.h assume 4- or 8-byte pointers */
|
||||
G_STATIC_ASSERT (sizeof (void *) == 4 || sizeof (void *) == 8);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* g_atomic_int_get:
|
||||
* @atomic: a pointer to a #gint or #guint
|
||||
|
@ -85,61 +85,39 @@ G_END_DECLS
|
||||
#if defined(G_ATOMIC_LOCK_FREE) && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
|
||||
|
||||
/* We prefer the new C11-style atomic extension of GCC if available */
|
||||
#if defined(__ATOMIC_SEQ_CST) && !defined(__clang__)
|
||||
|
||||
/* This assumes sizeof(int) is 4: gatomic.c statically
|
||||
* asserts that (using G_STATIC_ASSERT at top-level in a header was
|
||||
* problematic, see #730932) */
|
||||
#if defined(__ATOMIC_SEQ_CST)
|
||||
|
||||
#define g_atomic_int_get(atomic) \
|
||||
(G_GNUC_EXTENSION ({ \
|
||||
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gint)); \
|
||||
gint gaig_temp; \
|
||||
(void) (0 ? *(atomic) ^ *(atomic) : 1); \
|
||||
(gint) __atomic_load_4 ((atomic), __ATOMIC_SEQ_CST); \
|
||||
__atomic_load ((gint *)(atomic), &gaig_temp, __ATOMIC_SEQ_CST); \
|
||||
(gint) gaig_temp; \
|
||||
}))
|
||||
#define g_atomic_int_set(atomic, newval) \
|
||||
(G_GNUC_EXTENSION ({ \
|
||||
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gint)); \
|
||||
gint gais_temp = (gint) (newval); \
|
||||
(void) (0 ? *(atomic) ^ (newval) : 1); \
|
||||
__atomic_store_4 ((atomic), (newval), __ATOMIC_SEQ_CST); \
|
||||
__atomic_store ((gint *)(atomic), &gais_temp, __ATOMIC_SEQ_CST); \
|
||||
}))
|
||||
|
||||
#if GLIB_SIZEOF_VOID_P == 8
|
||||
|
||||
#define g_atomic_pointer_get(atomic) \
|
||||
(G_GNUC_EXTENSION ({ \
|
||||
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
|
||||
guint64 gapg_temp = __atomic_load_8 ((atomic), __ATOMIC_SEQ_CST); \
|
||||
(gpointer) gapg_temp; \
|
||||
gpointer gapg_temp; \
|
||||
__atomic_load ((gpointer *)(atomic), &gapg_temp, __ATOMIC_SEQ_CST); \
|
||||
gapg_temp; \
|
||||
}))
|
||||
#define g_atomic_pointer_set(atomic, newval) \
|
||||
(G_GNUC_EXTENSION ({ \
|
||||
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
|
||||
gpointer gaps_temp = (gpointer)(newval); \
|
||||
(void) (0 ? (gpointer) *(atomic) : NULL); \
|
||||
__atomic_store_8 ((atomic), (gsize) (newval), __ATOMIC_SEQ_CST); \
|
||||
__atomic_store ((gpointer *)(atomic), &gaps_temp, __ATOMIC_SEQ_CST); \
|
||||
}))
|
||||
|
||||
#else /* GLIB_SIZEOF_VOID_P == 8 */
|
||||
|
||||
/* This assumes that if sizeof(void *) is not 8, then it is 4:
|
||||
* gatomic.c statically asserts that (using G_STATIC_ASSERT
|
||||
* at top-level in a header was problematic, see #730932) */
|
||||
|
||||
#define g_atomic_pointer_get(atomic) \
|
||||
(G_GNUC_EXTENSION ({ \
|
||||
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
|
||||
guint32 gapg_temp = __atomic_load_4 ((atomic), __ATOMIC_SEQ_CST); \
|
||||
(gpointer) gapg_temp; \
|
||||
}))
|
||||
#define g_atomic_pointer_set(atomic, newval) \
|
||||
(G_GNUC_EXTENSION ({ \
|
||||
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
|
||||
(void) (0 ? (gpointer) *(atomic) : NULL); \
|
||||
__atomic_store_4 ((atomic), (gsize) (newval), __ATOMIC_SEQ_CST); \
|
||||
}))
|
||||
|
||||
#endif /* GLIB_SIZEOF_VOID_P == 8 */
|
||||
|
||||
#else /* defined(__ATOMIC_SEQ_CST) */
|
||||
|
||||
#define g_atomic_int_get(atomic) \
|
||||
|
Loading…
Reference in New Issue
Block a user