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  * Description
66  * The following functions can be used to atomically access integers and
67  * pointers. They are implemented as inline assembler function on most
68  * platforms and use slower fall-backs otherwise. Using them can sometimes
69  * save you from using a performance-expensive GMutex to protect the
70  * integer or pointer.
71  * The most important usage is reference counting. Using
72  * g_atomic_int_inc() and g_atomic_int_dec_and_test() makes reference
73  * counting a very fast operation.
74  * Note
75  * You must not directly read integers or pointers concurrently
76  * accessed by multiple threads, but use the atomic accessor functions
77  * instead. That is, always use g_atomic_int_get() and g_atomic_pointer_get()
78  * for read outs. They provide the neccessary synchonization mechanisms
79  * like memory barriers to access memory locations concurrently.
80  * Note
81  * If you are using those functions for anything apart from
82  * simple reference counting, you should really be aware of the implications
83  * of doing that. There are literally thousands of ways to shoot yourself
84  * in the foot. So if in doubt, use a GMutex. If you don't know, what
85  * memory barriers are, do not use anything but g_atomic_int_inc() and
86  * g_atomic_int_dec_and_test().
87  * Note
88  * It is not safe to set an integer or pointer just by assigning
89  * to it, when it is concurrently accessed by other threads with the following
90  * functions. Use g_atomic_int_compare_and_exchange() or
91  * g_atomic_pointer_compare_and_exchange() respectively.
92  */
93 public class Atomic
94 {
95 	
96 	/**
97 	 */
98 	
99 	/**
100 	 * Reads the value of the integer pointed to by atomic.
101 	 * Also acts as a memory barrier.
102 	 * Since 2.4
103 	 * Params:
104 	 * atomic = a pointer to an integer
105 	 * Returns: the value of *atomic
106 	 */
107 	public static int intGet(int* atomic)
108 	{
109 		// gint g_atomic_int_get (volatile gint G_GNUC_MAY_ALIAS *atomic);
110 		return g_atomic_int_get(atomic);
111 	}
112 	
113 	/**
114 	 * Sets the value of the integer pointed to by atomic.
115 	 * Also acts as a memory barrier.
116 	 * Since 2.10
117 	 * Params:
118 	 * atomic = a pointer to an integer
119 	 * newval = the new value
120 	 */
121 	public static void intSet(int* atomic, int newval)
122 	{
123 		// void g_atomic_int_set (volatile gint G_GNUC_MAY_ALIAS *atomic,  gint newval);
124 		g_atomic_int_set(atomic, newval);
125 	}
126 	
127 	/**
128 	 * Atomically adds val to the integer pointed to by atomic.
129 	 * Also acts as a memory barrier.
130 	 * Since 2.4
131 	 * Params:
132 	 * atomic = a pointer to an integer
133 	 * val = the value to add to *atomic
134 	 */
135 	public static void intAdd(int* atomic, int val)
136 	{
137 		// void g_atomic_int_add (volatile gint G_GNUC_MAY_ALIAS *atomic,  gint val);
138 		g_atomic_int_add(atomic, val);
139 	}
140 	
141 	/**
142 	 * Atomically adds val to the integer pointed to by atomic.
143 	 * It returns the value of *atomic just before the addition
144 	 * took place. Also acts as a memory barrier.
145 	 * Since 2.4
146 	 * Params:
147 	 * atomic = a pointer to an integer
148 	 * val = the value to add to *atomic
149 	 * Returns: the value of *atomic before the addition.
150 	 */
151 	public static int intExchangeAndAdd(int* atomic, int val)
152 	{
153 		// gint g_atomic_int_exchange_and_add (volatile gint G_GNUC_MAY_ALIAS *atomic,  gint val);
154 		return g_atomic_int_exchange_and_add(atomic, val);
155 	}
156 	
157 	/**
158 	 * Compares oldval with the integer pointed to by atomic and
159 	 * if they are equal, atomically exchanges *atomic with newval.
160 	 * Also acts as a memory barrier.
161 	 * Since 2.4
162 	 * Params:
163 	 * atomic = a pointer to an integer
164 	 * oldval = the assumed old value of *atomic
165 	 * newval = the new value of *atomic
166 	 * Returns: TRUE, if *atomic was equal oldval. FALSE otherwise.
167 	 */
168 	public static int intCompareAndExchange(int* atomic, int oldval, int newval)
169 	{
170 		// gboolean g_atomic_int_compare_and_exchange (volatile gint G_GNUC_MAY_ALIAS *atomic,  gint oldval,  gint newval);
171 		return g_atomic_int_compare_and_exchange(atomic, oldval, newval);
172 	}
173 	
174 	/**
175 	 * Reads the value of the pointer pointed to by atomic.
176 	 * Also acts as a memory barrier.
177 	 * Since 2.4
178 	 * Params:
179 	 * atomic = a pointer to a gpointer.
180 	 * Returns: the value to add to *atomic.
181 	 */
182 	public static void* pointerGet(void** atomic)
183 	{
184 		// gpointer g_atomic_pointer_get (volatile gpointer G_GNUC_MAY_ALIAS *atomic);
185 		return g_atomic_pointer_get(atomic);
186 	}
187 	
188 	/**
189 	 * Sets the value of the pointer pointed to by atomic.
190 	 * Also acts as a memory barrier.
191 	 * Since 2.10
192 	 * Params:
193 	 * atomic = a pointer to a gpointer
194 	 * newval = the new value
195 	 */
196 	public static void pointerSet(void** atomic, void* newval)
197 	{
198 		// void g_atomic_pointer_set (volatile gpointer G_GNUC_MAY_ALIAS *atomic,  gpointer newval);
199 		g_atomic_pointer_set(atomic, newval);
200 	}
201 	
202 	/**
203 	 * Compares oldval with the pointer pointed to by atomic and
204 	 * if they are equal, atomically exchanges *atomic with newval.
205 	 * Also acts as a memory barrier.
206 	 * Since 2.4
207 	 * Params:
208 	 * atomic = a pointer to a gpointer
209 	 * oldval = the assumed old value of *atomic
210 	 * newval = the new value of *atomic
211 	 * Returns: TRUE, if *atomic was equal oldval. FALSE otherwise.
212 	 */
213 	public static int pointerCompareAndExchange(void** atomic, void* oldval, void* newval)
214 	{
215 		// gboolean g_atomic_pointer_compare_and_exchange  (volatile gpointer G_GNUC_MAY_ALIAS *atomic,  gpointer oldval,  gpointer newval);
216 		return g_atomic_pointer_compare_and_exchange(atomic, oldval, newval);
217 	}
218 	
219 	/**
220 	 * Atomically increments the integer pointed to by atomic by 1.
221 	 * Since 2.4
222 	 * Params:
223 	 * atomic = a pointer to an integer.
224 	 */
225 	public static void intInc(int* atomic)
226 	{
227 		// void g_atomic_int_inc (gint *atomic);
228 		g_atomic_int_inc(atomic);
229 	}
230 	
231 	/**
232 	 * Atomically decrements the integer pointed to by atomic by 1.
233 	 * Since 2.4
234 	 * Params:
235 	 * atomic = a pointer to an integer
236 	 * Returns: TRUE if the integer pointed to by atomic is 0 after decrementing it
237 	 */
238 	public static int intDecAndTest(int* atomic)
239 	{
240 		// gboolean g_atomic_int_dec_and_test (gint *atomic);
241 		return g_atomic_int_dec_and_test(atomic);
242 	}
243 }