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 
64 /**
65  * The following is a collection of compiler macros to provide atomic
66  * access to integer and pointer-sized values.
67  *
68  * The macros that have 'int' in the name will operate on pointers to
69  * gint and guint. The macros with 'pointer' in the name will operate
70  * on pointers to any pointer-sized value, including gsize. There is
71  * no support for 64bit operations on platforms with 32bit pointers
72  * because it is not generally possible to perform these operations
73  * atomically.
74  *
75  * The get, set and exchange operations for integers and pointers
76  * nominally operate on gint and gpointer, respectively. Of the
77  * arithmetic operations, the 'add' operation operates on (and returns)
78  * signed integer values (gint and gssize) and the 'and', 'or', and
79  * 'xor' operations operate on (and return) unsigned integer values
80  * (guint and gsize).
81  *
82  * All of the operations act as a full compiler and (where appropriate)
83  * hardware memory barrier. Acquire and release or producer and
84  * consumer barrier semantics are not available through this API.
85  *
86  * It is very important that all accesses to a particular integer or
87  * pointer be performed using only this API and that different sizes of
88  * operation are not mixed or used on overlapping memory regions. Never
89  * read or assign directly from or to a value -- always use this API.
90  *
91  * For simple reference counting purposes you should use
92  * g_atomic_int_inc() and g_atomic_int_dec_and_test(). Other uses that
93  * fall outside of simple reference counting patterns are prone to
94  * subtle bugs and occasionally undefined behaviour. It is also worth
95  * noting that since all of these operations require global
96  * synchronisation of the entire machine, they can be quite slow. In
97  * the case of performing multiple atomic operations it can often be
98  * faster to simply acquire a mutex lock around the critical area,
99  * perform the operations normally and then release the lock.
100  */
101 public class Atomic
102 {
103 	
104 	/**
105 	 */
106 	
107 	/**
108 	 * Gets the current value of atomic.
109 	 * This call acts as a full compiler and hardware
110 	 * memory barrier (before the get).
111 	 * Since 2.4
112 	 * Params:
113 	 * atomic = a pointer to a gint or guint
114 	 * Returns: the value of the integer
115 	 */
116 	public static int intGet(int* atomic)
117 	{
118 		// gint g_atomic_int_get (const volatile gint *atomic);
119 		return g_atomic_int_get(atomic);
120 	}
121 	
122 	/**
123 	 * Sets the value of atomic to newval.
124 	 * This call acts as a full compiler and hardware
125 	 * memory barrier (after the set).
126 	 * Since 2.4
127 	 * Params:
128 	 * atomic = a pointer to a gint or guint
129 	 * newval = a new value to store
130 	 */
131 	public static void intSet(int* atomic, int newval)
132 	{
133 		// void g_atomic_int_set (volatile gint *atomic,  gint newval);
134 		g_atomic_int_set(atomic, newval);
135 	}
136 	
137 	/**
138 	 * Increments the value of atomic by 1.
139 	 * Think of this operation as an atomic version of
140 	 * { *atomic += 1; }
141 	 * This call acts as a full compiler and hardware memory barrier.
142 	 * Since 2.4
143 	 * Params:
144 	 * atomic = a pointer to a gint or guint
145 	 */
146 	public static void intInc(int* atomic)
147 	{
148 		// void g_atomic_int_inc (gint *atomic);
149 		g_atomic_int_inc(atomic);
150 	}
151 	
152 	/**
153 	 * Decrements the value of atomic by 1.
154 	 * Think of this operation as an atomic version of
155 	 * { *atomic -= 1; return (*atomic == 0); }
156 	 * This call acts as a full compiler and hardware memory barrier.
157 	 * Since 2.4
158 	 * Params:
159 	 * atomic = a pointer to a gint or guint
160 	 * Returns: TRUE if the resultant value is zero
161 	 */
162 	public static int intDecAndTest(int* atomic)
163 	{
164 		// gboolean g_atomic_int_dec_and_test (gint *atomic);
165 		return g_atomic_int_dec_and_test(atomic);
166 	}
167 	
168 	/**
169 	 * Compares atomic to oldval and, if equal, sets it to newval.
170 	 * If atomic was not equal to oldval then no change occurs.
171 	 * This compare and exchange is done atomically.
172 	 * Think of this operation as an atomic version of
173 	 * { if (*atomic == oldval) { *atomic = newval; return TRUE; } else return FALSE; }
174 	 * This call acts as a full compiler and hardware memory barrier.
175 	 * Since 2.4
176 	 * Params:
177 	 * atomic = a pointer to a gint or guint
178 	 * oldval = the value to compare with
179 	 * newval = the value to conditionally replace with
180 	 * Returns: TRUE if the exchange took place
181 	 */
182 	public static int intCompareAndExchange(int* atomic, int oldval, int newval)
183 	{
184 		// gboolean g_atomic_int_compare_and_exchange (volatile gint *atomic,  gint oldval,  gint newval);
185 		return g_atomic_int_compare_and_exchange(atomic, oldval, newval);
186 	}
187 	
188 	/**
189 	 * Atomically adds val to the value of atomic.
190 	 * Think of this operation as an atomic version of
191 	 * { tmp = *atomic; *atomic += val; return tmp; }
192 	 * This call acts as a full compiler and hardware memory barrier.
193 	 * Before version 2.30, this function did not return a value
194 	 * (but g_atomic_int_exchange_and_add() did, and had the same meaning).
195 	 * Since 2.4
196 	 * Params:
197 	 * atomic = a pointer to a gint or guint
198 	 * val = the value to add
199 	 * Returns: the value of atomic before the add, signed
200 	 */
201 	public static int intAdd(int* atomic, int val)
202 	{
203 		// gint g_atomic_int_add (volatile gint *atomic,  gint val);
204 		return g_atomic_int_add(atomic, val);
205 	}
206 	
207 	/**
208 	 * Performs an atomic bitwise 'and' of the value of atomic and val,
209 	 * storing the result back in atomic.
210 	 * This call acts as a full compiler and hardware memory barrier.
211 	 * Think of this operation as an atomic version of
212 	 * { tmp = *atomic; *atomic = val; return tmp; }
213 	 * Since 2.30
214 	 * Params:
215 	 * atomic = a pointer to a gint or guint
216 	 * val = the value to 'and'
217 	 * Returns: the value of atomic before the operation, unsigned
218 	 */
219 	public static uint intAnd(uint* atomic, uint val)
220 	{
221 		// guint g_atomic_int_and (volatile guint *atomic,  guint val);
222 		return g_atomic_int_and(atomic, val);
223 	}
224 	
225 	/**
226 	 * Performs an atomic bitwise 'or' of the value of atomic and val,
227 	 * storing the result back in atomic.
228 	 * Think of this operation as an atomic version of
229 	 * { tmp = *atomic; *atomic |= val; return tmp; }
230 	 * This call acts as a full compiler and hardware memory barrier.
231 	 * Since 2.30
232 	 * Params:
233 	 * atomic = a pointer to a gint or guint
234 	 * val = the value to 'or'
235 	 * Returns: the value of atomic before the operation, unsigned
236 	 */
237 	public static uint intOr(uint* atomic, uint val)
238 	{
239 		// guint g_atomic_int_or (volatile guint *atomic,  guint val);
240 		return g_atomic_int_or(atomic, val);
241 	}
242 	
243 	/**
244 	 * Performs an atomic bitwise 'xor' of the value of atomic and val,
245 	 * storing the result back in atomic.
246 	 * Think of this operation as an atomic version of
247 	 * { tmp = *atomic; *atomic ^= val; return tmp; }
248 	 * This call acts as a full compiler and hardware memory barrier.
249 	 * Since 2.30
250 	 * Params:
251 	 * atomic = a pointer to a gint or guint
252 	 * val = the value to 'xor'
253 	 * Returns: the value of atomic before the operation, unsigned
254 	 */
255 	public static uint intXor(uint* atomic, uint val)
256 	{
257 		// guint g_atomic_int_xor (volatile guint *atomic,  guint val);
258 		return g_atomic_int_xor(atomic, val);
259 	}
260 	
261 	/**
262 	 * Gets the current value of atomic.
263 	 * This call acts as a full compiler and hardware
264 	 * memory barrier (before the get).
265 	 * Since 2.4
266 	 * Params:
267 	 * atomic = a pointer to a gpointer-sized value
268 	 * Returns: the value of the pointer
269 	 */
270 	public static void* pointerGet(void* atomic)
271 	{
272 		// gpointer g_atomic_pointer_get (const volatile void *atomic);
273 		return g_atomic_pointer_get(atomic);
274 	}
275 	
276 	/**
277 	 * Sets the value of atomic to newval.
278 	 * This call acts as a full compiler and hardware
279 	 * memory barrier (after the set).
280 	 * Since 2.4
281 	 * Params:
282 	 * atomic = a pointer to a gpointer-sized value
283 	 * newval = a new value to store
284 	 */
285 	public static void pointerSet(void* atomic, void* newval)
286 	{
287 		// void g_atomic_pointer_set (volatile void *atomic,  gpointer newval);
288 		g_atomic_pointer_set(atomic, newval);
289 	}
290 	
291 	/**
292 	 * Compares atomic to oldval and, if equal, sets it to newval.
293 	 * If atomic was not equal to oldval then no change occurs.
294 	 * This compare and exchange is done atomically.
295 	 * Think of this operation as an atomic version of
296 	 * { if (*atomic == oldval) { *atomic = newval; return TRUE; } else return FALSE; }
297 	 * This call acts as a full compiler and hardware memory barrier.
298 	 * Since 2.4
299 	 * Params:
300 	 * atomic = a pointer to a gpointer-sized value
301 	 * oldval = the value to compare with
302 	 * newval = the value to conditionally replace with
303 	 * Returns: TRUE if the exchange took place
304 	 */
305 	public static int pointerCompareAndExchange(void* atomic, void* oldval, void* newval)
306 	{
307 		// gboolean g_atomic_pointer_compare_and_exchange  (volatile void *atomic,  gpointer oldval,  gpointer newval);
308 		return g_atomic_pointer_compare_and_exchange(atomic, oldval, newval);
309 	}
310 	
311 	/**
312 	 * Atomically adds val to the value of atomic.
313 	 * Think of this operation as an atomic version of
314 	 * { tmp = *atomic; *atomic += val; return tmp; }
315 	 * This call acts as a full compiler and hardware memory barrier.
316 	 * Since 2.30
317 	 * Params:
318 	 * atomic = a pointer to a gpointer-sized value
319 	 * val = the value to add
320 	 * Returns: the value of atomic before the add, signed
321 	 */
322 	public static gssize pointerAdd(void* atomic, gssize val)
323 	{
324 		// gssize g_atomic_pointer_add (volatile void *atomic,  gssize val);
325 		return g_atomic_pointer_add(atomic, val);
326 	}
327 	
328 	/**
329 	 * Performs an atomic bitwise 'and' of the value of atomic and val,
330 	 * storing the result back in atomic.
331 	 * Think of this operation as an atomic version of
332 	 * { tmp = *atomic; *atomic = val; return tmp; }
333 	 * This call acts as a full compiler and hardware memory barrier.
334 	 * Since 2.30
335 	 * Params:
336 	 * atomic = a pointer to a gpointer-sized value
337 	 * val = the value to 'and'
338 	 * Returns: the value of atomic before the operation, unsigned
339 	 */
340 	public static gsize pointerAnd(void* atomic, gsize val)
341 	{
342 		// gsize g_atomic_pointer_and (volatile void *atomic,  gsize val);
343 		return g_atomic_pointer_and(atomic, val);
344 	}
345 	
346 	/**
347 	 * Performs an atomic bitwise 'or' of the value of atomic and val,
348 	 * storing the result back in atomic.
349 	 * Think of this operation as an atomic version of
350 	 * { tmp = *atomic; *atomic |= val; return tmp; }
351 	 * This call acts as a full compiler and hardware memory barrier.
352 	 * Since 2.30
353 	 * Params:
354 	 * atomic = a pointer to a gpointer-sized value
355 	 * val = the value to 'or'
356 	 * Returns: the value of atomic before the operation, unsigned
357 	 */
358 	public static gsize pointerOr(void* atomic, gsize val)
359 	{
360 		// gsize g_atomic_pointer_or (volatile void *atomic,  gsize val);
361 		return g_atomic_pointer_or(atomic, val);
362 	}
363 	
364 	/**
365 	 * Performs an atomic bitwise 'xor' of the value of atomic and val,
366 	 * storing the result back in atomic.
367 	 * Think of this operation as an atomic version of
368 	 * { tmp = *atomic; *atomic ^= val; return tmp; }
369 	 * This call acts as a full compiler and hardware memory barrier.
370 	 * Since 2.30
371 	 * Params:
372 	 * atomic = a pointer to a gpointer-sized value
373 	 * val = the value to 'xor'
374 	 * Returns: the value of atomic before the operation, unsigned
375 	 */
376 	public static gsize pointerXor(void* atomic, gsize val)
377 	{
378 		// gsize g_atomic_pointer_xor (volatile void *atomic,  gsize val);
379 		return g_atomic_pointer_xor(atomic, val);
380 	}
381 	
382 	/**
383 	 * Warning
384 	 * 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.
385 	 * This function existed before g_atomic_int_add() returned the prior
386 	 * value of the integer (which it now does). It is retained only for
387 	 * compatibility reasons. Don't use this function in new code.
388 	 * Since 2.4
389 	 * Params:
390 	 * atomic = a pointer to a gint
391 	 * val = the value to add
392 	 * Returns: the value of atomic before the add, signed
393 	 */
394 	public static int intExchangeAndAdd(int* atomic, int val)
395 	{
396 		// gint g_atomic_int_exchange_and_add (volatile gint *atomic,  gint val);
397 		return g_atomic_int_exchange_and_add(atomic, val);
398 	}
399 }