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
50 private import glib
.glibtypes
;
52 private import lib
.glib
;
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
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.
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
70 * They provide the neccessary synchonization mechanisms like memory
71 * barriers to access memory locations concurrently.
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().
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.
92 * Reads the value of the integer pointed to by atomic. Also acts as
95 * a pointer to an integer
97 * the value of *atomic
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.
110 * a pointer to an integer
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.
125 * a pointer to an integer.
127 * the value to add to *atomic.
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.
141 * a pointer to an integer.
143 * the value to add to *atomic.
145 * the value of *atomic before the addition.
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.
159 * a pointer to an integer.
161 * the assumed old value of *atomic.
163 * the new value of *atomic.
165 * TRUE, if *atomic was equal oldval. FALSE otherwise.
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
178 * a pointer to a gpointer.
180 * the value to add to *atomic.
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.
193 * a pointer to a gpointer
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.
209 * a pointer to a gpointer.
211 * the assumed old value of *atomic.
213 * the new value of *atomic.
215 * TRUE, if *atomic was equal oldval. FALSE otherwise.
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.
227 * a pointer to an integer.
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.
239 * a pointer to an integer.
241 * TRUE, if the integer pointed to by atomic is 0 after
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
);