2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = glib-Atomic-Operations.html
55 import tango
.io
.Stdout
; // use the tango loging?
59 private import gtkc
.glibtypes
;
61 private import gtkc
.glib
;
70 * The following functions can be used to atomically access integers and
71 * pointers. They are implemented as inline assembler function on most
72 * platforms and use slower fall-backs otherwise. Using them can sometimes
73 * save you from using a performance-expensive GMutex to protect the
75 * The most important usage is reference counting. Using
76 * g_atomic_int_inc() and g_atomic_int_dec_and_test() makes reference
77 * counting a very fast operation.
79 * You must not directly read integers or pointers concurrently accessed
80 * by multiple threads, but use the atomic accessor functions instead.
81 * That is, always use g_atomic_int_get() and g_atomic_pointer_get() for
83 * They provide the neccessary synchonization mechanisms like memory
84 * barriers to access memory locations concurrently.
86 * If you are using those functions for anything apart from simple
87 * reference counting, you should really be aware of the implications of
88 * doing that. There are literally thousands of ways to shoot yourself in
89 * the foot. So if in doubt, use a GMutex. If you don't know, what
90 * memory barriers are, do not use anything but g_atomic_int_inc() and
91 * g_atomic_int_dec_and_test().
93 * It is not safe to set an integer or pointer just by assigning to it,
94 * when it is concurrently accessed by other threads with the following
95 * functions. Use g_atomic_int_compare_and_exchange() or
96 * g_atomic_pointer_compare_and_exchange() respectively.
105 * Reads the value of the integer pointed to by atomic. Also acts as
108 * a pointer to an integer
110 * the value of *atomic
113 public static int intGet(int* atomic
)
115 // gint g_atomic_int_get (volatile gint *atomic);
116 return g_atomic_int_get(atomic
);
120 * Sets the value of the integer pointed to by atomic.
121 * Also acts as a memory barrier.
123 * a pointer to an integer
128 public static void intSet(int* atomic
, int newval
)
130 // void g_atomic_int_set (volatile gint *atomic, gint newval);
131 g_atomic_int_set(atomic
, newval
);
135 * Atomically adds val to the integer pointed to by atomic.
136 * Also acts as a memory barrier.
138 * a pointer to an integer.
140 * the value to add to *atomic.
143 public static void intAdd(int* atomic
, int val
)
145 // void g_atomic_int_add (volatile gint *atomic, gint val);
146 g_atomic_int_add(atomic
, val
);
150 * Atomically adds val to the integer pointed to by atomic. It returns
151 * the value of *atomic just before the addition took place.
152 * Also acts as a memory barrier.
154 * a pointer to an integer.
156 * the value to add to *atomic.
158 * the value of *atomic before the addition.
161 public static int intExchangeAndAdd(int* atomic
, int val
)
163 // gint g_atomic_int_exchange_and_add (volatile gint *atomic, gint val);
164 return g_atomic_int_exchange_and_add(atomic
, val
);
168 * Compares oldval with the integer pointed to by atomic and
169 * if they are equal, atomically exchanges *atomic with newval.
170 * Also acts as a memory barrier.
172 * a pointer to an integer.
174 * the assumed old value of *atomic.
176 * the new value of *atomic.
178 * TRUE, if *atomic was equal oldval. FALSE otherwise.
181 public static int intCompareAndExchange(int* atomic
, int oldval
, int newval
)
183 // gboolean g_atomic_int_compare_and_exchange (volatile gint *atomic, gint oldval, gint newval);
184 return g_atomic_int_compare_and_exchange(atomic
, oldval
, newval
);
188 * Reads the value of the pointer pointed to by atomic. Also acts as
191 * a pointer to a gpointer.
193 * the value to add to *atomic.
196 public static void* pointerGet(void** atomic
)
198 // gpointer g_atomic_pointer_get (volatile gpointer *atomic);
199 return g_atomic_pointer_get(atomic
);
203 * Sets the value of the pointer pointed to by atomic.
204 * Also acts as a memory barrier.
206 * a pointer to a gpointer
211 public static void pointerSet(void** atomic
, void* newval
)
213 // void g_atomic_pointer_set (volatile gpointer *atomic, gpointer newval);
214 g_atomic_pointer_set(atomic
, newval
);
218 * Compares oldval with the pointer pointed to by atomic and
219 * if they are equal, atomically exchanges *atomic with newval.
220 * Also acts as a memory barrier.
222 * a pointer to a gpointer.
224 * the assumed old value of *atomic.
226 * the new value of *atomic.
228 * TRUE, if *atomic was equal oldval. FALSE otherwise.
231 public static int pointerCompareAndExchange(void** atomic
, void* oldval
, void* newval
)
233 // gboolean g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, gpointer oldval, gpointer newval);
234 return g_atomic_pointer_compare_and_exchange(atomic
, oldval
, newval
);
238 * Atomically increments the integer pointed to by atomic by 1.
240 * a pointer to an integer.
243 public static void intInc(int* atomic
)
245 // void g_atomic_int_inc (gint *atomic);
246 g_atomic_int_inc(atomic
);
250 * Atomically decrements the integer pointed to by atomic by 1.
252 * a pointer to an integer.
254 * TRUE, if the integer pointed to by atomic is 0 after
259 * GLib mutual exclusions.
261 public static int intDecAndTest(int* atomic
)
263 // gboolean g_atomic_int_dec_and_test (gint *atomic);
264 return g_atomic_int_dec_and_test(atomic
);