1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 module gtkc.gthreadtypes;
25 
26 
27 public import gtkc.glibtypes;
28 
29 /**
30  * Possible errors of thread related functions.
31  * G_THREAD_ERROR_AGAIN
32  * a thread couldn't be created due to resource
33  *  shortage. Try again later.
34  */
35 public enum GThreadError
36 {
37 	AGAIN /+* Resource temporarily unavailable +/
38 }
39 alias GThreadError ThreadError;
40 
41 /**
42  * Specifies the priority of a thread.
43  * Note
44  * It is not guaranteed that threads with different priorities
45  * really behave accordingly. On some systems (e.g. Linux) there are no
46  * thread priorities. On other systems (e.g. Solaris) there doesn't
47  * seem to be different scheduling for different priorities. All in all
48  * try to avoid being dependent on priorities.
49  * G_THREAD_PRIORITY_LOW
50  * a priority lower than normal
51  * G_THREAD_PRIORITY_NORMAL
52  * the default priority
53  * G_THREAD_PRIORITY_HIGH
54  * a priority higher than normal
55  * G_THREAD_PRIORITY_URGENT
56  * the highest priority
57  */
58 public enum GThreadPriority
59 {
60 	LOW,
61 	NORMAL,
62 	HIGH,
63 	URGENT
64 }
65 alias GThreadPriority ThreadPriority;
66 
67 /**
68  * The possible statuses of a one-time initialization function
69  * controlled by a GOnce struct.
70  * G_ONCE_STATUS_NOTCALLED
71  * the function has not been called yet.
72  * G_ONCE_STATUS_PROGRESS
73  * the function call is currently in progress.
74  * G_ONCE_STATUS_READY
75  * the function has been called.
76  * Since 2.4
77  */
78 public enum GOnceStatus
79 {
80 	NOTCALLED,
81 	PROGRESS,
82 	READY
83 }
84 alias GOnceStatus OnceStatus;
85 
86 
87 /**
88  * This function table is used by g_thread_init() to initialize the
89  * thread system. The functions in the table are directly used by their
90  * g_* prepended counterparts (described in this document). For
91  * example, if you call g_mutex_new() then mutex_new() from the table
92  * provided to g_thread_init() will be called.
93  * Note
94  * Do not use this struct unless you know what you are
95  * doing.
96  * mutex_new ()
97  * virtual function pointer for g_mutex_new()
98  * mutex_lock ()
99  * virtual function pointer for g_mutex_lock()
100  * mutex_trylock ()
101  * virtual function pointer for g_mutex_trylock()
102  * mutex_unlock ()
103  * virtual function pointer for g_mutex_unlock()
104  * mutex_free ()
105  * virtual function pointer for g_mutex_free()
106  * cond_new ()
107  * virtual function pointer for g_cond_new()
108  * cond_signal ()
109  * virtual function pointer for g_cond_signal()
110  * cond_broadcast ()
111  * virtual function pointer for g_cond_broadcast()
112  * cond_wait ()
113  * virtual function pointer for g_cond_wait()
114  * cond_timed_wait ()
115  * virtual function pointer for g_cond_timed_wait()
116  * cond_free ()
117  * virtual function pointer for g_cond_free()
118  * private_new ()
119  * virtual function pointer for g_private_new()
120  * private_get ()
121  * virtual function pointer for g_private_get()
122  * private_set ()
123  * virtual function pointer for g_private_set()
124  * thread_create ()
125  * virtual function pointer for g_thread_create()
126  * thread_yield ()
127  * virtual function pointer for g_thread_yield()
128  * thread_join ()
129  * virtual function pointer for g_thread_join()
130  * thread_exit ()
131  * virtual function pointer for g_thread_exit()
132  * thread_set_priority ()
133  * virtual function pointer for
134  * g_thread_set_priority()
135  * thread_self ()
136  * virtual function pointer for g_thread_self()
137  * thread_equal ()
138  * used internally by recursive mutex locks and by some
139  * assertion checks
140  */
141 public struct GThreadFunctions
142 {
143 	extern(C) GMutex* function() mutexNew;
144 	extern(C) void function(GMutex* mutex) mutexLock;
145 	extern(C) int function(GMutex* mutex) mutexTrylock;
146 	extern(C) void function(GMutex* mutex) mutexUnlock;
147 	extern(C) void function(GMutex* mutex) mutexFree;
148 	extern(C) GCond* function() condNew;
149 	extern(C) void function(GCond* cond) condSignal;
150 	extern(C) void function(GCond* cond) condBroadcast;
151 	extern(C) void function(GCond* cond, GMutex* mutex) condWait;
152 	extern(C) int function(GCond* cond, GMutex* mutex, GTimeVal* endTime) condTimedWait;
153 	extern(C) void function(GCond* cond) condFree;
154 	extern(C) GPrivate* function(GDestroyNotify destructor) privateNew;
155 	extern(C) void* function(GPrivate* privateKey) privateGet;
156 	extern(C) void function(GPrivate* privateKey, void* data) privateSet;
157 	extern(C) void function(GThreadFunc func, void* data, gulong stackSize, int joinable, int bound, GThreadPriority priority, void* thread, GError** error) threadCreate;
158 	extern(C) void function() threadYield;
159 	extern(C) void function(void* thread) threadJoin;
160 	extern(C) void function() threadExit;
161 	extern(C) void function(void* thread, GThreadPriority priority) threadSetPriority;
162 	extern(C) void function(void* thread) threadSelf;
163 	extern(C) int function(void* thread1, void* thread2) threadEqual;
164 }
165 
166 
167 /**
168  * Main Gtk struct.
169  * The GThread struct represents a running thread. It has three public
170  * read-only members, but the underlying struct is bigger, so you must
171  * not copy this struct.
172  * Note
173  * Resources for a joinable thread are not fully released
174  * until g_thread_join() is called for that thread.
175  */
176 public struct GThread{}
177 
178 
179 /**
180  * The GMutex struct is an opaque data structure to represent a mutex
181  * (mutual exclusion). It can be used to protect data against shared
182  * access. Take for example the following function:
183  * $(DDOC_COMMENT example)
184  * It is easy to see that this won't work in a multi-threaded
185  * application. There current_number must be protected against shared
186  * access. A first naive implementation would be:
187  * $(DDOC_COMMENT example)
188  * This looks like it would work, but there is a race condition while
189  * constructing the mutex and this code cannot work reliable. Please do
190  * not use such constructs in your own programs! One working solution
191  * is:
192  * $(DDOC_COMMENT example)
193  * GStaticMutex provides a simpler and safer way of doing this.
194  * If you want to use a mutex, and your code should also work without
195  * calling g_thread_init() first, then you can not use a GMutex, as
196  * g_mutex_new() requires that the thread system be initialized. Use a
197  * GStaticMutex instead.
198  * A GMutex should only be accessed via the following functions.
199  * Note
200  * All of the g_mutex_* functions are
201  * actually macros. Apart from taking their addresses, you can however
202  * use them as if they were functions.
203  */
204 public struct GMutex{}
205 
206 
207 /**
208  * A GStaticMutex works like a GMutex, but it has one significant
209  * advantage. It doesn't need to be created at run-time like a GMutex,
210  * but can be defined at compile-time. Here is a shorter, easier and
211  * safer version of our give_me_next_number()
212  * example:
213  * $(DDOC_COMMENT example)
214  * Sometimes you would like to dynamically create a mutex. If you don't
215  * want to require prior calling to g_thread_init(), because your code
216  * should also be usable in non-threaded programs, you are not able to
217  * use g_mutex_new() and thus GMutex, as that requires a prior call to
218  * g_thread_init(). In theses cases you can also use a GStaticMutex.
219  * It must be initialized with g_static_mutex_init() before using it
220  * and freed with with g_static_mutex_free() when not needed anymore to
221  * free up any allocated resources.
222  * Even though GStaticMutex is not opaque, it should only be used with
223  * the following functions, as it is defined differently on different
224  * platforms.
225  * All of the g_static_mutex_* functions apart
226  * from g_static_mutex_get_mutex can also be used
227  * even if g_thread_init() has not yet been called. Then they do
228  * nothing, apart from g_static_mutex_trylock,
229  * which does nothing but returning TRUE.
230  * Note
231  * All of the g_static_mutex_*
232  * functions are actually macros. Apart from taking their addresses, you
233  * can however use them as if they were functions.
234  */
235 public struct GStaticMutex{}
236 
237 
238 /**
239  * A GStaticRecMutex works like a GStaticMutex, but it can be locked
240  * multiple times by one thread. If you enter it n times, you have to
241  * unlock it n times again to let other threads lock it. An exception
242  * is the function g_static_rec_mutex_unlock_full(): that allows you to
243  * unlock a GStaticRecMutex completely returning the depth, (i.e. the
244  * number of times this mutex was locked). The depth can later be used
245  * to restore the state of the GStaticRecMutex by calling
246  * g_static_rec_mutex_lock_full().
247  * Even though GStaticRecMutex is not opaque, it should only be used
248  * with the following functions.
249  * All of the g_static_rec_mutex_* functions can
250  * be used even if g_thread_init() has not been called. Then they do
251  * nothing, apart from g_static_rec_mutex_trylock,
252  * which does nothing but returning TRUE.
253  */
254 public struct GStaticRecMutex{}
255 
256 
257 /**
258  * The GStaticRWLock struct represents a read-write lock. A read-write
259  * lock can be used for protecting data that some portions of code only
260  * read from, while others also write. In such situations it is
261  * desirable that several readers can read at once, whereas of course
262  * only one writer may write at a time. Take a look at the following
263  * example:
264  * $(DDOC_COMMENT example)
265  * This example shows an array which can be accessed by many readers
266  * (the my_array_get() function) simultaneously,
267  * whereas the writers (the my_array_set()
268  * function) will only be allowed once at a time and only if no readers
269  * currently access the array. This is because of the potentially
270  * dangerous resizing of the array. Using these functions is fully
271  * multi-thread safe now.
272  * Most of the time, writers should have precedence over readers. That
273  * means, for this implementation, that as soon as a writer wants to
274  * lock the data, no other reader is allowed to lock the data, whereas,
275  * of course, the readers that already have locked the data are allowed
276  * to finish their operation. As soon as the last reader unlocks the
277  * data, the writer will lock it.
278  * Even though GStaticRWLock is not opaque, it should only be used
279  * with the following functions.
280  * All of the g_static_rw_lock_* functions can be
281  * used even if g_thread_init() has not been called. Then they do
282  * nothing, apart from g_static_rw_lock_*_trylock,
283  * which does nothing but returning TRUE.
284  * Note
285  * A read-write lock has a higher overhead than a mutex. For
286  * example, both g_static_rw_lock_reader_lock() and
287  * g_static_rw_lock_reader_unlock() have to lock and unlock a
288  * GStaticMutex, so it takes at least twice the time to lock and unlock
289  * a GStaticRWLock that it does to lock and unlock a GStaticMutex. So
290  * only data structures that are accessed by multiple readers, and which
291  * keep the lock for a considerable time justify a GStaticRWLock. The
292  * above example most probably would fare better with a
293  * GStaticMutex.
294  */
295 public struct GStaticRWLock{}
296 
297 
298 /**
299  * The GCond struct is an opaque data structure that represents a
300  * condition. Threads can block on a GCond if they find a certain
301  * condition to be false. If other threads change the state of this
302  * condition they signal the GCond, and that causes the waiting
303  * threads to be woken up.
304  * $(DDOC_COMMENT example)
305  * Whenever a thread calls pop_data() now, it will
306  * wait until current_data is non-NULL, i.e. until some other thread
307  * has called push_data().
308  * Note
309  * It is important to use the g_cond_wait() and
310  * g_cond_timed_wait() functions only inside a loop which checks for the
311  * condition to be true. It is not guaranteed that the waiting thread
312  * will find the condition fulfilled after it wakes up, even if the
313  * signaling thread left the condition in that state: another thread may
314  * have altered the condition before the waiting thread got the chance
315  * to be woken up, even if the condition itself is protected by a
316  * GMutex, like above.
317  * A GCond should only be accessed via the following functions.
318  * Note
319  * All of the g_cond_* functions are
320  * actually macros. Apart from taking their addresses, you can however
321  * use them as if they were functions.
322  */
323 public struct GCond{}
324 
325 
326 /**
327  * The GPrivate struct is an opaque data structure to represent a
328  * thread private data key. Threads can thereby obtain and set a
329  * pointer which is private to the current thread. Take our
330  * give_me_next_number() example from
331  * above. Suppose we don't want current_number to be
332  * shared between the threads, but instead to be private to each thread.
333  * This can be done as follows:
334  * $(DDOC_COMMENT example)
335  * Here the pointer belonging to the key
336  * current_number_key is read. If it is NULL, it has
337  * not been set yet. Then get memory for an integer value, assign this
338  * memory to the pointer and write the pointer back. Now we have an
339  * integer value that is private to the current thread.
340  * The GPrivate struct should only be accessed via the following
341  * functions.
342  * Note
343  * All of the g_private_* functions are
344  * actually macros. Apart from taking their addresses, you can however
345  * use them as if they were functions.
346  */
347 public struct GPrivate{}
348 
349 
350 /**
351  * A GStaticPrivate works almost like a GPrivate, but it has one
352  * significant advantage. It doesn't need to be created at run-time
353  * like a GPrivate, but can be defined at compile-time. This is
354  * similar to the difference between GMutex and GStaticMutex. Now
355  * look at our give_me_next_number() example with
356  * GStaticPrivate:
357  * $(DDOC_COMMENT example)
358  */
359 public struct GStaticPrivate{}
360 
361 
362 /**
363  * A GOnce struct controls a one-time initialization function. Any
364  * one-time initialization function must have its own unique GOnce
365  * struct.
366  * volatile GOnceStatus status;
367  * the status of the GOnce
368  * volatile gpointer retval;
369  * the value returned by the call to the function, if status
370  * is G_ONCE_STATUS_READY
371  * Since 2.4
372  */
373 public struct GOnce
374 {
375 	GOnceStatus status;
376 	void* retval;
377 }
378 
379 
380 /*
381  * The G_LOCK_* macros provide a convenient interface to GStaticMutex
382  * with the advantage that they will expand to nothing in programs
383  * compiled against a thread-disabled GLib, saving code and memory
384  * there. G_LOCK_DEFINE defines a lock. It can appear anywhere
385  * variable definitions may appear in programs, i.e. in the first block
386  * of a function or outside of functions. The name parameter will be
387  * mangled to get the name of the GStaticMutex. This means that you
388  * can use names of existing variables as the parameter - e.g. the name
389  * of the variable you intent to protect with the lock. Look at our
390  * give_me_next_number() example using the
391  * G_LOCK_* macros:
392  * $(DDOC_COMMENT example)
393  * name :
394  * the name of the lock.
395  */
396 // TODO
397 // #define G_LOCK_DEFINE(name)
398 
399 /*
400  * This works like G_LOCK_DEFINE, but it creates a static object.
401  * name :
402  * the name of the lock.
403  */
404 // TODO
405 // #define G_LOCK_DEFINE_STATIC(name)
406 
407 /*
408  * This declares a lock, that is defined with G_LOCK_DEFINE in another
409  * module.
410  * name :
411  * the name of the lock.
412  */
413 // TODO
414 // #define G_LOCK_EXTERN(name)
415 
416 /*
417  * Works like g_mutex_lock(), but for a lock defined with
418  * G_LOCK_DEFINE.
419  * name :
420  * the name of the lock.
421  */
422 // TODO
423 // #define G_LOCK(name)
424 
425 /*
426  * Works like g_mutex_trylock(), but for a lock defined with
427  * G_LOCK_DEFINE.
428  * name :
429  * the name of the lock.
430  * Returns :
431  * TRUE, if the lock could be locked.
432  */
433 // TODO
434 // #define G_TRYLOCK(name)
435 
436 /*
437  * Works like g_mutex_unlock(), but for a lock defined with
438  * G_LOCK_DEFINE.
439  * name :
440  * the name of the lock.
441  */
442 // TODO
443 // #define G_UNLOCK(name)
444 
445 /*
446  * The first call to this routine by a process with a given GOnce
447  * struct calls func with the given argument. Thereafter, subsequent
448  * calls to g_once() with the same GOnce struct do not call func
449  * again, but return the stored result of the first call. On return
450  * from g_once(), the status of once will be G_ONCE_STATUS_READY.
451  * For example, a mutex or a thread-specific data key must be created
452  * exactly once. In a threaded environment, calling g_once() ensures
453  * that the initialization is serialized across multiple threads.
454  * Note
455  * Calling g_once() recursively on the same GOnce struct in
456  * func will lead to a deadlock.
457  * $(DDOC_COMMENT example)
458  * once :
459  * a GOnce structure
460  * func :
461  * the GThreadFunc function associated to once. This function
462  * is called only once, regardless of the number of times it and
463  * its associated GOnce struct are passed to g_once().
464  * arg :
465  * data to be passed to func
466  * Since 2.4
467  */
468 // TODO
469 // #define g_once(once, func, arg)
470 
471 /*
472  * Specifies the type of the func functions passed to
473  * g_thread_create() or g_thread_create_full().
474  * data :
475  * data passed to the thread.
476  * Returns :
477  * the return value of the thread, which will be returned by
478  * g_thread_join().
479  */
480 // gpointer (*GThreadFunc) (gpointer data);
481 public alias extern(C) void* function(void* data) GThreadFunc;