]> git.llucax.com Git - software/druntime.git/blob - import/stdc/posix/pthread.d
Applied all D2 changes to trunk. It should now be a fully functional D2 runtime.
[software/druntime.git] / import / stdc / posix / pthread.d
1 /**
2  * D header file for POSIX.
3  *
4  * Copyright: Public Domain
5  * License:   Public Domain
6  * Authors:   Sean Kelly
7  * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
8  */
9 module stdc.posix.pthread;
10
11 private import stdc.posix.config;
12 public import stdc.posix.sys.types;
13 public import stdc.posix.sched;
14 public import stdc.posix.time;
15
16 extern (C):
17
18 //
19 // Required
20 //
21 /*
22 PTHREAD_CANCEL_ASYNCHRONOUS
23 PTHREAD_CANCEL_ENABLE
24 PTHREAD_CANCEL_DEFERRED
25 PTHREAD_CANCEL_DISABLE
26 PTHREAD_CANCELED
27 PTHREAD_COND_INITIALIZER
28 PTHREAD_CREATE_DETACHED
29 PTHREAD_CREATE_JOINABLE
30 PTHREAD_EXPLICIT_SCHED
31 PTHREAD_INHERIT_SCHED
32 PTHREAD_MUTEX_INITIALIZER
33 PTHREAD_ONCE_INIT
34 PTHREAD_PROCESS_SHARED
35 PTHREAD_PROCESS_PRIVATE
36
37 int pthread_atfork(void function(), void function(), void function());
38 int pthread_attr_destroy(pthread_attr_t*);
39 int pthread_attr_getdetachstate(in pthread_attr_t*, int*);
40 int pthread_attr_getschedparam(in pthread_attr_t*, sched_param*);
41 int pthread_attr_init(pthread_attr_t*);
42 int pthread_attr_setdetachstate(pthread_attr_t*, int);
43 int pthread_attr_setschedparam(in pthread_attr_t*, sched_param*);
44 int pthread_cancel(pthread_t);
45 void pthread_cleanup_push(void function(void*), void*);
46 void pthread_cleanup_pop(int);
47 int pthread_cond_broadcast(pthread_cond_t*);
48 int pthread_cond_destroy(pthread_cond_t*);
49 int pthread_cond_init(in pthread_cond_t*, pthread_condattr_t*);
50 int pthread_cond_signal(pthread_cond_t*);
51 int pthread_cond_timedwait(pthread_cond_t*, pthread_mutex_t*, in timespec*);
52 int pthread_cond_wait(pthread_cond_t*, pthread_mutex_t*);
53 int pthread_condattr_destroy(pthread_condattr_t*);
54 int pthread_condattr_init(pthread_condattr_t*);
55 int pthread_create(pthread_t*, in pthread_attr_t*, void* function(void*), void*);
56 int pthread_detach(pthread_t);
57 int pthread_equal(pthread_t, pthread_t);
58 void pthread_exit(void*);
59 void* pthread_getspecific(pthread_key_t);
60 int pthread_join(pthread_t, void**);
61 int pthread_key_create(pthread_key_t*, void function(void*));
62 int pthread_key_delete(pthread_key_t);
63 int pthread_mutex_destroy(pthread_mutex_t*);
64 int pthread_mutex_init(pthread_mutex_t*, pthread_mutexattr_t*);
65 int pthread_mutex_lock(pthread_mutex_t*);
66 int pthread_mutex_trylock(pthread_mutex_t*);
67 int pthread_mutex_unlock(pthread_mutex_t*);
68 int pthread_mutexattr_destroy(pthread_mutexattr_t*);
69 int pthread_mutexattr_init(pthread_mutexattr_t*);
70 int pthread_once(pthread_once_t*, void function());
71 int pthread_rwlock_destroy(pthread_rwlock_t*);
72 int pthread_rwlock_init(in pthread_rwlock_t*, pthread_rwlockattr_t*);
73 int pthread_rwlock_rdlock(pthread_rwlock_t*);
74 int pthread_rwlock_tryrdlock(pthread_rwlock_t*);
75 int pthread_rwlock_trywrlock(pthread_rwlock_t*);
76 int pthread_rwlock_unlock(pthread_rwlock_t*);
77 int pthread_rwlock_wrlock(pthread_rwlock_t*);
78 int pthread_rwlockattr_destroy(pthread_rwlockattr_t*);
79 int pthread_rwlockattr_init(pthread_rwlockattr_t*);
80 pthread_t pthread_self();
81 int pthread_setcancelstate(int, int*);
82 int pthread_setcanceltype(int, int*);
83 int pthread_setspecific(pthread_key_t, in void*);
84 void pthread_testcancel();
85 */
86 version( linux )
87 {
88     enum
89     {
90         PTHREAD_CANCEL_ENABLE,
91         PTHREAD_CANCEL_DISABLE
92     }
93
94     enum
95     {
96         PTHREAD_CANCEL_DEFERRED,
97         PTHREAD_CANCEL_ASYNCHRONOUS
98     }
99
100     const PTHREAD_CANCELED = cast(void*) -1;
101
102     //const pthread_mutex_t PTHREAD_COND_INITIALIZER = { __LOCK_ALT_INITIALIZER, 0, "", 0 };
103
104     enum
105     {
106         PTHREAD_CREATE_JOINABLE,
107         PTHREAD_CREATE_DETACHED
108     }
109
110     enum
111     {
112         PTHREAD_INHERIT_SCHED,
113         PTHREAD_EXPLICIT_SCHED
114     }
115
116     //const pthread_mutex_t PTHREAD_MUTEX_INITIALIZER = { 0, 0, null, PTHREAD_MUTEX_NORMAL, { 0, 0 } };
117
118     const PTHREAD_ONCE_INIT = 0;
119
120     enum
121     {
122         PTHREAD_PROCESS_PRIVATE,
123         PTHREAD_PROCESS_SHARED
124     }
125 }
126 else version( darwin )
127 {
128     enum
129     {
130         PTHREAD_CANCEL_ENABLE   = 1,
131         PTHREAD_CANCEL_DISABLE  = 0
132     }
133
134     enum
135     {
136         PTHREAD_CANCEL_DEFERRED     = 2,
137         PTHREAD_CANCEL_ASYNCHRONOUS = 0
138     }
139
140     const PTHREAD_CANCELED = cast(void*) -1;
141
142     //const pthread_mutex_t PTHREAD_COND_INITIALIZER = { __LOCK_ALT_INITIALIZER, 0, "", 0 };
143
144     enum
145     {
146         PTHREAD_CREATE_JOINABLE = 1,
147         PTHREAD_CREATE_DETACHED = 2
148     }
149
150     enum
151     {
152         PTHREAD_INHERIT_SCHED   = 1,
153         PTHREAD_EXPLICIT_SCHED  = 2
154     }
155
156     //const pthread_mutex_t PTHREAD_MUTEX_INITIALIZER = { 0, 0, null, PTHREAD_MUTEX_NORMAL, { 0, 0 } };
157
158     const PTHREAD_ONCE_INIT = 0;
159
160     enum
161     {
162         PTHREAD_PROCESS_PRIVATE = 2,
163         PTHREAD_PROCESS_SHARED  = 1
164     }
165 }
166
167 int pthread_atfork(void function(), void function(), void function());
168 int pthread_attr_destroy(pthread_attr_t*);
169 int pthread_attr_getdetachstate(in pthread_attr_t*, int*);
170 int pthread_attr_getschedparam(in pthread_attr_t*, sched_param*);
171 int pthread_attr_init(pthread_attr_t*);
172 int pthread_attr_setdetachstate(pthread_attr_t*, int);
173 int pthread_attr_setschedparam(in pthread_attr_t*, sched_param*);
174 int pthread_cancel(pthread_t);
175
176 version( linux )
177 {
178     alias void function(void*) _pthread_cleanup_routine;
179
180     struct _pthread_cleanup_buffer
181     {
182         _pthread_cleanup_routine    __routine;
183         void*                       __arg;
184         int                         __canceltype;
185         _pthread_cleanup_buffer*    __prev;
186     }
187
188     void _pthread_cleanup_push(_pthread_cleanup_buffer*, _pthread_cleanup_routine, void*);
189     void _pthread_cleanup_pop(_pthread_cleanup_buffer*, int);
190
191     struct pthread_cleanup
192     {
193         _pthread_cleanup_buffer buffer = void;
194
195         void push()( _pthread_cleanup_routine routine, void* arg )
196         {
197             _pthread_cleanup_push( &buffer, routine, arg );
198         }
199
200         void pop()( int execute )
201         {
202             _pthread_cleanup_pop( &buffer, execute );
203         }
204     }
205 }
206 else version( darwin )
207 {
208     alias void function(void*) _pthread_cleanup_routine;
209
210     struct _pthread_cleanup_buffer
211     {
212         _pthread_cleanup_routine    __routine;
213         void*                       __arg;
214         _pthread_cleanup_buffer*    __next;
215     }
216
217     struct pthread_cleanup
218     {
219         _pthread_cleanup_buffer buffer = void;
220
221         void push()( _pthread_cleanup_routine routine, void* arg )
222         {
223             pthread_t self       = pthread_self();
224             buffer.__routine     = routine;
225             buffer.__arg         = arg;
226             buffer.__next        = cast(_pthread_cleanup_buffer*) self.__cleanup_stack;
227             self.__cleanup_stack = cast(pthread_handler_rec*) &buffer;
228         }
229
230         void pop()( int execute )
231         {
232             pthread_t self       = pthread_self();
233             self.__cleanup_stack = cast(pthread_handler_rec*) buffer.__next;
234             if( execute )
235             {
236                 buffer.__routine( buffer.__arg );
237             }
238         }
239     }
240 }
241 else
242 {
243     void pthread_cleanup_push(void function(void*), void*);
244     void pthread_cleanup_pop(int);
245 }
246
247 int pthread_cond_broadcast(pthread_cond_t*);
248 int pthread_cond_destroy(pthread_cond_t*);
249 int pthread_cond_init(in pthread_cond_t*, pthread_condattr_t*);
250 int pthread_cond_signal(pthread_cond_t*);
251 int pthread_cond_timedwait(pthread_cond_t*, pthread_mutex_t*, in timespec*);
252 int pthread_cond_wait(pthread_cond_t*, pthread_mutex_t*);
253 int pthread_condattr_destroy(pthread_condattr_t*);
254 int pthread_condattr_init(pthread_condattr_t*);
255 int pthread_create(pthread_t*, in pthread_attr_t*, void* function(void*), void*);
256 int pthread_detach(pthread_t);
257 int pthread_equal(pthread_t, pthread_t);
258 void pthread_exit(void*);
259 void* pthread_getspecific(pthread_key_t);
260 int pthread_join(pthread_t, void**);
261 int pthread_key_create(pthread_key_t*, void function(void*));
262 int pthread_key_delete(pthread_key_t);
263 int pthread_mutex_destroy(pthread_mutex_t*);
264 int pthread_mutex_init(pthread_mutex_t*, pthread_mutexattr_t*);
265 int pthread_mutex_lock(pthread_mutex_t*);
266 int pthread_mutex_trylock(pthread_mutex_t*);
267 int pthread_mutex_unlock(pthread_mutex_t*);
268 int pthread_mutexattr_destroy(pthread_mutexattr_t*);
269 int pthread_mutexattr_init(pthread_mutexattr_t*);
270 int pthread_once(pthread_once_t*, void function());
271 int pthread_rwlock_destroy(pthread_rwlock_t*);
272 int pthread_rwlock_init(in pthread_rwlock_t*, pthread_rwlockattr_t*);
273 int pthread_rwlock_rdlock(pthread_rwlock_t*);
274 int pthread_rwlock_tryrdlock(pthread_rwlock_t*);
275 int pthread_rwlock_trywrlock(pthread_rwlock_t*);
276 int pthread_rwlock_unlock(pthread_rwlock_t*);
277 int pthread_rwlock_wrlock(pthread_rwlock_t*);
278 int pthread_rwlockattr_destroy(pthread_rwlockattr_t*);
279 int pthread_rwlockattr_init(pthread_rwlockattr_t*);
280 pthread_t pthread_self();
281 int pthread_setcancelstate(int, int*);
282 int pthread_setcanceltype(int, int*);
283 int pthread_setspecific(pthread_key_t, in void*);
284 void pthread_testcancel();
285
286 //
287 // Barrier (BAR)
288 //
289 /*
290 PTHREAD_BARRIER_SERIAL_THREAD
291
292 int pthread_barrier_destroy(pthread_barrier_t*);
293 int pthread_barrier_init(pthread_barrier_t*, in pthread_barrierattr_t*, uint);
294 int pthread_barrier_wait(pthread_barrier_t*);
295 int pthread_barrierattr_destroy(pthread_barrierattr_t*);
296 int pthread_barrierattr_getpshared(in pthread_barrierattr_t*, int*); (BAR|TSH)
297 int pthread_barrierattr_init(pthread_barrierattr_t*);
298 int pthread_barrierattr_setpshared(pthread_barrierattr_t*, int); (BAR|TSH)
299 */
300
301 version( linux )
302 {
303     const PTHREAD_BARRIER_SERIAL_THREAD = -1;
304
305     int pthread_barrier_destroy(pthread_barrier_t*);
306     int pthread_barrier_init(pthread_barrier_t*, in pthread_barrierattr_t*, uint);
307     int pthread_barrier_wait(pthread_barrier_t*);
308     int pthread_barrierattr_destroy(pthread_barrierattr_t*);
309     int pthread_barrierattr_getpshared(in pthread_barrierattr_t*, int*);
310     int pthread_barrierattr_init(pthread_barrierattr_t*);
311     int pthread_barrierattr_setpshared(pthread_barrierattr_t*, int);
312 }
313
314 //
315 // Clock (CS)
316 //
317 /*
318 int pthread_condattr_getclock(in pthread_condattr_t*, clockid_t*);
319 int pthread_condattr_setclock(pthread_condattr_t*, clockid_t);
320 */
321
322 //
323 // Spinlock (SPI)
324 //
325 /*
326 int pthread_spin_destroy(pthread_spinlock_t*);
327 int pthread_spin_init(pthread_spinlock_t*, int);
328 int pthread_spin_lock(pthread_spinlock_t*);
329 int pthread_spin_trylock(pthread_spinlock_t*);
330 int pthread_spin_unlock(pthread_spinlock_t*);
331 */
332
333 version( linux )
334 {
335     int pthread_spin_destroy(pthread_spinlock_t*);
336     int pthread_spin_init(pthread_spinlock_t*, int);
337     int pthread_spin_lock(pthread_spinlock_t*);
338     int pthread_spin_trylock(pthread_spinlock_t*);
339     int pthread_spin_unlock(pthread_spinlock_t*);
340 }
341
342 //
343 // XOpen (XSI)
344 //
345 /*
346 PTHREAD_MUTEX_DEFAULT
347 PTHREAD_MUTEX_ERRORCHECK
348 PTHREAD_MUTEX_NORMAL
349 PTHREAD_MUTEX_RECURSIVE
350
351 int pthread_attr_getguardsize(in pthread_attr_t*, size_t*);
352 int pthread_attr_setguardsize(pthread_attr_t*, size_t);
353 int pthread_getconcurrency();
354 int pthread_mutexattr_gettype(in pthread_mutexattr_t*, int*);
355 int pthread_mutexattr_settype(pthread_mutexattr_t*, int);
356 int pthread_setconcurrency(int);
357 */
358
359 version( linux )
360 {
361     const PTHREAD_MUTEX_NORMAL      = 0;
362     const PTHREAD_MUTEX_RECURSIVE   = 1;
363     const PTHREAD_MUTEX_ERRORCHECK  = 2;
364     const PTHREAD_MUTEX_DEFAULT     = PTHREAD_MUTEX_NORMAL;
365
366     int pthread_attr_getguardsize(in pthread_attr_t*, size_t*);
367     int pthread_attr_setguardsize(pthread_attr_t*, size_t);
368     int pthread_getconcurrency();
369     int pthread_mutexattr_gettype(in pthread_mutexattr_t*, int*);
370     int pthread_mutexattr_settype(pthread_mutexattr_t*, int);
371     int pthread_setconcurrency(int);
372 }
373 else version( darwin )
374 {
375     const PTHREAD_MUTEX_NORMAL      = 0;
376     const PTHREAD_MUTEX_ERRORCHECK  = 1;
377     const PTHREAD_MUTEX_RECURSIVE   = 2;
378     const PTHREAD_MUTEX_DEFAULT     = PTHREAD_MUTEX_NORMAL;
379
380     int pthread_attr_getguardsize(in pthread_attr_t*, size_t*);
381     int pthread_attr_setguardsize(pthread_attr_t*, size_t);
382     int pthread_getconcurrency();
383     int pthread_mutexattr_gettype(in pthread_mutexattr_t*, int*);
384     int pthread_mutexattr_settype(pthread_mutexattr_t*, int);
385     int pthread_setconcurrency(int);
386 }
387
388 //
389 // CPU Time (TCT)
390 //
391 /*
392 int pthread_getcpuclockid(pthread_t, clockid_t*);
393 */
394
395 version( linux )
396 {
397     int pthread_getcpuclockid(pthread_t, clockid_t*);
398 }
399
400 //
401 // Timeouts (TMO)
402 //
403 /*
404 int pthread_mutex_timedlock(pthread_mutex_t*, timespec*);
405 int pthread_rwlock_timedrdlock(pthread_rwlock_t*, in timespec*);
406 int pthread_rwlock_timedwrlock(pthread_rwlock_t*, in timespec*);
407 */
408
409 version( linux )
410 {
411     int pthread_mutex_timedlock(pthread_mutex_t*, timespec*);
412     int pthread_rwlock_timedrdlock(pthread_rwlock_t*, in timespec*);
413     int pthread_rwlock_timedwrlock(pthread_rwlock_t*, in timespec*);
414 }
415 else version( darwin )
416 {
417     int pthread_mutex_timedlock(pthread_mutex_t*, timespec*);
418     int pthread_rwlock_timedrdlock(pthread_rwlock_t*, in timespec*);
419     int pthread_rwlock_timedwrlock(pthread_rwlock_t*, in timespec*);
420 }
421
422 //
423 // Priority (TPI|TPP)
424 //
425 /*
426 PTHREAD_PRIO_INHERIT (TPI)
427 PTHREAD_PRIO_NONE (TPP|TPI)
428 PTHREAD_PRIO_PROTECT (TPI)
429
430 int pthread_mutex_getprioceiling(in pthread_mutex_t*, int*); (TPP)
431 int pthread_mutex_setprioceiling(pthread_mutex_t*, int, int*); (TPP)
432 int pthread_mutexattr_getprioceiling(pthread_mutexattr_t*, int*); (TPP)
433 int pthread_mutexattr_getprotocol(in pthread_mutexattr_t*, int*); (TPI|TPP)
434 int pthread_mutexattr_setprioceiling(pthread_mutexattr_t*, int); (TPP)
435 int pthread_mutexattr_setprotocol(pthread_mutexattr_t*, int); (TPI|TPP)
436 */
437
438 //
439 // Scheduling (TPS)
440 //
441 /*
442 PTHREAD_SCOPE_PROCESS
443 PTHREAD_SCOPE_SYSTEM
444
445 int pthread_attr_getinheritsched(in pthread_attr_t*, int*);
446 int pthread_attr_getschedpolicy(in pthread_attr_t*, int*);
447 int pthread_attr_getscope(in pthread_attr_t*, int*);
448 int pthread_attr_setinheritsched(pthread_attr_t*, int);
449 int pthread_attr_setschedpolicy(pthread_attr_t*, int);
450 int pthread_attr_setscope(pthread_attr_t*, int);
451 int pthread_getschedparam(pthread_t, int*, sched_param*);
452 int pthread_setschedparam(pthread_t, int, in sched_param*);
453 int pthread_setschedprio(pthread_t, int);
454 */
455
456 version( linux )
457 {
458     enum
459     {
460         PTHREAD_SCOPE_SYSTEM,
461         PTHREAD_SCOPE_PROCESS
462     }
463
464     int pthread_attr_getinheritsched(in pthread_attr_t*, int*);
465     int pthread_attr_getschedpolicy(in pthread_attr_t*, int*);
466     int pthread_attr_getscope(in pthread_attr_t*, int*);
467     int pthread_attr_setinheritsched(pthread_attr_t*, int);
468     int pthread_attr_setschedpolicy(pthread_attr_t*, int);
469     int pthread_attr_setscope(pthread_attr_t*, int);
470     int pthread_getschedparam(pthread_t, int*, sched_param*);
471     int pthread_setschedparam(pthread_t, int, in sched_param*);
472     //int pthread_setschedprio(pthread_t, int);
473 }
474 else version( darwin )
475 {
476     enum
477     {
478         PTHREAD_SCOPE_SYSTEM    = 1,
479         PTHREAD_SCOPE_PROCESS   = 2
480     }
481
482     int pthread_attr_getinheritsched(in pthread_attr_t*, int*);
483     int pthread_attr_getschedpolicy(in pthread_attr_t*, int*);
484     int pthread_attr_getscope(in pthread_attr_t*, int*);
485     int pthread_attr_setinheritsched(pthread_attr_t*, int);
486     int pthread_attr_setschedpolicy(pthread_attr_t*, int);
487     int pthread_attr_setscope(pthread_attr_t*, int);
488     int pthread_getschedparam(pthread_t, int*, sched_param*);
489     int pthread_setschedparam(pthread_t, int, in sched_param*);
490     //int pthread_setschedprio(pthread_t, int);
491 }
492
493 //
494 // Stack (TSA|TSS)
495 //
496 /*
497 int pthread_attr_getstack(in pthread_attr_t*, void**, size_t*); (TSA|TSS)
498 int pthread_attr_getstackaddr(in pthread_attr_t*, void**); (TSA)
499 int pthread_attr_getstacksize(in pthread_attr_t*, size_t*); (TSS)
500 int pthread_attr_setstack(pthread_attr_t*, void*, size_t); (TSA|TSS)
501 int pthread_attr_setstackaddr(pthread_attr_t*, void*); (TSA)
502 int pthread_attr_setstacksize(pthread_attr_t*, size_t); (TSS)
503 */
504
505 version( linux )
506 {
507     int pthread_attr_getstack(in pthread_attr_t*, void**, size_t*);
508     int pthread_attr_getstackaddr(in pthread_attr_t*, void**);
509     int pthread_attr_getstacksize(in pthread_attr_t*, size_t*);
510     int pthread_attr_setstack(pthread_attr_t*, void*, size_t);
511     int pthread_attr_setstackaddr(pthread_attr_t*, void*);
512     int pthread_attr_setstacksize(pthread_attr_t*, size_t);
513 }
514 else version( darwin )
515 {
516     int pthread_attr_getstack(in pthread_attr_t*, void**, size_t*);
517     int pthread_attr_getstackaddr(in pthread_attr_t*, void**);
518     int pthread_attr_getstacksize(in pthread_attr_t*, size_t*);
519     int pthread_attr_setstack(pthread_attr_t*, void*, size_t);
520     int pthread_attr_setstackaddr(pthread_attr_t*, void*);
521     int pthread_attr_setstacksize(pthread_attr_t*, size_t);
522 }
523
524 //
525 // Shared Synchronization (TSH)
526 //
527 /*
528 int pthread_condattr_getpshared(in pthread_condattr_t*, int*);
529 int pthread_condattr_setpshared(pthread_condattr_t*, int);
530 int pthread_mutexattr_getpshared(in pthread_mutexattr_t*, int*);
531 int pthread_mutexattr_setpshared(pthread_mutexattr_t*, int);
532 int pthread_rwlockattr_getpshared(in pthread_rwlockattr_t*, int*);
533 int pthread_rwlockattr_setpshared(pthread_rwlockattr_t*, int);
534 */