1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD 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
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = glib-Atomic-Operations.html
27  * outPack = glib
28  * outFile = Atomic
29  * strct   = 
30  * realStrct=
31  * ctorStrct=
32  * clss    = Atomic
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_atomic_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * structWrap:
47  * module aliases:
48  * local aliases:
49  * overrides:
50  */
51 
52 module glib.Atomic;
53 
54 public  import gtkc.glibtypes;
55 
56 private import gtkc.glib;
57 private import glib.ConstructionException;
58 
59 
60 
61 
62 /**
63  * The following is a collection of compiler macros to provide atomic
64  * access to integer and pointer-sized values.
65  *
66  * The macros that have 'int' in the name will operate on pointers to
67  * gint and guint. The macros with 'pointer' in the name will operate
68  * on pointers to any pointer-sized value, including gsize. There is
69  * no support for 64bit operations on platforms with 32bit pointers
70  * because it is not generally possible to perform these operations
71  * atomically.
72  *
73  * The get, set and exchange operations for integers and pointers
74  * nominally operate on gint and gpointer, respectively. Of the
75  * arithmetic operations, the 'add' operation operates on (and returns)
76  * signed integer values (gint and gssize) and the 'and', 'or', and
77  * 'xor' operations operate on (and return) unsigned integer values
78  * (guint and gsize).
79  *
80  * All of the operations act as a full compiler and (where appropriate)
81  * hardware memory barrier. Acquire and release or producer and
82  * consumer barrier semantics are not available through this API.
83  *
84  * It is very important that all accesses to a particular integer or
85  * pointer be performed using only this API and that different sizes of
86  * operation are not mixed or used on overlapping memory regions. Never
87  * read or assign directly from or to a value -- always use this API.
88  *
89  * For simple reference counting purposes you should use
90  * g_atomic_int_inc() and g_atomic_int_dec_and_test(). Other uses that
91  * fall outside of simple reference counting patterns are prone to
92  * subtle bugs and occasionally undefined behaviour. It is also worth
93  * noting that since all of these operations require global
94  * synchronisation of the entire machine, they can be quite slow. In
95  * the case of performing multiple atomic operations it can often be
96  * faster to simply acquire a mutex lock around the critical area,
97  * perform the operations normally and then release the lock.
98  */
99 public class Atomic
100 {
101 	
102 	/**
103 	 */
104 	
105 	/**
106 	 * Gets the current value of atomic.
107 	 * This call acts as a full compiler and hardware
108 	 * memory barrier (before the get).
109 	 * Since 2.4
110 	 * Params:
111 	 * atomic = a pointer to a gint or guint
112 	 * Returns: the value of the integer
113 	 */
114 	public static int intGet(int* atomic)
115 	{
116 		// gint g_atomic_int_get (const volatile gint *atomic);
117 		return g_atomic_int_get(atomic);
118 	}
119 	
120 	/**
121 	 * Sets the value of atomic to newval.
122 	 * This call acts as a full compiler and hardware
123 	 * memory barrier (after the set).
124 	 * Since 2.4
125 	 * Params:
126 	 * atomic = a pointer to a gint or guint
127 	 * newval = a new value to store
128 	 */
129 	public static void intSet(int* atomic, int newval)
130 	{
131 		// void g_atomic_int_set (volatile gint *atomic,  gint newval);
132 		g_atomic_int_set(atomic, newval);
133 	}
134 	
135 	/**
136 	 * Increments the value of atomic by 1.
137 	 * Think of this operation as an atomic version of
138 	 * { *atomic += 1; }
139 	 * This call acts as a full compiler and hardware memory barrier.
140 	 * Since 2.4
141 	 * Params:
142 	 * atomic = a pointer to a gint or guint
143 	 */
144 	public static void intInc(int* atomic)
145 	{
146 		// void g_atomic_int_inc (gint *atomic);
147 		g_atomic_int_inc(atomic);
148 	}
149 	
150 	/**
151 	 * Decrements the value of atomic by 1.
152 	 * Think of this operation as an atomic version of
153 	 * { *atomic -= 1; return (*atomic == 0); }
154 	 * This call acts as a full compiler and hardware memory barrier.
155 	 * Since 2.4
156 	 * Params:
157 	 * atomic = a pointer to a gint or guint
158 	 * Returns: TRUE if the resultant value is zero
159 	 */
160 	public static int intDecAndTest(int* atomic)
161 	{
162 		// gboolean g_atomic_int_dec_and_test (gint *atomic);
163 		return g_atomic_int_dec_and_test(atomic);
164 	}
165 	
166 	/**
167 	 * Compares atomic to oldval and, if equal, sets it to newval.
168 	 * If atomic was not equal to oldval then no change occurs.
169 	 * This compare and exchange is done atomically.
170 	 * Think of this operation as an atomic version of
171 	 * { if (*atomic == oldval) { *atomic = newval; return TRUE; } else return FALSE; }
172 	 * This call acts as a full compiler and hardware memory barrier.
173 	 * Since 2.4
174 	 * Params:
175 	 * atomic = a pointer to a gint or guint
176 	 * oldval = the value to compare with
177 	 * newval = the value to conditionally replace with
178 	 * Returns: TRUE if the exchange took place
179 	 */
180 	public static int intCompareAndExchange(int* atomic, int oldval, int newval)
181 	{
182 		// gboolean g_atomic_int_compare_and_exchange (volatile gint *atomic,  gint oldval,  gint newval);
183 		return g_atomic_int_compare_and_exchange(atomic, oldval, newval);
184 	}
185 	
186 	/**
187 	 * Atomically adds val to the value of atomic.
188 	 * Think of this operation as an atomic version of
189 	 * { tmp = *atomic; *atomic += val; return tmp; }
190 	 * This call acts as a full compiler and hardware memory barrier.
191 	 * Before version 2.30, this function did not return a value
192 	 * (but g_atomic_int_exchange_and_add() did, and had the same meaning).
193 	 * Since 2.4
194 	 * Params:
195 	 * atomic = a pointer to a gint or guint
196 	 * val = the value to add
197 	 * Returns: the value of atomic before the add, signed
198 	 */
199 	public static int intAdd(int* atomic, int val)
200 	{
201 		// gint g_atomic_int_add (volatile gint *atomic,  gint val);
202 		return g_atomic_int_add(atomic, val);
203 	}
204 	
205 	/**
206 	 * Performs an atomic bitwise 'and' of the value of atomic and val,
207 	 * storing the result back in atomic.
208 	 * This call acts as a full compiler and hardware memory barrier.
209 	 * Think of this operation as an atomic version of
210 	 * { tmp = *atomic; *atomic = val; return tmp; }
211 	 * Since 2.30
212 	 * Params:
213 	 * atomic = a pointer to a gint or guint
214 	 * val = the value to 'and'
215 	 * Returns: the value of atomic before the operation, unsigned
216 	 */
217 	public static uint intAnd(uint* atomic, uint val)
218 	{
219 		// guint g_atomic_int_and (volatile guint *atomic,  guint val);
220 		return g_atomic_int_and(atomic, val);
221 	}
222 	
223 	/**
224 	 * Performs an atomic bitwise 'or' of the value of atomic and val,
225 	 * storing the result back in atomic.
226 	 * Think of this operation as an atomic version of
227 	 * { tmp = *atomic; *atomic |= val; return tmp; }
228 	 * This call acts as a full compiler and hardware memory barrier.
229 	 * Since 2.30
230 	 * Params:
231 	 * atomic = a pointer to a gint or guint
232 	 * val = the value to 'or'
233 	 * Returns: the value of atomic before the operation, unsigned
234 	 */
235 	public static uint intOr(uint* atomic, uint val)
236 	{
237 		// guint g_atomic_int_or (volatile guint *atomic,  guint val);
238 		return g_atomic_int_or(atomic, val);
239 	}
240 	
241 	/**
242 	 * Performs an atomic bitwise 'xor' of the value of atomic and val,
243 	 * storing the result back in atomic.
244 	 * Think of this operation as an atomic version of
245 	 * { tmp = *atomic; *atomic ^= val; return tmp; }
246 	 * This call acts as a full compiler and hardware memory barrier.
247 	 * Since 2.30
248 	 * Params:
249 	 * atomic = a pointer to a gint or guint
250 	 * val = the value to 'xor'
251 	 * Returns: the value of atomic before the operation, unsigned
252 	 */
253 	public static uint intXor(uint* atomic, uint val)
254 	{
255 		// guint g_atomic_int_xor (volatile guint *atomic,  guint val);
256 		return g_atomic_int_xor(atomic, val);
257 	}
258 	
259 	/**
260 	 * Gets the current value of atomic.
261 	 * This call acts as a full compiler and hardware
262 	 * memory barrier (before the get).
263 	 * Since 2.4
264 	 * Params:
265 	 * atomic = a pointer to a gpointer-sized value
266 	 * Returns: the value of the pointer
267 	 */
268 	public static void* pointerGet(void* atomic)
269 	{
270 		// gpointer g_atomic_pointer_get (const volatile void *atomic);
271 		return g_atomic_pointer_get(atomic);
272 	}
273 	
274 	/**
275 	 * Sets the value of atomic to newval.
276 	 * This call acts as a full compiler and hardware
277 	 * memory barrier (after the set).
278 	 * Since 2.4
279 	 * Params:
280 	 * atomic = a pointer to a gpointer-sized value
281 	 * newval = a new value to store
282 	 */
283 	public static void pointerSet(void* atomic, void* newval)
284 	{
285 		// void g_atomic_pointer_set (volatile void *atomic,  gpointer newval);
286 		g_atomic_pointer_set(atomic, newval);
287 	}
288 	
289 	/**
290 	 * Compares atomic to oldval and, if equal, sets it to newval.
291 	 * If atomic was not equal to oldval then no change occurs.
292 	 * This compare and exchange is done atomically.
293 	 * Think of this operation as an atomic version of
294 	 * { if (*atomic == oldval) { *atomic = newval; return TRUE; } else return FALSE; }
295 	 * This call acts as a full compiler and hardware memory barrier.
296 	 * Since 2.4
297 	 * Params:
298 	 * atomic = a pointer to a gpointer-sized value
299 	 * oldval = the value to compare with
300 	 * newval = the value to conditionally replace with
301 	 * Returns: TRUE if the exchange took place
302 	 */
303 	public static int pointerCompareAndExchange(void* atomic, void* oldval, void* newval)
304 	{
305 		// gboolean g_atomic_pointer_compare_and_exchange  (volatile void *atomic,  gpointer oldval,  gpointer newval);
306 		return g_atomic_pointer_compare_and_exchange(atomic, oldval, newval);
307 	}
308 	
309 	/**
310 	 * Atomically adds val to the value of atomic.
311 	 * Think of this operation as an atomic version of
312 	 * { tmp = *atomic; *atomic += val; return tmp; }
313 	 * This call acts as a full compiler and hardware memory barrier.
314 	 * Since 2.30
315 	 * Params:
316 	 * atomic = a pointer to a gpointer-sized value
317 	 * val = the value to add
318 	 * Returns: the value of atomic before the add, signed
319 	 */
320 	public static gssize pointerAdd(void* atomic, gssize val)
321 	{
322 		// gssize g_atomic_pointer_add (volatile void *atomic,  gssize val);
323 		return g_atomic_pointer_add(atomic, val);
324 	}
325 	
326 	/**
327 	 * Performs an atomic bitwise 'and' of the value of atomic and val,
328 	 * storing the result back in atomic.
329 	 * Think of this operation as an atomic version of
330 	 * { tmp = *atomic; *atomic = val; return tmp; }
331 	 * This call acts as a full compiler and hardware memory barrier.
332 	 * Since 2.30
333 	 * Params:
334 	 * atomic = a pointer to a gpointer-sized value
335 	 * val = the value to 'and'
336 	 * Returns: the value of atomic before the operation, unsigned
337 	 */
338 	public static gsize pointerAnd(void* atomic, gsize val)
339 	{
340 		// gsize g_atomic_pointer_and (volatile void *atomic,  gsize val);
341 		return g_atomic_pointer_and(atomic, val);
342 	}
343 	
344 	/**
345 	 * Performs an atomic bitwise 'or' of the value of atomic and val,
346 	 * storing the result back in atomic.
347 	 * Think of this operation as an atomic version of
348 	 * { tmp = *atomic; *atomic |= val; return tmp; }
349 	 * This call acts as a full compiler and hardware memory barrier.
350 	 * Since 2.30
351 	 * Params:
352 	 * atomic = a pointer to a gpointer-sized value
353 	 * val = the value to 'or'
354 	 * Returns: the value of atomic before the operation, unsigned
355 	 */
356 	public static gsize pointerOr(void* atomic, gsize val)
357 	{
358 		// gsize g_atomic_pointer_or (volatile void *atomic,  gsize val);
359 		return g_atomic_pointer_or(atomic, val);
360 	}
361 	
362 	/**
363 	 * Performs an atomic bitwise 'xor' of the value of atomic and val,
364 	 * storing the result back in atomic.
365 	 * Think of this operation as an atomic version of
366 	 * { tmp = *atomic; *atomic ^= val; return tmp; }
367 	 * This call acts as a full compiler and hardware memory barrier.
368 	 * Since 2.30
369 	 * Params:
370 	 * atomic = a pointer to a gpointer-sized value
371 	 * val = the value to 'xor'
372 	 * Returns: the value of atomic before the operation, unsigned
373 	 */
374 	public static gsize pointerXor(void* atomic, gsize val)
375 	{
376 		// gsize g_atomic_pointer_xor (volatile void *atomic,  gsize val);
377 		return g_atomic_pointer_xor(atomic, val);
378 	}
379 	
380 	/**
381 	 * Warning
382 	 * g_atomic_int_exchange_and_add has been deprecated since version 2.30 and should not be used in newly-written code. Use g_atomic_int_add() instead.
383 	 * This function existed before g_atomic_int_add() returned the prior
384 	 * value of the integer (which it now does). It is retained only for
385 	 * compatibility reasons. Don't use this function in new code.
386 	 * Since 2.4
387 	 * Params:
388 	 * atomic = a pointer to a gint
389 	 * val = the value to add
390 	 * Returns: the value of atomic before the add, signed
391 	 */
392 	public static int intExchangeAndAdd(int* atomic, int val)
393 	{
394 		// gint g_atomic_int_exchange_and_add (volatile gint *atomic,  gint val);
395 		return g_atomic_int_exchange_and_add(atomic, val);
396 	}
397 }