mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-11 03:46:17 +01:00
Merge branch 'atomic-take2' into 'master'
atomic: Fix type check of g_atomic_pointer_compare_and_exchange() See merge request GNOME/glib!1919
This commit is contained in:
commit
f67b12467b
@ -182,6 +182,25 @@ G_END_DECLS
|
||||
(void) (0 ? *(atomic) ^ (val) : 1); \
|
||||
(guint) __atomic_fetch_xor ((atomic), (val), __ATOMIC_SEQ_CST); \
|
||||
}))
|
||||
|
||||
#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) \
|
||||
(G_GNUC_EXTENSION ({ \
|
||||
G_STATIC_ASSERT (sizeof (oldval) == sizeof (gpointer)); \
|
||||
glib_typeof (*(atomic)) 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; \
|
||||
}))
|
||||
#else /* if !(defined(glib_typeof) && defined(__cplusplus) && __cplusplus >= 201103L) */
|
||||
#define g_atomic_pointer_compare_and_exchange(atomic, oldval, newval) \
|
||||
(G_GNUC_EXTENSION ({ \
|
||||
G_STATIC_ASSERT (sizeof (oldval) == sizeof (gpointer)); \
|
||||
@ -190,6 +209,7 @@ 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; \
|
||||
}))
|
||||
#endif /* defined(glib_typeof) */
|
||||
#define g_atomic_pointer_add(atomic, val) \
|
||||
(G_GNUC_EXTENSION ({ \
|
||||
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
|
||||
|
Loading…
Reference in New Issue
Block a user