From a1847d0d038d70054dd7ee91d6e3ce4d42c93c7a Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Wed, 14 Oct 2020 13:35:34 -0400 Subject: [PATCH] gatomic: Check if glib_typeof() is defined before using it --- glib/gatomic.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/glib/gatomic.h b/glib/gatomic.h index 7ab11a5d0..bb1435c70 100644 --- a/glib/gatomic.h +++ b/glib/gatomic.h @@ -183,6 +183,7 @@ G_END_DECLS (guint) __atomic_fetch_xor ((atomic), (val), __ATOMIC_SEQ_CST); \ })) +#if defined(glib_typeof) #define g_atomic_pointer_compare_and_exchange(atomic, oldval, newval) \ (G_GNUC_EXTENSION ({ \ G_STATIC_ASSERT (sizeof (oldval) == sizeof (gpointer)); \ @@ -191,6 +192,16 @@ G_END_DECLS (void) (0 ? (gpointer) *(atomic) : NULL); \ __atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \ })) +#else /* if !defined(glib_typeof) */ +#define g_atomic_pointer_compare_and_exchange(atomic, oldval, newval) \ + (G_GNUC_EXTENSION ({ \ + G_STATIC_ASSERT (sizeof (oldval) == sizeof (gpointer)); \ + gpointer gapcae_oldval = (gpointer)(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; \ + })) +#endif /* defined(glib_typeof) */ #define g_atomic_pointer_add(atomic, val) \ (G_GNUC_EXTENSION ({ \ G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \ @@ -283,6 +294,7 @@ G_END_DECLS __asm__ __volatile__ ("" : : : "memory"); \ gapg_result; \ })) +#if defined(glib_typeof) #define g_atomic_pointer_set(atomic, newval) \ (G_GNUC_EXTENSION ({ \ G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \ @@ -291,6 +303,16 @@ G_END_DECLS __asm__ __volatile__ ("" : : : "memory"); \ *(atomic) = (glib_typeof (*(atomic))) (gsize) (newval); \ })) +#else /* if !defined(glib_typeof) */ +#define g_atomic_pointer_set(atomic, newval) \ + (G_GNUC_EXTENSION ({ \ + G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \ + (void) (0 ? (gpointer) *(atomic) : NULL); \ + __sync_synchronize (); \ + __asm__ __volatile__ ("" : : : "memory"); \ + *(atomic) = (gpointer) (gsize) (newval); \ + })) +#endif /* defined(glib_typeof) */ #define g_atomic_int_inc(atomic) \ (G_GNUC_EXTENSION ({ \ @@ -408,6 +430,6 @@ G_END_DECLS #define g_atomic_pointer_xor(atomic, val) \ (g_atomic_pointer_xor ((atomic), (gsize) (val))) -#endif /* defined(__GNUC__) && defined(G_ATOMIC_OP_USE_GCC_BUILTINS) */ +#endif /* defined(G_ATOMIC_LOCK_FREE) && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) */ #endif /* __G_ATOMIC_H__ */