mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-13 21:06:17 +01:00
Merge branch '1940-atomic-types' into 'master'
tests: Use pointers in calls to g_atomic_pointer_compare_and_exchange() Closes #1940 See merge request GNOME/glib!1234
This commit is contained in:
commit
9dc006cfc8
@ -85,9 +85,7 @@ G_END_DECLS
|
|||||||
#if defined(G_ATOMIC_LOCK_FREE) && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
|
#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 */
|
/* We prefer the new C11-style atomic extension of GCC if available */
|
||||||
/* FIXME: Temporarily disabled on FreeBSD due to CI failures:
|
#if defined(__ATOMIC_SEQ_CST)
|
||||||
* https://gitlab.gnome.org/GNOME/glib/issues/1940 */
|
|
||||||
#if defined(__ATOMIC_SEQ_CST) && !defined(__FreeBSD__)
|
|
||||||
|
|
||||||
#define g_atomic_int_get(atomic) \
|
#define g_atomic_int_get(atomic) \
|
||||||
(G_GNUC_EXTENSION ({ \
|
(G_GNUC_EXTENSION ({ \
|
||||||
@ -187,6 +185,7 @@ G_END_DECLS
|
|||||||
|
|
||||||
#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)); \
|
||||||
__typeof__ ((oldval)) gapcae_oldval = (oldval); \
|
__typeof__ ((oldval)) 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); \
|
||||||
|
@ -83,14 +83,14 @@ test_types (void)
|
|||||||
res = g_atomic_pointer_compare_and_exchange (&vp, &s, &s);
|
res = g_atomic_pointer_compare_and_exchange (&vp, &s, &s);
|
||||||
g_assert_false (res);
|
g_assert_false (res);
|
||||||
g_assert_true (vp == 0);
|
g_assert_true (vp == 0);
|
||||||
res = g_atomic_pointer_compare_and_exchange (&vp, 0, 0);
|
res = g_atomic_pointer_compare_and_exchange (&vp, NULL, NULL);
|
||||||
g_assert_true (res);
|
g_assert_true (res);
|
||||||
g_assert_true (vp == 0);
|
g_assert_true (vp == 0);
|
||||||
|
|
||||||
g_atomic_pointer_set (&ip, 0);
|
g_atomic_pointer_set (&ip, 0);
|
||||||
ip2 = g_atomic_pointer_get (&ip);
|
ip2 = g_atomic_pointer_get (&ip);
|
||||||
g_assert_true (ip2 == 0);
|
g_assert_true (ip2 == 0);
|
||||||
res = g_atomic_pointer_compare_and_exchange (&ip, 0, 0);
|
res = g_atomic_pointer_compare_and_exchange (&ip, NULL, NULL);
|
||||||
g_assert_true (res);
|
g_assert_true (res);
|
||||||
g_assert_true (ip == 0);
|
g_assert_true (ip == 0);
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ test_types (void)
|
|||||||
vp2 = (gpointer) g_atomic_pointer_get (&gs);
|
vp2 = (gpointer) g_atomic_pointer_get (&gs);
|
||||||
gs2 = (gsize) vp2;
|
gs2 = (gsize) vp2;
|
||||||
g_assert_cmpuint (gs2, ==, 0);
|
g_assert_cmpuint (gs2, ==, 0);
|
||||||
res = g_atomic_pointer_compare_and_exchange (&gs, 0, 0);
|
res = g_atomic_pointer_compare_and_exchange (&gs, NULL, NULL);
|
||||||
g_assert_true (res);
|
g_assert_true (res);
|
||||||
g_assert_cmpuint (gs, ==, 0);
|
g_assert_cmpuint (gs, ==, 0);
|
||||||
gs2 = (gsize) g_atomic_pointer_add (&gs, 5);
|
gs2 = (gsize) g_atomic_pointer_add (&gs, 5);
|
||||||
@ -191,14 +191,14 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
|||||||
res = g_atomic_pointer_compare_and_exchange (&vp, &s, &s);
|
res = g_atomic_pointer_compare_and_exchange (&vp, &s, &s);
|
||||||
g_assert_false (res);
|
g_assert_false (res);
|
||||||
g_assert_true (vp == 0);
|
g_assert_true (vp == 0);
|
||||||
res = g_atomic_pointer_compare_and_exchange (&vp, 0, 0);
|
res = g_atomic_pointer_compare_and_exchange (&vp, NULL, NULL);
|
||||||
g_assert_true (res);
|
g_assert_true (res);
|
||||||
g_assert_true (vp == 0);
|
g_assert_true (vp == 0);
|
||||||
|
|
||||||
g_atomic_pointer_set (&ip, 0);
|
g_atomic_pointer_set (&ip, 0);
|
||||||
ip2 = g_atomic_pointer_get (&ip);
|
ip2 = g_atomic_pointer_get (&ip);
|
||||||
g_assert_true (ip2 == 0);
|
g_assert_true (ip2 == 0);
|
||||||
res = g_atomic_pointer_compare_and_exchange (&ip, 0, 0);
|
res = g_atomic_pointer_compare_and_exchange (&ip, NULL, NULL);
|
||||||
g_assert_true (res);
|
g_assert_true (res);
|
||||||
g_assert_true (ip == 0);
|
g_assert_true (ip == 0);
|
||||||
|
|
||||||
@ -206,7 +206,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
|||||||
vp = g_atomic_pointer_get (&gs);
|
vp = g_atomic_pointer_get (&gs);
|
||||||
gs2 = (gsize) vp;
|
gs2 = (gsize) vp;
|
||||||
g_assert_cmpuint (gs2, ==, 0);
|
g_assert_cmpuint (gs2, ==, 0);
|
||||||
res = g_atomic_pointer_compare_and_exchange (&gs, 0, 0);
|
res = g_atomic_pointer_compare_and_exchange (&gs, NULL, NULL);
|
||||||
g_assert_true (res);
|
g_assert_true (res);
|
||||||
g_assert_cmpuint (gs, ==, 0);
|
g_assert_cmpuint (gs, ==, 0);
|
||||||
gs2 = (gsize) g_atomic_pointer_add (&gs, 5);
|
gs2 = (gsize) g_atomic_pointer_add (&gs, 5);
|
||||||
|
Loading…
Reference in New Issue
Block a user