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:
43 * - g_static_rec_mutex_
56 * - GDataset* -> Dataset
59 * - GSource* -> Source
60 * - GThread* -> Thread
64 module gthread
.Thread
;
66 private import gthread
.gthreadtypes
;
68 private import lib
.gthread
;
70 private import glib
.ErrorG
;
71 private import gthread
.Mutex
;
72 private import glib
.Source
;
73 private import glib
.Dataset
;
74 private import glib
.ListG
;
78 * Threads act almost like processes, but unlike processes all threads of
79 * one process share the same memory. This is good, as it provides easy
80 * communication between the involved threads via this shared memory, and
81 * it is bad, because strange things (so called "Heisenbugs") might
82 * happen if the program is not carefully designed. In particular, due to
83 * the concurrent nature of threads, no assumptions on the order of
84 * execution of code running in different threads can be made, unless
85 * order is explicitly forced by the programmer through synchronization
87 * The aim of the thread related functions in GLib is to provide a
88 * portable means for writing multi-threaded software. There are
89 * primitives for mutexes to protect the access to portions of memory
90 * (GMutex, GStaticMutex, G_LOCK_DEFINE, GStaticRecMutex and
91 * GStaticRWLock). There are primitives for condition variables to allow
92 * synchronization of threads (GCond). There are primitives
93 * for thread-private data - data that every thread has a private instance of
94 * (GPrivate, GStaticPrivate). Last but definitely not least there are
95 * primitives to portably create and manage threads (GThread).
96 * You must call g_thread_init() before executing any other GLib
97 * functions in a threaded GLib program. After that, GLib is completely
98 * thread safe (all global data is automatically locked), but individual
99 * data structure instances are not automatically locked for performance
100 * reasons. So, for example you must coordinate accesses to the same
101 * GHashTable from multiple threads. The two notable exceptions from
102 * this rule are GMainLoop and GAsyncQueue,
103 * which are threadsafe and needs no further
104 * application-level locking to be accessed from multiple threads.
109 /** the main Gtk struct */
110 protected GThread
* gThread
;
113 public GThread
* getThreadStruct()
119 /** the main Gtk struct as a void* */
120 protected void* getStruct()
122 return cast(void*)gThread
;
126 * Sets our main struct and passes it to the parent class
128 public this (GThread
* gThread
)
130 this.gThread
= gThread
;
143 * If you use GLib from more than one thread, you must initialize
144 * the thread system by calling g_thread_init(). Most of the time you
145 * will only have to call g_thread_init (NULL).
147 * Do not call g_thread_init() with a non-NULL parameter unless you
148 * really know what you are doing.
150 * g_thread_init() must not be called directly or indirectly as a
151 * callback from GLib. Also no mutexes may be currently locked while
152 * calling g_thread_init().
153 * g_thread_init() might only be called once. On the second call
154 * it will abort with an error. If you want to make sure that the thread
155 * system is initialized, you can do this:
156 * if (!g_thread_supported ()) g_thread_init (NULL);
157 * After that line, either the thread system is initialized or, if no
158 * thread system is available in GLib (i.e. either G_THREADS_ENABLED is
159 * not defined or G_THREADS_IMPL_NONE is defined), the program will
161 * If no thread system is available and vtable is NULL or if not all
162 * elements of vtable are non-NULL, then g_thread_init() will abort.
164 * To use g_thread_init() in your program, you have to link with the
165 * libraries that the command pkg-config --libs gthread-2.0
166 * outputs. This is not the case for all the other thread related functions of
167 * GLib. Those can be used without having to link with the thread libraries.
169 * a function table of type GThreadFunctions, that provides the
170 * entry points to the thread system to be used.
172 public static void init(GThreadFunctions
* vtable
)
174 // void g_thread_init (GThreadFunctions *vtable);
175 g_thread_init(vtable
);
179 * This function returns TRUE if the thread system is initialized, and
180 * FALSE if it is not.
182 * This function is actually a macro. Apart from taking the address of it
183 * you can however use it as if it was a function.
185 * TRUE, if the thread system is initialized.
187 public static int supported()
189 // gboolean g_thread_supported ();
190 return g_thread_supported();
197 * This function creates a new thread with the default priority.
198 * If joinable is TRUE, you can wait for this threads termination
199 * calling g_thread_join(). Otherwise the thread will just disappear when
201 * The new thread executes the function func with the argument
202 * data. If the thread was created successfully, it is returned.
203 * error can be NULL to ignore errors, or non-NULL to report errors. The
204 * error is set, if and only if the function returns NULL.
206 * a function to execute in the new thread.
208 * an argument to supply to the new thread.
210 * should this thread be joinable?
212 * return location for error.
214 * the new GThread on success.
216 public static Thread
create(GThreadFunc func
, void* data
, int joinable
, GError
** error
)
218 // GThread* g_thread_create (GThreadFunc func, gpointer data, gboolean joinable, GError **error);
219 return new Thread( g_thread_create(func
, data
, joinable
, error
) );
223 * This function creates a new thread with the priority priority. If the
224 * underlying thread implementation supports it, the thread gets a stack
225 * size of stack_size or the default value for the current platform, if
227 * If joinable is TRUE, you can wait for this threads termination
228 * calling g_thread_join(). Otherwise the thread will just disappear when
229 * it terminates. If bound is TRUE, this thread will be scheduled in
230 * the system scope, otherwise the implementation is free to do
231 * scheduling in the process scope. The first variant is more expensive
232 * resource-wise, but generally faster. On some systems (e.g. Linux) all
234 * The new thread executes the function func with the argument
235 * data. If the thread was created successfully, it is returned.
236 * error can be NULL to ignore errors, or non-NULL to report errors. The
237 * error is set, if and only if the function returns NULL.
239 * It is not guaranteed that threads with different priorities really
240 * behave accordingly. On some systems (e.g. Linux) there are no thread
241 * priorities. On other systems (e.g. Solaris) there doesn't seem to be
242 * different scheduling for different priorities. All in all try to avoid
243 * being dependent on priorities. Use G_THREAD_PRIORITY_NORMAL here as a
246 * Only use g_thread_create_full() if you really can't use
247 * g_thread_create() instead. g_thread_create() does not take
248 * stack_size, bound, and priority as arguments, as they should only
249 * be used in cases in which it is unavoidable.
251 * a function to execute in the new thread.
253 * an argument to supply to the new thread.
255 * a stack size for the new thread.
257 * should this thread be joinable?
259 * should this thread be bound to a system thread?
261 * a priority for the thread.
263 * return location for error.
265 * the new GThread on success.
267 public static Thread
createFull(GThreadFunc func
, void* data
, uint stackSize
, int joinable
, int bound, GThreadPriority priority
, GError
** error
)
269 // GThread* g_thread_create_full (GThreadFunc func, gpointer data, gulong stack_size, gboolean joinable, gboolean bound, GThreadPriority priority, GError **error);
270 return new Thread( g_thread_create_full(func
, data
, stackSize
, joinable
, bound, priority
, error
) );
274 * This functions returns the GThread corresponding to the calling thread.
276 * the current thread.
278 public static Thread
self()
280 // GThread* g_thread_self (void);
281 return new Thread( g_thread_self() );
285 * Waits until thread finishes, i.e. the function func, as given
286 * to g_thread_create(), returns or g_thread_exit() is called by
287 * thread. All resources of thread including the GThread struct are
288 * released. thread must have been created with joinable=TRUE in
289 * g_thread_create(). The value returned by func or given to
290 * g_thread_exit() by thread is returned by this function.
292 * a GThread to be waited for.
294 * the return value of the thread.
298 // gpointer g_thread_join (GThread *thread);
299 return g_thread_join(gThread
);
303 * Changes the priority of thread to priority.
305 * It is not guaranteed that threads with different priorities really
306 * behave accordingly. On some systems (e.g. Linux) there are no thread
307 * priorities. On other systems (e.g. Solaris) there doesn't seem to be
308 * different scheduling for different priorities. All in all try to avoid
309 * being dependent on priorities.
313 * a new priority for thread.
315 public void setPriority(GThreadPriority priority
)
317 // void g_thread_set_priority (GThread *thread, GThreadPriority priority);
318 g_thread_set_priority(gThread
, priority
);
322 * Gives way to other threads waiting to be scheduled.
323 * This function is often used as a method to make busy wait less
324 * evil. But in most cases you will encounter, there are better methods
325 * to do that. So in general you shouldn't use this function.
327 public static void yield()
329 // void g_thread_yield ();
334 * Exits the current thread. If another thread is waiting for that thread
335 * using g_thread_join() and the current thread is joinable, the waiting
336 * thread will be woken up and get retval as the return value of
337 * g_thread_join(). If the current thread is not joinable, retval is
339 * g_thread_exit (retval);
340 * is equivalent to calling
342 * in the function func, as given to g_thread_create().
344 * Never call g_thread_exit() from within a thread of a GThreadPool, as
345 * that will mess up the bookkeeping and lead to funny and unwanted results.
347 * the return value of this thread.
349 public static void exit(void* retval
)
351 // void g_thread_exit (gpointer retval);
352 g_thread_exit(retval
);
356 * Call thread_func on all existing GThread structures. Note that
357 * threads may decide to exit while thread_func is running, so
358 * without intimate knowledge about the lifetime of foreign threads,
359 * thread_func shouldn't access the GThread* pointer passed in as
360 * first argument. However, thread_func will not be called for threads
361 * which are known to have exited already.
362 * Due to thread lifetime checks, this function has an execution complexity
363 * which is quadratic in the number of existing threads.
365 * function to call for all GThread structures
367 * second argument to thread_func
370 public static void foreac(GFunc threadFunc
, void* userData
)
372 // void g_thread_foreach (GFunc thread_func, gpointer user_data);
373 g_thread_foreach(threadFunc
, userData
);
385 * Initializes mutex. Alternatively you can initialize it with
386 * G_STATIC_MUTEX_INIT.
388 * a GStaticMutex to be initialized.
390 public static void gStaticMutexInit(GStaticMutex
* mutex
)
392 // void g_static_mutex_init (GStaticMutex *mutex);
393 g_static_mutex_init(mutex
);
397 * Works like g_mutex_lock(), but for a GStaticMutex.
401 public static void gStaticMutexLock(GStaticMutex
* mutex
)
403 // void g_static_mutex_lock (GStaticMutex *mutex);
404 g_static_mutex_lock(mutex
);
408 * Works like g_mutex_trylock(), but for a GStaticMutex.
412 * TRUE, if the GStaticMutex could be locked.
414 public static int gStaticMutexTrylock(GStaticMutex
* mutex
)
416 // gboolean g_static_mutex_trylock (GStaticMutex *mutex);
417 return g_static_mutex_trylock(mutex
);
421 * Works like g_mutex_unlock(), but for a GStaticMutex.
425 public static void gStaticMutexUnlock(GStaticMutex
* mutex
)
427 // void g_static_mutex_unlock (GStaticMutex *mutex);
428 g_static_mutex_unlock(mutex
);
432 * For some operations (like g_cond_wait()) you must have a GMutex
433 * instead of a GStaticMutex. This function will return the
434 * corresponding GMutex for mutex.
438 * the GMutex corresponding to mutex.
440 public static Mutex
gStaticMutexGetMutex(GStaticMutex
* mutex
)
442 // GMutex* g_static_mutex_get_mutex (GStaticMutex *mutex);
443 return new Mutex( g_static_mutex_get_mutex(mutex
) );
447 * Releases all resources allocated to mutex.
448 * You don't have to call this functions for a GStaticMutex with an
449 * unbounded lifetime, i.e. objects declared 'static', but if you have a
450 * GStaticMutex as a member of a structure and the structure is freed,
451 * you should also free the GStaticMutex.
453 * a GStaticMutex to be freed.
455 public static void gStaticMutexFree(GStaticMutex
* mutex
)
457 // void g_static_mutex_free (GStaticMutex *mutex);
458 g_static_mutex_free(mutex
);