1 | /* GLIB - Library of useful routines for C programming |
---|
2 | * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald |
---|
3 | * |
---|
4 | * g_atomic_*: atomic operations. |
---|
5 | * Copyright (C) 2003 Sebastian Wilhelmi |
---|
6 | * |
---|
7 | * This library is free software; you can redistribute it and/or |
---|
8 | * modify it under the terms of the GNU Lesser General Public |
---|
9 | * License as published by the Free Software Foundation; either |
---|
10 | * version 2 of the License, or (at your option) any later version. |
---|
11 | * |
---|
12 | * This library is distributed in the hope that it will be useful, |
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
15 | * Lesser General Public License for more details. |
---|
16 | * |
---|
17 | * You should have received a copy of the GNU Lesser General Public |
---|
18 | * License along with this library; if not, write to the |
---|
19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
20 | * Boston, MA 02111-1307, USA. |
---|
21 | */ |
---|
22 | |
---|
23 | /* |
---|
24 | * Modified by the GLib Team and others 1997-2000. See the AUTHORS |
---|
25 | * file for a list of people on the GLib Team. See the ChangeLog |
---|
26 | * files for a list of changes. These files are distributed with |
---|
27 | * GLib at ftp://ftp.gtk.org/pub/gtk/. |
---|
28 | */ |
---|
29 | |
---|
30 | #ifndef __G_ATOMIC_H__ |
---|
31 | #define __G_ATOMIC_H__ |
---|
32 | |
---|
33 | #include <glib/gtypes.h> |
---|
34 | |
---|
35 | G_BEGIN_DECLS |
---|
36 | |
---|
37 | gint g_atomic_int_exchange_and_add (gint *atomic, |
---|
38 | gint val); |
---|
39 | void g_atomic_int_add (gint *atomic, |
---|
40 | gint val); |
---|
41 | gboolean g_atomic_int_compare_and_exchange (gint *atomic, |
---|
42 | gint oldval, |
---|
43 | gint newval); |
---|
44 | gboolean g_atomic_pointer_compare_and_exchange (gpointer *atomic, |
---|
45 | gpointer oldval, |
---|
46 | gpointer newval); |
---|
47 | |
---|
48 | #ifdef G_ATOMIC_OP_MEMORY_BARRIER_NEEDED |
---|
49 | gint g_atomic_int_get (gint *atomic); |
---|
50 | gpointer g_atomic_pointer_get (gpointer *atomic); |
---|
51 | #else /* !G_ATOMIC_OP_MEMORY_BARRIER_NEEDED */ |
---|
52 | # define g_atomic_int_get(atomic) (*(atomic)) |
---|
53 | # define g_atomic_pointer_get(atomic) (*(atomic)) |
---|
54 | #endif /* G_ATOMIC_OP_MEMORY_BARRIER_NEEDED */ |
---|
55 | |
---|
56 | #define g_atomic_int_inc(atomic) (g_atomic_int_add ((atomic), 1)) |
---|
57 | #define g_atomic_int_dec_and_test(atomic) \ |
---|
58 | (g_atomic_int_exchange_and_add ((atomic), -1) == 1) |
---|
59 | |
---|
60 | G_END_DECLS |
---|
61 | |
---|
62 | #endif /* __G_ATOMIC_H__ */ |
---|