1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * g_atomic_*: atomic operations.
5 * Copyright (C) 2003 Sebastian Wilhelmi
6 * Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
26 * file for a list of people on the GLib Team. See the ChangeLog
27 * files for a list of changes. These files are distributed with
28 * GLib at ftp://ftp.gtk.org/pub/gtk/.
31 #ifndef __G_ATOMIC_H__
32 #define __G_ATOMIC_H__
35 #include <glib/gtypes.h>
39 IMPORT_C gint g_atomic_int_exchange_and_add (volatile gint *atomic,
41 IMPORT_C void g_atomic_int_add (volatile gint *atomic,
43 IMPORT_C gboolean g_atomic_int_compare_and_exchange (volatile gint *atomic,
46 IMPORT_C gboolean g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic,
50 IMPORT_C gint g_atomic_int_get (volatile gint *atomic);
51 IMPORT_C void g_atomic_int_set (volatile gint *atomic,
53 IMPORT_C gpointer g_atomic_pointer_get (volatile gpointer *atomic);
54 IMPORT_C void g_atomic_pointer_set (volatile gpointer *atomic,
57 #ifndef G_ATOMIC_OP_MEMORY_BARRIER_NEEDED
58 # define g_atomic_int_get(atomic) (*(atomic))
59 # define g_atomic_int_set(atomic, newval) ((void) (*(atomic) = (newval)))
60 # define g_atomic_pointer_get(atomic) (*(atomic))
61 # define g_atomic_pointer_set(atomic, newval) ((void) (*(atomic) = (newval)))
62 #endif /* G_ATOMIC_OP_MEMORY_BARRIER_NEEDED */
64 #define g_atomic_int_inc(atomic) (g_atomic_int_add ((atomic), 1))
65 #define g_atomic_int_dec_and_test(atomic) \
66 (g_atomic_int_exchange_and_add ((atomic), -1) == 1)
70 #endif /* __G_ATOMIC_H__ */