Merge "Implementation of following functionality" into connectivity-abstraction
[platform/upstream/iotivity.git] / resource / csdk / connectivity / lib / android / glib-master / glib / gatomic-gcc.c
1 /* GLIB - Library of useful routines for C programming
2  * gatomic-gcc.c: atomic operations using GCC builtins.
3  * Copyright (C) 2009 Hiroyuki Ikezoe
4  *
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.
9  *
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.
14  *
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.
19  */
20
21 #include "config.h"
22
23 #include "gatomic.h"
24
25 gint
26 g_atomic_int_exchange_and_add (volatile gint G_GNUC_MAY_ALIAS *atomic,
27                                gint           val)
28 {
29   return __sync_fetch_and_add (atomic, val);
30 }
31
32 void
33 g_atomic_int_add (volatile gint G_GNUC_MAY_ALIAS *atomic,
34                   gint val)
35 {
36   __sync_fetch_and_add (atomic, val);
37 }
38
39 gboolean
40 g_atomic_int_compare_and_exchange (volatile gint G_GNUC_MAY_ALIAS *atomic,
41                                    gint           oldval,
42                                    gint           newval)
43 {
44   return __sync_bool_compare_and_swap (atomic, oldval, newval);
45 }
46
47 gboolean
48 g_atomic_pointer_compare_and_exchange (volatile gpointer G_GNUC_MAY_ALIAS *atomic,
49                                        gpointer           oldval,
50                                        gpointer           newval)
51 {
52   return __sync_bool_compare_and_swap (atomic, oldval, newval);
53 }
54
55 void
56 _g_atomic_thread_init (void)
57 {
58 }
59
60 gint
61 (g_atomic_int_get) (volatile gint G_GNUC_MAY_ALIAS *atomic)
62 {
63   __sync_synchronize ();
64   return *atomic;
65 }
66
67 void
68 (g_atomic_int_set) (volatile gint G_GNUC_MAY_ALIAS *atomic,
69                     gint           newval)
70 {
71   *atomic = newval;
72   __sync_synchronize ();
73 }
74
75 gpointer
76 (g_atomic_pointer_get) (volatile gpointer G_GNUC_MAY_ALIAS *atomic)
77 {
78   __sync_synchronize ();
79   return *atomic;
80 }
81
82 void
83 (g_atomic_pointer_set) (volatile gpointer G_GNUC_MAY_ALIAS *atomic,
84                         gpointer           newval)
85 {
86   *atomic = newval;
87   __sync_synchronize ();
88 }