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:
59 import tango
.io
.Stdout
; // use the tango loging?
63 private import gtkc
.gthreadtypes
;
65 private import gtkc
.gthread
;
68 private import glib
.Date
;
69 private import gthread
.Mutex
;
76 * Threads act almost like processes, but unlike processes all threads of
77 * one process share the same memory. This is good, as it provides easy
78 * communication between the involved threads via this shared memory, and
79 * it is bad, because strange things (so called "Heisenbugs") might
80 * happen if the program is not carefully designed. In particular, due to
81 * the concurrent nature of threads, no assumptions on the order of
82 * execution of code running in different threads can be made, unless
83 * order is explicitly forced by the programmer through synchronization
85 * The aim of the thread related functions in GLib is to provide a
86 * portable means for writing multi-threaded software. There are
87 * primitives for mutexes to protect the access to portions of memory
88 * (GMutex, GStaticMutex, G_LOCK_DEFINE, GStaticRecMutex and
89 * GStaticRWLock). There are primitives for condition variables to allow
90 * synchronization of threads (GCond). There are primitives
91 * for thread-private data - data that every thread has a private instance of
92 * (GPrivate, GStaticPrivate). Last but definitely not least there are
93 * primitives to portably create and manage threads (GThread).
94 * You must call g_thread_init() before executing any other GLib
95 * functions in a threaded GLib program. After that, GLib is completely
96 * thread safe (all global data is automatically locked), but individual
97 * data structure instances are not automatically locked for performance
98 * reasons. So, for example you must coordinate accesses to the same
99 * GHashTable from multiple threads. The two notable exceptions from
100 * this rule are GMainLoop and GAsyncQueue,
101 * which are threadsafe and needs no further
102 * application-level locking to be accessed from multiple threads.
107 /** the main Gtk struct */
108 protected GCond
* gCond
;
111 public GCond
* getCondStruct()
117 /** the main Gtk struct as a void* */
118 protected void* getStruct()
120 return cast(void*)gCond
;
124 * Sets our main struct and passes it to the parent class
126 public this (GCond
* gCond
)
135 Stdout("struct gCond is null on constructor").newline
;
139 printf("struct gCond is null on constructor");
146 assert(gCond
!is null, "struct gCond is null on constructor");
214 * Creates a new GCond. This function will abort, if g_thread_init()
215 * has not been called yet.
221 // GCond* g_cond_new ();
222 this(cast(GCond
*)g_cond_new() );
226 * If threads are waiting for cond, exactly one of them is woken up. It
227 * is good practice to hold the same lock as the waiting thread while
228 * calling this function, though not required.
229 * This function can be used even if g_thread_init() has not yet been called,
230 * and, in that case, will do nothing.
236 // void g_cond_signal (GCond *cond);
237 g_cond_signal(gCond
);
241 * If threads are waiting for cond, all of them are woken up. It is good
242 * practice to lock the same mutex as the waiting threads, while calling
243 * this function, though not required.
244 * This function can be used even if g_thread_init() has not yet been called,
245 * and, in that case, will do nothing.
249 public void broadcast()
251 // void g_cond_broadcast (GCond *cond);
252 g_cond_broadcast(gCond
);
256 * Waits until this thread is woken up on cond. The mutex is unlocked
257 * before falling asleep and locked again before resuming.
258 * This function can be used even if g_thread_init() has not yet been
259 * called, and, in that case, will immediately return.
263 * a GMutex, that is currently locked.
265 public void wait(Mutex mutex
)
267 // void g_cond_wait (GCond *cond, GMutex *mutex);
268 g_cond_wait(gCond
, (mutex
is null) ?
null : mutex
.getMutexStruct());
272 * Waits until this thread is woken up on cond, but not longer than
273 * until the time specified by abs_time. The mutex is
274 * unlocked before falling asleep and locked again before resuming.
275 * If abs_time is NULL, g_cond_timed_wait() acts like g_cond_wait().
276 * This function can be used even if g_thread_init() has not yet been
277 * called, and, in that case, will immediately return TRUE.
278 * To easily calculate abs_time a combination of g_get_current_time()
279 * and g_time_val_add() can be used.
283 * a GMutex that is currently locked.
285 * a GTimeVal, determining the final time.
287 * TRUE if cond was signalled, or FALSE on timeout.
289 public int timedWait(Mutex mutex
, GTimeVal
* absTime
)
291 // gboolean g_cond_timed_wait (GCond *cond, GMutex *mutex, GTimeVal *abs_time);
292 return g_cond_timed_wait(gCond
, (mutex
is null) ?
null : mutex
.getMutexStruct(), absTime
);
296 * Destroys the GCond.
302 // void g_cond_free (GCond *cond);