alternative to assert
[gtkD.git] / src / gthread / Mutex.d
blobe37048ecbfdd3ff02f7320883ec7dcc401a7853d
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 = /home/ruimt/data/down/GTK/API/glib/glib-Threads.html
26 * outPack = gthread
27 * outFile = Mutex
28 * strct = GMutex
29 * realStrct=
30 * ctorStrct=
31 * clss = Mutex
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - g_mutex_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * structWrap:
45 * local aliases:
48 module gthread.Mutex;
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 Mutex
88 /** the main Gtk struct */
89 protected GMutex* gMutex;
92 public GMutex* getMutexStruct()
94 return gMutex;
98 /** the main Gtk struct as a void* */
99 protected void* getStruct()
101 return cast(void*)gMutex;
105 * Sets our main struct and passes it to the parent class
107 public this (GMutex* gMutex)
109 this.gMutex = gMutex;
136 * Creates a new GMutex.
137 * Note
138 * This function will abort if g_thread_init() has not been called yet.
139 * Returns:
140 * a new GMutex.
142 public this ()
144 // GMutex* g_mutex_new ();
145 this(cast(GMutex*)g_mutex_new() );
149 * Locks mutex. If mutex is already locked by another thread, the
150 * current thread will block until mutex is unlocked by the other
151 * thread.
152 * This function can be used even if g_thread_init() has not yet been
153 * called, and, in that case, will do nothing.
154 * Note
155 * GMutex is neither guaranteed to be recursive nor to be non-recursive,
156 * i.e. a thread could deadlock while calling g_mutex_lock(), if it
157 * already has locked mutex. Use GStaticRecMutex, if you need recursive
158 * mutexes.
159 * mutex:
160 * a GMutex.
162 public void lock()
164 // void g_mutex_lock (GMutex *mutex);
165 g_mutex_lock(gMutex);
169 * Tries to lock mutex. If mutex is already locked by another
170 * thread, it immediately returns FALSE. Otherwise it locks mutex
171 * and returns TRUE.
172 * This function can be used even if g_thread_init() has not yet been
173 * called, and, in that case, will immediately return TRUE.
174 * Note
175 * GMutex is neither guaranteed to be recursive nor to be non-recursive,
176 * i.e. the return value of g_mutex_trylock() could be both FALSE or
177 * TRUE, if the current thread already has locked mutex. Use
178 * GStaticRecMutex, if you need recursive mutexes.
179 * mutex:
180 * a GMutex.
181 * Returns:
182 * TRUE, if mutex could be locked.
184 public int trylock()
186 // gboolean g_mutex_trylock (GMutex *mutex);
187 return g_mutex_trylock(gMutex);
191 * Unlocks mutex. If another thread is blocked in a g_mutex_lock() call
192 * for mutex, it will be woken and can lock mutex itself.
193 * This function can be used even if g_thread_init() has not yet been
194 * called, and, in that case, will do nothing.
195 * mutex:
196 * a GMutex.
198 public void unlock()
200 // void g_mutex_unlock (GMutex *mutex);
201 g_mutex_unlock(gMutex);
205 * Destroys mutex.
206 * mutex:
207 * a GMutex.
209 public void free()
211 // void g_mutex_free (GMutex *mutex);
212 g_mutex_free(gMutex);