alternative to assert
[gtkD.git] / src / gthread / StaticRecMutex.d
blob2caf4b058a21ead3dabd997367bda594b4437b54
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 =
26 * outPack = gthread
27 * outFile = StaticRecMutex
28 * strct = GStaticRecMutex
29 * realStrct=
30 * ctorStrct=
31 * clss = StaticRecMutex
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - g_static_rec_mutex_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * structWrap:
45 * local aliases:
48 module gthread.StaticRecMutex;
50 private import gthread.gthreadtypes;
52 private import lib.gthread;
55 /**
56 * Description
57 * Threads act almost like processes, but unlike processes all threads of
58 * one process share the same memory. This is good, as it provides easy
59 * communication between the involved threads via this shared memory, and
60 * it is bad, because strange things (so called "Heisenbugs") might
61 * happen if the program is not carefully designed. In particular, due to
62 * the concurrent nature of threads, no assumptions on the order of
63 * execution of code running in different threads can be made, unless
64 * order is explicitly forced by the programmer through synchronization
65 * primitives.
66 * The aim of the thread related functions in GLib is to provide a
67 * portable means for writing multi-threaded software. There are
68 * primitives for mutexes to protect the access to portions of memory
69 * (GMutex, GStaticMutex, G_LOCK_DEFINE, GStaticRecMutex and
70 * GStaticRWLock). There are primitives for condition variables to allow
71 * synchronization of threads (GCond). There are primitives
72 * for thread-private data - data that every thread has a private instance of
73 * (GPrivate, GStaticPrivate). Last but definitely not least there are
74 * primitives to portably create and manage threads (GThread).
75 * You must call g_thread_init() before executing any other GLib
76 * functions in a threaded GLib program. After that, GLib is completely
77 * thread safe (all global data is automatically locked), but individual
78 * data structure instances are not automatically locked for performance
79 * reasons. So, for example you must coordinate accesses to the same
80 * GHashTable from multiple threads. The two notable exceptions from
81 * this rule are GMainLoop and GAsyncQueue,
82 * which are threadsafe and needs no further
83 * application-level locking to be accessed from multiple threads.
85 public class StaticRecMutex
88 /** the main Gtk struct */
89 protected GStaticRecMutex* gStaticRecMutex;
92 public GStaticRecMutex* getStaticRecMutexStruct()
94 return gStaticRecMutex;
98 /** the main Gtk struct as a void* */
99 protected void* getStruct()
101 return cast(void*)gStaticRecMutex;
105 * Sets our main struct and passes it to the parent class
107 public this (GStaticRecMutex* gStaticRecMutex)
109 this.gStaticRecMutex = gStaticRecMutex;
157 * A GStaticRecMutex must be initialized with this function before it
158 * can be used. Alternatively you can initialize it with
159 * G_STATIC_REC_MUTEX_INIT.
160 * mutex:
161 * a GStaticRecMutex to be initialized.
163 public void init()
165 // void g_static_rec_mutex_init (GStaticRecMutex *mutex);
166 g_static_rec_mutex_init(gStaticRecMutex);
170 * Locks mutex. If mutex is already locked by another thread, the
171 * current thread will block until mutex is unlocked by the other
172 * thread. If mutex is already locked by the calling thread, this
173 * functions increases the depth of mutex and returns immediately.
174 * mutex:
175 * a GStaticRecMutex to lock.
177 public void lock()
179 // void g_static_rec_mutex_lock (GStaticRecMutex *mutex);
180 g_static_rec_mutex_lock(gStaticRecMutex);
184 * Tries to lock mutex. If mutex is already locked by another thread,
185 * it immediately returns FALSE. Otherwise it locks mutex and returns
186 * TRUE. If mutex is already locked by the calling thread, this
187 * functions increases the depth of mutex and immediately returns TRUE.
188 * mutex:
189 * a GStaticRecMutex to lock.
190 * Returns:
191 * TRUE, if mutex could be locked.
193 public int trylock()
195 // gboolean g_static_rec_mutex_trylock (GStaticRecMutex *mutex);
196 return g_static_rec_mutex_trylock(gStaticRecMutex);
200 * Unlocks mutex. Another thread can will be allowed to lock mutex only
201 * when it has been unlocked as many times as it had been locked
202 * before. If mutex is completely unlocked and another thread is blocked
203 * in a g_static_rec_mutex_lock() call for mutex, it will be woken and
204 * can lock mutex itself.
205 * mutex:
206 * a GStaticRecMutex to unlock.
208 public void unlock()
210 // void g_static_rec_mutex_unlock (GStaticRecMutex *mutex);
211 g_static_rec_mutex_unlock(gStaticRecMutex);
215 * Works like calling g_static_rec_mutex_lock() for mutex depth times.
216 * mutex:
217 * a GStaticRecMutex to lock.
218 * depth:
219 * number of times this mutex has to be unlocked to be completely unlocked.
221 public void lockFull(uint depth)
223 // void g_static_rec_mutex_lock_full (GStaticRecMutex *mutex, guint depth);
224 g_static_rec_mutex_lock_full(gStaticRecMutex, depth);
228 * Completely unlocks mutex. If another thread is blocked in a
229 * g_static_rec_mutex_lock() call for mutex, it will be woken and can
230 * lock mutex itself. This function returns the number of times that
231 * mutex has been locked by the current thread. To restore the state
232 * before the call to g_static_rec_mutex_unlock_full() you can call
233 * g_static_rec_mutex_lock_full() with the depth returned by this
234 * function.
235 * mutex:
236 * a GStaticRecMutex to completely unlock.
237 * Returns:
238 * number of times mutex has been locked by the current thread.
240 public uint unlockFull()
242 // guint g_static_rec_mutex_unlock_full (GStaticRecMutex *mutex);
243 return g_static_rec_mutex_unlock_full(gStaticRecMutex);
247 * Releases all resources allocated to a GStaticRecMutex.
248 * You don't have to call this functions for a GStaticRecMutex with an
249 * unbounded lifetime, i.e. objects declared 'static', but if you have a
250 * GStaticRecMutex as a member of a structure and the structure is
251 * freed, you should also free the GStaticRecMutex.
252 * mutex:
253 * a GStaticRecMutex to be freed.
255 public void free()
257 // void g_static_rec_mutex_free (GStaticRecMutex *mutex);
258 g_static_rec_mutex_free(gStaticRecMutex);