alternative to assert
[gtkD.git] / gtkD / src / glib / Atomic.d
blobfe1284568cc82326f0e51ae0e387a280c91f00a0
1 /*
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
26 * outPack = glib
27 * outFile = Atomic
28 * strct =
29 * realStrct=
30 * ctorStrct=
31 * clss = Atomic
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - g_atomic_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * structWrap:
45 * module aliases:
46 * local aliases:
49 module glib.Atomic;
51 version(noAssert)
53 version(Tango)
55 import tango.io.Stdout; // use the tango loging?
59 private import gtkc.glibtypes;
61 private import gtkc.glib;
68 /**
69 * Description
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
74 * integer or pointer.
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.
78 * Note
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
82 * read outs.
83 * They provide the neccessary synchonization mechanisms like memory
84 * barriers to access memory locations concurrently.
85 * Note
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().
92 * Note
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.
98 public class Atomic
105 * Reads the value of the integer pointed to by atomic. Also acts as
106 * a memory barrier.
107 * atomic:
108 * a pointer to an integer
109 * Returns:
110 * the value of *atomic
111 * Since 2.4
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.
122 * atomic:
123 * a pointer to an integer
124 * newval:
125 * the new value
126 * Since 2.10
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.
137 * atomic:
138 * a pointer to an integer.
139 * val:
140 * the value to add to *atomic.
141 * Since 2.4
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.
153 * atomic:
154 * a pointer to an integer.
155 * val:
156 * the value to add to *atomic.
157 * Returns:
158 * the value of *atomic before the addition.
159 * Since 2.4
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.
171 * atomic:
172 * a pointer to an integer.
173 * oldval:
174 * the assumed old value of *atomic.
175 * newval:
176 * the new value of *atomic.
177 * Returns:
178 * TRUE, if *atomic was equal oldval. FALSE otherwise.
179 * Since 2.4
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
189 * a memory barrier.
190 * atomic:
191 * a pointer to a gpointer.
192 * Returns:
193 * the value to add to *atomic.
194 * Since 2.4
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.
205 * atomic:
206 * a pointer to a gpointer
207 * newval:
208 * the new value
209 * Since 2.10
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.
221 * atomic:
222 * a pointer to a gpointer.
223 * oldval:
224 * the assumed old value of *atomic.
225 * newval:
226 * the new value of *atomic.
227 * Returns:
228 * TRUE, if *atomic was equal oldval. FALSE otherwise.
229 * Since 2.4
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.
239 * atomic:
240 * a pointer to an integer.
241 * Since 2.4
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.
251 * atomic:
252 * a pointer to an integer.
253 * Returns:
254 * TRUE, if the integer pointed to by atomic is 0 after
255 * decrementing it.
256 * Since 2.4
257 * See Also
258 * GMutex
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);