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.
27 g_atomic_int_exchange_and_add (volatile gint G_GNUC_MAY_ALIAS *atomic,
30 return __sync_fetch_and_add (atomic, val);
34 g_atomic_int_add (volatile gint G_GNUC_MAY_ALIAS *atomic,
37 __sync_fetch_and_add (atomic, val);
41 g_atomic_int_compare_and_exchange (volatile gint G_GNUC_MAY_ALIAS *atomic,
45 return __sync_bool_compare_and_swap (atomic, oldval, newval);
49 g_atomic_pointer_compare_and_exchange (volatile gpointer G_GNUC_MAY_ALIAS *atomic,
53 return __sync_bool_compare_and_swap (atomic, oldval, newval);
57 _g_atomic_thread_init (void)
62 (g_atomic_int_get) (volatile gint G_GNUC_MAY_ALIAS *atomic)
64 __sync_synchronize ();
69 (g_atomic_int_set) (volatile gint G_GNUC_MAY_ALIAS *atomic,
73 __sync_synchronize ();
77 (g_atomic_pointer_get) (volatile gpointer G_GNUC_MAY_ALIAS *atomic)
79 __sync_synchronize ();
84 (g_atomic_pointer_set) (volatile gpointer G_GNUC_MAY_ALIAS *atomic,
88 __sync_synchronize ();
91 #define __G_ATOMIC_C__
92 #include "galiasdef.c"