I've no idea here...
[gtkD.git] / src / glib / Atomic.d
blobb193f40752650f16e3441f67df49683cabbfed95
1 /*
2 * This file is part of duit.
4 * duit 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 * duit 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 duit; 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 * local aliases:
48 module glib.Atomic;
50 private import glib.glibtypes;
52 private import lib.glib;
55 /**
56 * Description
57 * The following functions can be used to atomically access integers and
58 * pointers. They are implemented as inline assembler function on most
59 * platforms and use slower fall-backs otherwise. Using them can sometimes
60 * save you from using a performance-expensive GMutex to protect the
61 * integer or pointer.
62 * The most important usage is reference counting. Using
63 * g_atomic_int_inc() and g_atomic_int_dec_and_test() makes reference
64 * counting a very fast operation.
65 * Note
66 * You must not directly read integers or pointers concurrently accessed
67 * by multiple threads, but use the atomic accessor functions instead.
68 * That is, always use g_atomic_int_get() and g_atomic_pointer_get() for
69 * read outs.
70 * They provide the neccessary synchonization mechanisms like memory
71 * barriers to access memory locations concurrently.
72 * Note
73 * If you are using those functions for anything apart from simple
74 * reference counting, you should really be aware of the implications of
75 * doing that. There are literally thousands of ways to shoot yourself in
76 * the foot. So if in doubt, use a GMutex. If you don't know, what
77 * memory barriers are, do not use anything but g_atomic_int_inc() and
78 * g_atomic_int_dec_and_test().
79 * Note
80 * It is not safe to set an integer or pointer just by assigning to it,
81 * when it is concurrently accessed by other threads with the following
82 * functions. Use g_atomic_int_compare_and_exchange() or
83 * g_atomic_pointer_compare_and_exchange() respectively.
85 public class Atomic
88 /**
91 /**
92 * Reads the value of the integer pointed to by atomic. Also acts as
93 * a memory barrier.
94 * atomic:
95 * a pointer to an integer
96 * Returns:
97 * the value of *atomic
98 * Since 2.4
100 public static int intGet(int* atomic)
102 // gint g_atomic_int_get (volatile gint *atomic);
103 return g_atomic_int_get(atomic);
107 * Sets the value of the integer pointed to by atomic.
108 * Also acts as a memory barrier.
109 * atomic:
110 * a pointer to an integer
111 * newval:
112 * the new value
113 * Since 2.10
115 public static void intSet(int* atomic, int newval)
117 // void g_atomic_int_set (volatile gint *atomic, gint newval);
118 g_atomic_int_set(atomic, newval);
122 * Atomically adds val to the integer pointed to by atomic.
123 * Also acts as a memory barrier.
124 * atomic:
125 * a pointer to an integer.
126 * val:
127 * the value to add to *atomic.
128 * Since 2.4
130 public static void intAdd(int* atomic, int val)
132 // void g_atomic_int_add (volatile gint *atomic, gint val);
133 g_atomic_int_add(atomic, val);
137 * Atomically adds val to the integer pointed to by atomic. It returns
138 * the value of *atomic just before the addition took place.
139 * Also acts as a memory barrier.
140 * atomic:
141 * a pointer to an integer.
142 * val:
143 * the value to add to *atomic.
144 * Returns:
145 * the value of *atomic before the addition.
146 * Since 2.4
148 public static int intExchangeAndAdd(int* atomic, int val)
150 // gint g_atomic_int_exchange_and_add (volatile gint *atomic, gint val);
151 return g_atomic_int_exchange_and_add(atomic, val);
155 * Compares oldval with the integer pointed to by atomic and
156 * if they are equal, atomically exchanges *atomic with newval.
157 * Also acts as a memory barrier.
158 * atomic:
159 * a pointer to an integer.
160 * oldval:
161 * the assumed old value of *atomic.
162 * newval:
163 * the new value of *atomic.
164 * Returns:
165 * TRUE, if *atomic was equal oldval. FALSE otherwise.
166 * Since 2.4
168 public static int intCompareAndExchange(int* atomic, int oldval, int newval)
170 // gboolean g_atomic_int_compare_and_exchange (volatile gint *atomic, gint oldval, gint newval);
171 return g_atomic_int_compare_and_exchange(atomic, oldval, newval);
175 * Reads the value of the pointer pointed to by atomic. Also acts as
176 * a memory barrier.
177 * atomic:
178 * a pointer to a gpointer.
179 * Returns:
180 * the value to add to *atomic.
181 * Since 2.4
183 public static void* pointerGet(void** atomic)
185 // gpointer g_atomic_pointer_get (volatile gpointer *atomic);
186 return g_atomic_pointer_get(atomic);
190 * Sets the value of the pointer pointed to by atomic.
191 * Also acts as a memory barrier.
192 * atomic:
193 * a pointer to a gpointer
194 * newval:
195 * the new value
196 * Since 2.10
198 public static void pointerSet(void** atomic, void* newval)
200 // void g_atomic_pointer_set (volatile gpointer *atomic, gpointer newval);
201 g_atomic_pointer_set(atomic, newval);
205 * Compares oldval with the pointer pointed to by atomic and
206 * if they are equal, atomically exchanges *atomic with newval.
207 * Also acts as a memory barrier.
208 * atomic:
209 * a pointer to a gpointer.
210 * oldval:
211 * the assumed old value of *atomic.
212 * newval:
213 * the new value of *atomic.
214 * Returns:
215 * TRUE, if *atomic was equal oldval. FALSE otherwise.
216 * Since 2.4
218 public static int pointerCompareAndExchange(void** atomic, void* oldval, void* newval)
220 // gboolean g_atomic_pointer_compare_and_exchange (volatile gpointer *atomic, gpointer oldval, gpointer newval);
221 return g_atomic_pointer_compare_and_exchange(atomic, oldval, newval);
225 * Atomically increments the integer pointed to by atomic by 1.
226 * atomic:
227 * a pointer to an integer.
228 * Since 2.4
230 public static void intInc(int* atomic)
232 // void g_atomic_int_inc (gint *atomic);
233 g_atomic_int_inc(atomic);
237 * Atomically decrements the integer pointed to by atomic by 1.
238 * atomic:
239 * a pointer to an integer.
240 * Returns:
241 * TRUE, if the integer pointed to by atomic is 0 after
242 * decrementing it.
243 * Since 2.4
244 * See Also
245 * GMutex
246 * GLib mutual exclusions.
248 public static int intDecAndTest(int* atomic)
250 // gboolean g_atomic_int_dec_and_test (gint *atomic);
251 return g_atomic_int_dec_and_test(atomic);