1
#undef G_DISABLE_ASSERT
6
/* Obviously we can't test that the operations are atomic, but we can
7
* at least test, that they do, what they ought to do */
15
gpointer atomic_pointer = NULL;
16
gpointer biggest_pointer = (gpointer)((gsize)atomic_pointer - 1);
18
for (i = 0; i < 15; i++)
19
g_atomic_int_inc (&atomic);
20
g_assert (atomic == 10);
21
for (i = 0; i < 9; i++)
22
g_assert (!g_atomic_int_dec_and_test (&atomic));
23
g_assert (g_atomic_int_dec_and_test (&atomic));
24
g_assert (atomic == 0);
26
g_assert (g_atomic_int_exchange_and_add (&atomic, 5) == 0);
27
g_assert (atomic == 5);
29
g_assert (g_atomic_int_exchange_and_add (&atomic, -10) == 5);
30
g_assert (atomic == -5);
32
g_atomic_int_add (&atomic, 20);
33
g_assert (atomic == 15);
35
g_atomic_int_add (&atomic, -35);
36
g_assert (atomic == -20);
38
g_assert (atomic == g_atomic_int_get (&atomic));
40
g_assert (g_atomic_int_compare_and_exchange (&atomic, -20, 20));
41
g_assert (atomic == 20);
43
g_assert (!g_atomic_int_compare_and_exchange (&atomic, 42, 12));
44
g_assert (atomic == 20);
46
g_assert (g_atomic_int_compare_and_exchange (&atomic, 20, G_MAXINT));
47
g_assert (atomic == G_MAXINT);
49
g_assert (g_atomic_int_compare_and_exchange (&atomic, G_MAXINT, G_MININT));
50
g_assert (atomic == G_MININT);
52
g_assert (g_atomic_pointer_compare_and_exchange (&atomic_pointer,
53
NULL, biggest_pointer));
54
g_assert (atomic_pointer == biggest_pointer);
56
g_assert (atomic_pointer == g_atomic_pointer_get (&atomic_pointer));
58
g_assert (g_atomic_pointer_compare_and_exchange (&atomic_pointer,
59
biggest_pointer, NULL));
60
g_assert (atomic_pointer == NULL);