1
0
mirror of https://gitlab.gnome.org/GNOME/glib.git synced 2025-08-14 12:58:48 +02:00
Files
debian
docs
glib
gmodule
gobject
gthread
m4macros
po
tests
gobject
markups
.cvsignore
Makefile.am
array-test.c
atomic-test.c
casefold.txt
casemap.txt
child-test.c
completion-test.c
cxx-test.C
date-test.c
dirname-test.c
env-test.c
file-test.c
gen-casefold-txt.pl
gen-casemap-txt.pl
gio-test.c
hash-test.c
iochannel-test-infile
iochannel-test.c
libmoduletestplugin_a.c
libmoduletestplugin_b.c
list-test.c
mainloop-test.c
makefile.mingw.in
makefile.msc.in
markup-escape-test.c
markup-test.c
module-test.c
node-test.c
patterntest.c
printf-test.c
qsort-test.c
queue-test.c
rand-test.c
relation-test.c
run-markup-tests.sh
shell-test.c
slist-test.c
spawn-test-win32-gui.c
spawn-test.c
strfunc-test.c
string-test.c
strtod-test.c
testgdate.c
testgdateparser.c
testglib.c
thread-test.c
threadpool-test.c
timeloop-basic.c
timeloop-closure.c
timeloop.c
tree-test.c
type-test.c
unicode-caseconv.c
unicode-collate.c
unicode-encoding.c
unicode-normalize.c
uri-test.c
utf8.txt
.cvsignore
AUTHORS
COPYING
ChangeLog
ChangeLog.pre-1-2
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
HACKING
INSTALL
INSTALL.in
Makefile.am
NEWS
NEWS.pre-1-3
README
README.in
README.win32
TODO.xml
acglib.m4
acinclude.m4
autogen.sh
config.h.win32.in
configure.in
glib-2.0-uninstalled.pc.in
glib-2.0.pc.in
glib-gettextize.in
glib-zip.in
glib.spec.in
glibconfig.h.win32.in
gmodule-2.0-uninstalled.pc.in
gmodule-2.0.pc.in
gobject-2.0-uninstalled.pc.in
gobject-2.0.pc.in
gthread-2.0-uninstalled.pc.in
gthread-2.0.pc.in
makefile.mingw
makefile.msc
msvc_recommended_pragmas.h
sanity_check
win32-fixup.pl
glib/tests/atomic-test.c

64 lines
1.7 KiB
C
Raw Normal View History

#undef G_DISABLE_ASSERT
#undef G_LOG_DOMAIN
#include <glib.h>
/* Obviously we can't test that the operations are atomic, but we can
* at least test, that they do, what they ought to do */
int
main (int argc,
char *argv[])
{
gint i;
gint atomic = -5;
gpointer atomic_pointer = NULL;
gpointer biggest_pointer = (gpointer)((gsize)atomic_pointer - 1);
for (i = 0; i < 15; i++)
g_atomic_int_inc (&atomic);
g_assert (atomic == 10);
for (i = 0; i < 9; i++)
g_assert (!g_atomic_int_dec_and_test (&atomic));
g_assert (g_atomic_int_dec_and_test (&atomic));
g_assert (atomic == 0);
g_assert (g_atomic_int_exchange_and_add (&atomic, 5) == 0);
g_assert (atomic == 5);
g_assert (g_atomic_int_exchange_and_add (&atomic, -10) == 5);
g_assert (atomic == -5);
g_atomic_int_add (&atomic, 20);
g_assert (atomic == 15);
g_atomic_int_add (&atomic, -35);
g_assert (atomic == -20);
g_assert (atomic == g_atomic_int_get (&atomic));
g_assert (g_atomic_int_compare_and_exchange (&atomic, -20, 20));
g_assert (atomic == 20);
g_assert (!g_atomic_int_compare_and_exchange (&atomic, 42, 12));
g_assert (atomic == 20);
g_assert (g_atomic_int_compare_and_exchange (&atomic, 20, G_MAXINT));
g_assert (atomic == G_MAXINT);
g_assert (g_atomic_int_compare_and_exchange (&atomic, G_MAXINT, G_MININT));
g_assert (atomic == G_MININT);
g_assert (g_atomic_pointer_compare_and_exchange (&atomic_pointer,
NULL, biggest_pointer));
g_assert (atomic_pointer == biggest_pointer);
g_assert (atomic_pointer == g_atomic_pointer_get (&atomic_pointer));
g_assert (g_atomic_pointer_compare_and_exchange (&atomic_pointer,
biggest_pointer, NULL));
g_assert (atomic_pointer == NULL);
return 0;
}