comparison dwt/internal/gtk/c/gthreadtypes.d @ 11:5f725d09c076

Added dynamic loader from gtkd with cleanup and modifications. Tango only support. No OS.d tie-in yet.
author John Reimer<terminal.node@gmail.com>
date Sat, 05 Jan 2008 15:13:44 -0800
parents
children
comparison
equal deleted inserted replaced
10:63c023465156 11:5f725d09c076
1 /******************************************************************************
2
3 This file is part of gtkD.
4
5 gtkD is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 ******************************************************************************/
20
21 module dwt.internal.gtk.c.gthreadtypes;
22
23 public import dwt.internal.gtk.c.glibtypes;
24
25 /******************************************************************************
26
27 Possible errors of thread related functions.
28 G_THREAD_ERROR_AGAIN
29 a thread couldn't be created due to resource
30 shortage. Try again later.
31
32 ******************************************************************************/
33
34 public enum GThreadError
35 {
36 AGAIN /+* Resource temporarily unavailable +/
37 }
38 alias GThreadError ThreadError;
39
40 /**
41 * Specifies the priority of a thread.
42 * Note
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
56 */
57 public enum GThreadPriority
58 {
59 LOW,
60 NORMAL,
61 HIGH,
62 URGENT
63 }
64 alias GThreadPriority ThreadPriority;
65
66 /**
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.
72 * G_ONCE_STATUS_READY
73 * the function has been called.
74 * Since 2.4
75 */
76 public enum GOnceStatus
77 {
78 NOTCALLED,
79 PROGRESS,
80 READY
81 }
82 alias GOnceStatus OnceStatus;
83
84
85 /**
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.
91 * Note
92 * Do not use this struct unless you know what you are doing.
93 */
94 public struct GThreadFunctions{}
95 // GMutex* (*mutexNew) (void);
96 //
97 // void (*mutexLock) (GMutex *mutex);
98 //
99 // int (*mutexTrylock) (GMutex *mutex);
100 //
101 // void (*mutexUnlock) (GMutex *mutex);
102 //
103 // void (*mutexFree) (GMutex *mutex);
104 //
105 // GCond* (*condNew) (void);
106 //
107 // void (*condSignal) (GCond *cond);
108 //
109 // void (*condBroadcast) (GCond *cond);
110 //
111 // void (*condWait) (GCond *cond,
112 //
113 // GMutex *mutex);
114 //
115 // int (*condTimedWait) (GCond *cond,
116 //
117 // GMutex *mutex,
118 //
119 // GTimeVal *endTime);
120 //
121 // void (*condFree) (GCond *cond);
122 //
123 // GPrivate* (*privateNew) (GDestroyNotify destructor);
124 //
125 // void* (*privateGet) (GPrivate *privateKey);
126 //
127 // void (*privateSet) (GPrivate *privateKey,
128 //
129 // void* data);
130 //
131 // void (*threadCreate) (GThreadFunc func,
132 //
133 // void* data,
134 //
135 // uint stackSize,
136 //
137 // int joinable,
138 //
139 // int bound,
140 //
141 // GThreadPriority priority,
142 //
143 // void* thread,
144 //
145 // GError **error);
146 //
147 // void (*threadYield) (void);
148 //
149 // void (*threadJoin) (void* thread);
150 //
151 // void (*threadExit) (void);
152 //
153 // void (*threadSetPriority)(void* thread,
154 //
155 // GThreadPriority priority);
156 //
157 // void (*threadSelf) (void* thread);
158 //
159 // int (*threadEqual) (void* thread1,
160 //
161 // void* thread2);
162 //
163
164
165 /**
166 * Main Gtk struct.
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.
170 * Note
171 * Resources for a joinable thread are not fully released until
172 * g_thread_join() is called for that thread.
173 */
174 public struct GThread{}
175
176
177 /**
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 * Example2.A function which will not work in a threaded environment
182 */
183 public struct GMutex{}
184
185
186 /**
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 * Example5.Using GStaticMutex to simplify thread-safe programming
192 */
193 public struct GStaticMutex{}
194
195
196 /**
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 be
208 * used even if g_thread_init() has not been called. Then they do
209 * nothing, apart from g_static_rec_mutex_trylock,
210 * which does nothing but returning TRUE.
211 */
212 public struct GStaticRecMutex{}
213
214
215 /**
216 * The GStaticRWLock struct represents a read-write lock. A read-write
217 * lock can be used for protecting data that some portions of code only
218 * read from, while others also write. In such situations it is
219 * desirable that several readers can read at once, whereas of course
220 * only one writer may write at a time. Take a look at the following
221 * example:
222 * Example7.An array with access functions
223 */
224 public struct GStaticRWLock{}
225
226
227 /**
228 * The GCond struct is an opaque data structure that represents a
229 * condition. Threads can block on a GCond if they find a certain
230 * condition to be false. If other threads change the state of this
231 * condition they signal the GCond, and that causes the waiting threads
232 * to be woken up.
233 * Example8.Using GCond to block a thread until a condition is satisfied
234 * GCond* data_cond = NULL; /+* Must be initialized somewhere +/
235 * GMutex* data_mutex = NULL; /+* Must be initialized somewhere +/
236 * gpointer current_data = NULL;
237 * void push_data (gpointer data)
238 * {
239 */
240 public struct GCond{}
241
242
243 /**
244 * The GPrivate struct is an opaque data structure to represent a thread
245 * private data key. Threads can thereby obtain and set a pointer which
246 * is private to the current thread.
247 * Take our give_me_next_number() example from above.
248 * Suppose we don't want current_number to be shared
249 * between the threads, but instead to be private to each thread. This can be
250 * done as follows:
251 * Example9.Using GPrivate for per-thread data
252 */
253 public struct GPrivate{}
254
255
256 /**
257 * A GStaticPrivate works almost like a GPrivate, but it has one
258 * significant advantage. It doesn't need to be created at run-time like
259 * a GPrivate, but can be defined at compile-time. This is similar to
260 * the difference between GMutex and GStaticMutex. Now look at our
261 * give_me_next_number() example with ""
262 * Example10.Using GStaticPrivate for per-thread data
263 */
264 public struct GStaticPrivate{}
265
266
267 /**
268 * A GOnce struct controls a one-time initialization
269 * function. Any one-time initialization function must have its own unique
270 * GOnce struct.
271 * volatileGOnceStatusstatus;
272 * the status of the GOnce
273 * volatilegpointerretval;
274 * the value returned by the call to the function, if status
275 */
276 public struct GOnce
277 {
278 GOnceStatus status;
279 void* retval;
280 }
281
282
283 /*
284 * The G_LOCK_* macros provide a convenient interface to GStaticMutex
285 * with the advantage that they will expand to nothing in programs
286 * compiled against a thread-disabled GLib, saving code and memory
287 * there. G_LOCK_DEFINE defines a lock. It can appear anywhere variable
288 * definitions may appear in programs, i.e. in the first block of a
289 * function or outside of functions. The name parameter will be mangled
290 * to get the name of the GStaticMutex. This means that you can use
291 * names of existing variables as the parameter - e.g. the name of the
292 * variable you intent to protect with the lock. Look at our
293 * give_me_next_number() example using the G_LOCK_* macros:
294 * Example6.Using the G_LOCK_* convenience macros
295 * G_LOCK_DEFINE (current_number);
296 * int give_me_next_number ()
297 * {
298 * static int current_number = 0;
299 * int ret_val;
300 * G_LOCK (current_number);
301 * ret_val = current_number = calc_next_number (current_number);
302 * G_UNLOCK (current_number);
303 * return ret_val;
304 * }
305 * name:
306 * the name of the lock.
307 */
308 // TODO
309 // #define G_LOCK_DEFINE(name)
310
311 /*
312 * This works like G_LOCK_DEFINE, but it creates a static object.
313 * name:
314 * the name of the lock.
315 */
316 // TODO
317 // #define G_LOCK_DEFINE_STATIC(name)
318
319 /*
320 * This declares a lock, that is defined with G_LOCK_DEFINE in another module.
321 * name:
322 * the name of the lock.
323 */
324 // TODO
325 // #define G_LOCK_EXTERN(name)
326
327 /*
328 * Works like g_mutex_lock(), but for a lock defined with G_LOCK_DEFINE.
329 * name:
330 * the name of the lock.
331 */
332 // TODO
333 // #define G_LOCK(name)
334
335 /*
336 * Works like g_mutex_trylock(), but for a lock defined with G_LOCK_DEFINE.
337 * name:
338 * the name of the lock.
339 * Returns:
340 * TRUE, if the lock could be locked.
341 */
342 // TODO
343 // #define G_TRYLOCK(name)
344
345 /*
346 * Works like g_mutex_unlock(), but for a lock defined with G_LOCK_DEFINE.
347 * name:
348 * the name of the lock.
349 */
350 // TODO
351 // #define G_UNLOCK(name)
352
353 /*
354 * The first call to this routine by a process with a given GOnce struct calls
355 * func with the given argument. Thereafter, subsequent calls to g_once() with
356 * the same GOnce struct do not call func again, but return the stored result
357 * of the first call. On return from g_once(), the status of once will be
358 * G_ONCE_STATUS_READY.
359 * For example, a mutex or a thread-specific data key must be created exactly
360 * once. In a threaded environment, calling g_once() ensures that the
361 * initialization is serialized across multiple threads.
362 * Note
363 * Calling g_once() recursively on the same GOnce struct in func will lead
364 * to a deadlock.
365 * gpointer
366 * get_debug_flags ()
367 * {
368 * static GOnce my_once = G_ONCE_INIT;
369 * g_once (my_once, parse_debug_flags, NULL);
370 * return my_once.retval;
371 * }
372 * once:
373 * a GOnce structure
374 * func:
375 * the GThreadFunc function associated to once. This function is
376 * called only once, regardless of the number of times it and its
377 * associated GOnce struct are passed to g_once() .
378 * arg:
379 * data to be passed to func
380 * Since 2.4
381 */
382 // TODO
383 // #define g_once(once, func, arg)
384
385 /*
386 * Specifies the type of the func functions passed to
387 * g_thread_create() or g_thread_create_full().
388 * data:
389 * data passed to the thread.
390 * Returns:
391 * the return value of the thread, which will be returned by
392 * g_thread_join().
393 */
394 // gpointer (*GThreadFunc) (gpointer data);
395 public typedef extern(C) void* function (void*) GThreadFunc;