2 * This file is part of gtkD.
4 * gtkD 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 * gtkD 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 gtkD; 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-Threads.html
55 import tango
.io
.Stdout
; // use the tango loging?
59 private import gtkc
.gthreadtypes
;
61 private import gtkc
.gthread
;
70 * Threads act almost like processes, but unlike processes all threads of
71 * one process share the same memory. This is good, as it provides easy
72 * communication between the involved threads via this shared memory, and
73 * it is bad, because strange things (so called "Heisenbugs") might
74 * happen if the program is not carefully designed. In particular, due to
75 * the concurrent nature of threads, no assumptions on the order of
76 * execution of code running in different threads can be made, unless
77 * order is explicitly forced by the programmer through synchronization
79 * The aim of the thread related functions in GLib is to provide a
80 * portable means for writing multi-threaded software. There are
81 * primitives for mutexes to protect the access to portions of memory
82 * (GMutex, GStaticMutex, G_LOCK_DEFINE, GStaticRecMutex and
83 * GStaticRWLock). There are primitives for condition variables to allow
84 * synchronization of threads (GCond). There are primitives
85 * for thread-private data - data that every thread has a private instance of
86 * (GPrivate, GStaticPrivate). Last but definitely not least there are
87 * primitives to portably create and manage threads (GThread).
88 * You must call g_thread_init() before executing any other GLib
89 * functions in a threaded GLib program. After that, GLib is completely
90 * thread safe (all global data is automatically locked), but individual
91 * data structure instances are not automatically locked for performance
92 * reasons. So, for example you must coordinate accesses to the same
93 * GHashTable from multiple threads. The two notable exceptions from
94 * this rule are GMainLoop and GAsyncQueue,
95 * which are threadsafe and needs no further
96 * application-level locking to be accessed from multiple threads.
101 /** the main Gtk struct */
102 protected GMutex
* gMutex
;
105 public GMutex
* getMutexStruct()
111 /** the main Gtk struct as a void* */
112 protected void* getStruct()
114 return cast(void*)gMutex
;
118 * Sets our main struct and passes it to the parent class
120 public this (GMutex
* gMutex
)
124 if ( gMutex
is null )
129 Stdout("struct gMutex is null on constructor").newline
;
133 printf("struct gMutex is null on constructor");
140 assert(gMutex
!is null, "struct gMutex is null on constructor");
142 this.gMutex
= gMutex
;
169 * Creates a new GMutex.
171 * This function will abort if g_thread_init() has not been called yet.
177 // GMutex* g_mutex_new ();
178 this(cast(GMutex
*)g_mutex_new() );
182 * Locks mutex. If mutex is already locked by another thread, the
183 * current thread will block until mutex is unlocked by the other
185 * This function can be used even if g_thread_init() has not yet been
186 * called, and, in that case, will do nothing.
188 * GMutex is neither guaranteed to be recursive nor to be non-recursive,
189 * i.e. a thread could deadlock while calling g_mutex_lock(), if it
190 * already has locked mutex. Use GStaticRecMutex, if you need recursive
197 // void g_mutex_lock (GMutex *mutex);
198 g_mutex_lock(gMutex
);
202 * Tries to lock mutex. If mutex is already locked by another
203 * thread, it immediately returns FALSE. Otherwise it locks mutex
205 * This function can be used even if g_thread_init() has not yet been
206 * called, and, in that case, will immediately return TRUE.
208 * GMutex is neither guaranteed to be recursive nor to be non-recursive,
209 * i.e. the return value of g_mutex_trylock() could be both FALSE or
210 * TRUE, if the current thread already has locked mutex. Use
211 * GStaticRecMutex, if you need recursive mutexes.
215 * TRUE, if mutex could be locked.
219 // gboolean g_mutex_trylock (GMutex *mutex);
220 return g_mutex_trylock(gMutex
);
224 * Unlocks mutex. If another thread is blocked in a g_mutex_lock() call
225 * for mutex, it will be woken and can lock mutex itself.
226 * This function can be used even if g_thread_init() has not yet been
227 * called, and, in that case, will do nothing.
233 // void g_mutex_unlock (GMutex *mutex);
234 g_mutex_unlock(gMutex
);
244 // void g_mutex_free (GMutex *mutex);
245 g_mutex_free(gMutex
);