[glib: 4/4] Merge branch '1750-more-atomic-intrinsics' into 'master'
- From: Sebastian Dröge <sdroege src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 4/4] Merge branch '1750-more-atomic-intrinsics' into 'master'
- Date: Thu, 14 Nov 2019 13:41:27 +0000 (UTC)
commit 4dcad56fb2ff885cddcfa4cae23ef01ab0339512
Merge: d8b45684e 30dd30d05
Author: Sebastian Dröge <slomo coaxion net>
Date: Thu Nov 14 13:40:47 2019 +0000
Merge branch '1750-more-atomic-intrinsics' into 'master'
gatomic: Use new __atomic_*() intrinsics for all atomic operations
Closes #1750
See merge request GNOME/glib!1123
glib/gatomic.h | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++--
glib/tests/atomic.c | 6 ++++
tests/atomic-test.c | 63 -------------------------------------
tests/meson.build | 1 -
4 files changed, 94 insertions(+), 66 deletions(-)
---
diff --cc glib/gatomic.h
index 304e855b1,712553e69..092589454
--- a/glib/gatomic.h
+++ b/glib/gatomic.h
@@@ -115,30 -113,97 +115,116 @@@ G_END_DECL
#define g_atomic_pointer_set(atomic, newval) \
(G_GNUC_EXTENSION ({ \
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
- gpointer gaps_temp = (gpointer)(newval); \
+ __typeof__((atomic)) gaps_temp_atomic = (atomic); \
+ __typeof__(*(atomic)) gaps_temp_newval = (newval); \
(void) (0 ? (gpointer) *(atomic) : NULL); \
- __atomic_store ((gpointer *)(atomic), &gaps_temp, __ATOMIC_SEQ_CST); \
+ __atomic_store (gaps_temp_atomic, &gaps_temp_newval, __ATOMIC_SEQ_CST); \
}))
+#else /* if !defined(g_has_typeof) */
+#define g_atomic_pointer_get(atomic) \
+ (G_GNUC_EXTENSION ({ \
+ G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
+ gpointer gapg_temp_newval; \
+ gpointer *gapg_temp_atomic = (gpointer *)(atomic); \
+ __atomic_load (gapg_temp_atomic, &gapg_temp_newval, __ATOMIC_SEQ_CST); \
+ gapg_temp_newval; \
+ }))
+#define g_atomic_pointer_set(atomic, newval) \
+ (G_GNUC_EXTENSION ({ \
+ G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
+ gpointer *gaps_temp_atomic = (gpointer *)(atomic); \
+ gpointer gaps_temp_newval = (gpointer)(newval); \
+ (void) (0 ? (gpointer) *(atomic) : NULL); \
+ __atomic_store (gaps_temp_atomic, &gaps_temp_newval, __ATOMIC_SEQ_CST); \
+ }))
+#endif /* !defined(g_has_typeof) */
+ #define g_atomic_int_inc(atomic) \
+ (G_GNUC_EXTENSION ({ \
+ G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gint)); \
+ (void) (0 ? *(atomic) ^ *(atomic) : 1); \
+ (void) __atomic_fetch_add ((atomic), 1, __ATOMIC_SEQ_CST); \
+ }))
+ #define g_atomic_int_dec_and_test(atomic) \
+ (G_GNUC_EXTENSION ({ \
+ G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gint)); \
+ (void) (0 ? *(atomic) ^ *(atomic) : 1); \
+ __atomic_fetch_sub ((atomic), 1, __ATOMIC_SEQ_CST) == 1; \
+ }))
+ #define g_atomic_int_compare_and_exchange(atomic, oldval, newval) \
+ (G_GNUC_EXTENSION ({ \
+ gint gaicae_oldval = (oldval); \
+ G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gint)); \
+ (void) (0 ? *(atomic) ^ (newval) ^ (oldval) : 1); \
+ __atomic_compare_exchange_n ((atomic), &gaicae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST,
__ATOMIC_SEQ_CST) ? TRUE : FALSE; \
+ }))
+ #define g_atomic_int_add(atomic, val) \
+ (G_GNUC_EXTENSION ({ \
+ G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gint)); \
+ (void) (0 ? *(atomic) ^ (val) : 1); \
+ (gint) __atomic_fetch_add ((atomic), (val), __ATOMIC_SEQ_CST); \
+ }))
+ #define g_atomic_int_and(atomic, val) \
+ (G_GNUC_EXTENSION ({ \
+ G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gint)); \
+ (void) (0 ? *(atomic) ^ (val) : 1); \
+ (guint) __atomic_fetch_and ((atomic), (val), __ATOMIC_SEQ_CST); \
+ }))
+ #define g_atomic_int_or(atomic, val) \
+ (G_GNUC_EXTENSION ({ \
+ G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gint)); \
+ (void) (0 ? *(atomic) ^ (val) : 1); \
+ (guint) __atomic_fetch_or ((atomic), (val), __ATOMIC_SEQ_CST); \
+ }))
+ #define g_atomic_int_xor(atomic, val) \
+ (G_GNUC_EXTENSION ({ \
+ G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gint)); \
+ (void) (0 ? *(atomic) ^ (val) : 1); \
+ (guint) __atomic_fetch_xor ((atomic), (val), __ATOMIC_SEQ_CST); \
+ }))
+
+ #define g_atomic_pointer_compare_and_exchange(atomic, oldval, newval) \
+ (G_GNUC_EXTENSION ({ \
+ __typeof__ ((oldval)) gapcae_oldval = (oldval); \
+ G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
+ (void) (0 ? (gpointer) *(atomic) : NULL); \
+ __atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST,
__ATOMIC_SEQ_CST) ? TRUE : FALSE; \
+ }))
+ #define g_atomic_pointer_add(atomic, val) \
+ (G_GNUC_EXTENSION ({ \
+ G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
+ (void) (0 ? (gpointer) *(atomic) : NULL); \
+ (void) (0 ? (val) ^ (val) : 1); \
+ (gssize) __atomic_fetch_add ((atomic), (val), __ATOMIC_SEQ_CST); \
+ }))
+ #define g_atomic_pointer_and(atomic, val) \
+ (G_GNUC_EXTENSION ({ \
+ volatile gsize *gapa_atomic = (volatile gsize *) (atomic); \
+ G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
+ G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gsize)); \
+ (void) (0 ? (gpointer) *(atomic) : NULL); \
+ (void) (0 ? (val) ^ (val) : 1); \
+ (gsize) __atomic_fetch_and (gapa_atomic, (val), __ATOMIC_SEQ_CST); \
+ }))
+ #define g_atomic_pointer_or(atomic, val) \
+ (G_GNUC_EXTENSION ({ \
+ volatile gsize *gapo_atomic = (volatile gsize *) (atomic); \
+ G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
+ G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gsize)); \
+ (void) (0 ? (gpointer) *(atomic) : NULL); \
+ (void) (0 ? (val) ^ (val) : 1); \
+ (gsize) __atomic_fetch_or (gapo_atomic, (val), __ATOMIC_SEQ_CST); \
+ }))
+ #define g_atomic_pointer_xor(atomic, val) \
+ (G_GNUC_EXTENSION ({ \
+ volatile gsize *gapx_atomic = (volatile gsize *) (atomic); \
+ G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
+ G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gsize)); \
+ (void) (0 ? (gpointer) *(atomic) : NULL); \
+ (void) (0 ? (val) ^ (val) : 1); \
+ (gsize) __atomic_fetch_xor (gapx_atomic, (val), __ATOMIC_SEQ_CST); \
+ }))
+
#else /* defined(__ATOMIC_SEQ_CST) */
/* We want to achieve __ATOMIC_SEQ_CST semantics here. See
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]