mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-20 07:38:54 +02:00
atomic: Fix type check of g_atomic_pointer_compare_and_exchange()
This commit is contained in:
@@ -183,16 +183,24 @@ G_END_DECLS
|
|||||||
(guint) __atomic_fetch_xor ((atomic), (val), __ATOMIC_SEQ_CST); \
|
(guint) __atomic_fetch_xor ((atomic), (val), __ATOMIC_SEQ_CST); \
|
||||||
}))
|
}))
|
||||||
|
|
||||||
#if defined(glib_typeof)
|
#if defined(glib_typeof) && defined(__cplusplus) && __cplusplus >= 201103L
|
||||||
|
/* This is typesafe because we check we can assign oldval to the type of
|
||||||
|
* (*atomic). Unfortunately it can only be done in C++ because gcc/clang warn
|
||||||
|
* when atomic is volatile and not oldval, or when atomic is gsize* and oldval
|
||||||
|
* is NULL. Note that clang++ force us to be typesafe because it is an error if the 2nd
|
||||||
|
* argument of __atomic_compare_exchange_n() has a different type than the
|
||||||
|
* first.
|
||||||
|
* https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1919
|
||||||
|
* https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1715#note_1024120. */
|
||||||
#define g_atomic_pointer_compare_and_exchange(atomic, oldval, newval) \
|
#define g_atomic_pointer_compare_and_exchange(atomic, oldval, newval) \
|
||||||
(G_GNUC_EXTENSION ({ \
|
(G_GNUC_EXTENSION ({ \
|
||||||
G_STATIC_ASSERT (sizeof (oldval) == sizeof (gpointer)); \
|
G_STATIC_ASSERT (sizeof (oldval) == sizeof (gpointer)); \
|
||||||
glib_typeof ((oldval)) gapcae_oldval = (oldval); \
|
glib_typeof (*(atomic)) gapcae_oldval = (oldval); \
|
||||||
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
|
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
|
||||||
(void) (0 ? (gpointer) *(atomic) : NULL); \
|
(void) (0 ? (gpointer) *(atomic) : NULL); \
|
||||||
__atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
|
__atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
|
||||||
}))
|
}))
|
||||||
#else /* if !defined(glib_typeof) */
|
#else /* if !(defined(glib_typeof) && defined(__cplusplus) && __cplusplus >= 201103L) */
|
||||||
#define g_atomic_pointer_compare_and_exchange(atomic, oldval, newval) \
|
#define g_atomic_pointer_compare_and_exchange(atomic, oldval, newval) \
|
||||||
(G_GNUC_EXTENSION ({ \
|
(G_GNUC_EXTENSION ({ \
|
||||||
G_STATIC_ASSERT (sizeof (oldval) == sizeof (gpointer)); \
|
G_STATIC_ASSERT (sizeof (oldval) == sizeof (gpointer)); \
|
||||||
|
Reference in New Issue
Block a user