1 /* GLIB - Library of useful routines for C programming
2 * gatomic-gcc.c: atomic operations using GCC builtins.
3 * Copyright (C) 2009 Hiroyuki Ikezoe
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
26 g_atomic_int_exchange_and_add (volatile gint G_GNUC_MAY_ALIAS *atomic,
29 return __sync_fetch_and_add (atomic, val);
33 g_atomic_int_add (volatile gint G_GNUC_MAY_ALIAS *atomic,
36 __sync_fetch_and_add (atomic, val);
40 g_atomic_int_compare_and_exchange (volatile gint G_GNUC_MAY_ALIAS *atomic,
44 return __sync_bool_compare_and_swap (atomic, oldval, newval);
48 g_atomic_pointer_compare_and_exchange (volatile gpointer G_GNUC_MAY_ALIAS *atomic,
52 return __sync_bool_compare_and_swap (atomic, oldval, newval);
56 _g_atomic_thread_init (void)
61 (g_atomic_int_get) (volatile gint G_GNUC_MAY_ALIAS *atomic)
63 __sync_synchronize ();
68 (g_atomic_int_set) (volatile gint G_GNUC_MAY_ALIAS *atomic,
72 __sync_synchronize ();
76 (g_atomic_pointer_get) (volatile gpointer G_GNUC_MAY_ALIAS *atomic)
78 __sync_synchronize ();
83 (g_atomic_pointer_set) (volatile gpointer G_GNUC_MAY_ALIAS *atomic,
87 __sync_synchronize ();