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
23 module gthread
.gthreadtypes
;
26 public import glib
.glibtypes
;
29 * Possible errors of thread related functions.
30 * G_THREAD_ERROR_AGAIN
31 * a thread couldn't be created due to resource
32 * shortage. Try again later.
34 public enum GThreadError
36 AGAIN
/+* Resource temporarily unavailable +/
38 alias GThreadError ThreadError
;
41 * Specifies the priority of a thread.
43 * It is not guaranteed that threads with different priorities really
44 * behave accordingly. On some systems (e.g. Linux) there are no thread
45 * priorities. On other systems (e.g. Solaris) there doesn't seem to be
46 * different scheduling for different priorities. All in all try to avoid
47 * being dependent on priorities.
48 * G_THREAD_PRIORITY_LOW
49 * a priority lower than normal
50 * G_THREAD_PRIORITY_NORMAL
51 * the default priority
52 * G_THREAD_PRIORITY_HIGH
53 * a priority higher than normal
54 * G_THREAD_PRIORITY_URGENT
55 * the highest priority
57 public enum GThreadPriority
64 alias GThreadPriority ThreadPriority
;
67 * The possible statuses of a one-time initialization function controlled by a GOnce struct.
68 * G_ONCE_STATUS_NOTCALLED
69 * the function has not been called yet.
70 * G_ONCE_STATUS_PROGRESS
71 * the function call is currently in progress.
73 * the function has been called.
76 public enum GOnceStatus
82 alias GOnceStatus OnceStatus
;
86 * This function table is used by g_thread_init() to initialize the
87 * thread system. The functions in the table are directly used by their
88 * g_* prepended counterparts (described in this document). For example,
89 * if you call g_mutex_new() then mutex_new() from the table provided to
90 * g_thread_init() will be called.
92 * Do not use this struct unless you know what you are doing.
94 public struct GThreadFunctions
{}
95 // GMutex* (*mutexNew) (void);
97 // void (*mutexLock) (GMutex *mutex);
99 // int (*mutexTrylock) (GMutex *mutex);
101 // void (*mutexUnlock) (GMutex *mutex);
103 // void (*mutexFree) (GMutex *mutex);
105 // GCond* (*condNew) (void);
107 // void (*condSignal) (GCond *cond);
109 // void (*condBroadcast) (GCond *cond);
111 // void (*condWait) (GCond *cond,
115 // int (*condTimedWait) (GCond *cond,
119 // GTimeVal *endTime);
121 // void (*condFree) (GCond *cond);
123 // GPrivate* (*privateNew) (GDestroyNotify destructor);
125 // void* (*privateGet) (GPrivate *privateKey);
127 // void (*privateSet) (GPrivate *privateKey,
131 // void (*threadCreate) (GThreadFunc func,
141 // GThreadPriority priority,
147 // void (*threadYield) (void);
149 // void (*threadJoin) (void* thread);
151 // void (*threadExit) (void);
153 // void (*threadSetPriority)(void* thread,
155 // GThreadPriority priority);
157 // void (*threadSelf) (void* thread);
159 // int (*threadEqual) (void* thread1,
167 * The GThread struct represents a running thread. It has three public
168 * read-only members, but the underlying struct is bigger, so you must
169 * not copy this struct.
171 * Resources for a joinable thread are not fully released until
172 * g_thread_join() is called for that thread.
174 public struct GThread
{}
178 * The GMutex struct is an opaque data structure to represent a mutex
179 * (mutual exclusion). It can be used to protect data against shared
180 * access. Take for example the following function:
181 * Example3.A function which will not work in a threaded environment
183 public struct GMutex
{}
187 * A GStaticMutex works like a GMutex, but it has one significant
188 * advantage. It doesn't need to be created at run-time like a GMutex,
189 * but can be defined at compile-time. Here is a shorter, easier and
190 * safer version of our give_me_next_number() example:
191 * Example6.Using GStaticMutex to simplify thread-safe programming
193 public struct GStaticMutex
{}
197 * A GStaticRecMutex works like a GStaticMutex, but it can be locked
198 * multiple times by one thread. If you enter it n times, you have to
199 * unlock it n times again to let other threads lock it. An exception is
200 * the function g_static_rec_mutex_unlock_full(): that allows you to
201 * unlock a GStaticRecMutex completely returning the depth, (i.e. the
202 * number of times this mutex was locked). The depth can later be used to
203 * restore the state of the GStaticRecMutex by calling
204 * g_static_rec_mutex_lock_full().
205 * Even though GStaticRecMutex is not opaque, it should only be used with
206 * the following functions.
207 * All of the g_static_rec_mutex_* functions can
208 * be used even if g_thread_init() has not been called.
210 public struct GStaticRecMutex
{}
214 * The GStaticRWLock struct represents a read-write lock. A read-write
215 * lock can be used for protecting data that some portions of code only
216 * read from, while others also write. In such situations it is
217 * desirable that several readers can read at once, whereas of course
218 * only one writer may write at a time. Take a look at the following
220 * Example8.An array with access functions
222 public struct GStaticRWLock
{}
226 * The GCond struct is an opaque data structure that represents a
227 * condition. Threads can block on a GCond if they find a certain
228 * condition to be false. If other threads change the state of this
229 * condition they signal the GCond, and that causes the waiting threads
231 * Example9.Using GCond to block a thread until a condition is satisfied
232 * GCond* data_cond = NULL; /+* Must be initialized somewhere +/
233 * GMutex* data_mutex = NULL; /+* Must be initialized somewhere +/
234 * gpointer current_data = NULL;
235 * void push_data (gpointer data)
238 public struct GCond
{}
242 * The GPrivate struct is an opaque data structure to represent a thread
243 * private data key. Threads can thereby obtain and set a pointer which
244 * is private to the current thread.
245 * Take our give_me_next_number() example from above.
246 * Suppose we don't want current_number to be shared
247 * between the threads, but instead to be private to each thread. This can be
249 * Example10.Using GPrivate for per-thread data
251 public struct GPrivate
{}
255 * A GStaticPrivate works almost like a GPrivate, but it has one
256 * significant advantage. It doesn't need to be created at run-time like
257 * a GPrivate, but can be defined at compile-time. This is similar to
258 * the difference between GMutex and GStaticMutex. Now look at our
259 * give_me_next_number() example with GStaticPrivate:
260 * Example11.Using GStaticPrivate for per-thread data
262 public struct GStaticPrivate
{}
266 * A GOnce struct controls a one-time initialization
267 * function. Any one-time initialization function must have its own unique
269 * volatileGOnceStatusstatus;
270 * the status of the GOnce
271 * volatilegpointerretval;
272 * the value returned by the call to the function, if status
282 * The G_LOCK_* macros provide a convenient interface to GStaticMutex
283 * with the advantage that they will expand to nothing in programs
284 * compiled against a thread-disabled GLib, saving code and memory
285 * there. G_LOCK_DEFINE defines a lock. It can appear anywhere variable
286 * definitions may appear in programs, i.e. in the first block of a
287 * function or outside of functions. The name parameter will be mangled
288 * to get the name of the GStaticMutex. This means that you can use
289 * names of existing variables as the parameter - e.g. the name of the
290 * variable you intent to protect with the lock. Look at our
291 * give_me_next_number() example using the G_LOCK_* macros:
292 * Example7.Using the G_LOCK_* convenience macros
293 * G_LOCK_DEFINE (current_number);
294 * int give_me_next_number ()
296 * static int current_number = 0;
298 * G_LOCK (current_number);
299 * ret_val = current_number = calc_next_number (current_number);
300 * G_UNLOCK (current_number);
304 * the name of the lock.
307 // #define G_LOCK_DEFINE(name)
310 * This works like G_LOCK_DEFINE, but it creates a static object.
312 * the name of the lock.
315 // #define G_LOCK_DEFINE_STATIC(name)
318 * This declares a lock, that is defined with G_LOCK_DEFINE in another module.
320 * the name of the lock.
323 // #define G_LOCK_EXTERN(name)
326 * Works like g_mutex_lock(), but for a lock defined with G_LOCK_DEFINE.
328 * the name of the lock.
331 // #define G_LOCK(name)
334 * Works like g_mutex_trylock(), but for a lock defined with G_LOCK_DEFINE.
336 * the name of the lock.
338 * TRUE, if the lock could be locked.
341 // #define G_TRYLOCK(name)
344 * Works like g_mutex_unlock(), but for a lock defined with G_LOCK_DEFINE.
346 * the name of the lock.
349 // #define G_UNLOCK(name)
352 * The first call to this routine by a process with a given GOnce struct calls
353 * func with the given argument. Thereafter, subsequent calls to g_once() with
354 * the same GOnce struct do not call func again, but return the stored result
355 * of the first call. On return from g_once(), the status of once will be
356 * G_ONCE_STATUS_READY.
357 * For example, a mutex or a thread-specific data key must be created exactly
358 * once. In a threaded environment, calling g_once() ensures that the
359 * initialization is serialized across multiple threads.
361 * Calling g_once() recursively on the same GOnce struct in func will lead
366 * static GOnce my_once = G_ONCE_INIT;
367 * g_once (my_once, parse_debug_flags, NULL);
368 * return my_once.retval;
373 * the GThreadFunc function associated to once. This function is
374 * called only once, regardless of the number of times it and its
375 * associated GOnce struct are passed to g_once() .
377 * data to be passed to func
383 * Send asynchronous messages between threads.
386 // #define g_once(once, func, arg)
389 * Specifies the type of the func functions passed to
390 * g_thread_create() or g_thread_create_full().
392 * data passed to the thread.
394 * the return value of the thread, which will be returned by
397 // gpointer (*GThreadFunc) (gpointer data);
398 public typedef extern(C
) void* function (void*) GThreadFunc
;