2 * D header file for POSIX.
4 * Copyright: Public Domain
5 * License: Public Domain
7 * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
9 module core.sys.posix.pthread;
11 private import core.sys.posix.config;
12 public import core.sys.posix.sys.types;
13 public import core.sys.posix.sched;
14 public import core.sys.posix.time;
22 PTHREAD_CANCEL_ASYNCHRONOUS
24 PTHREAD_CANCEL_DEFERRED
25 PTHREAD_CANCEL_DISABLE
27 PTHREAD_COND_INITIALIZER
28 PTHREAD_CREATE_DETACHED
29 PTHREAD_CREATE_JOINABLE
30 PTHREAD_EXPLICIT_SCHED
32 PTHREAD_MUTEX_INITIALIZER
34 PTHREAD_PROCESS_SHARED
35 PTHREAD_PROCESS_PRIVATE
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();
90 PTHREAD_CANCEL_ENABLE,
91 PTHREAD_CANCEL_DISABLE
96 PTHREAD_CANCEL_DEFERRED,
97 PTHREAD_CANCEL_ASYNCHRONOUS
100 const PTHREAD_CANCELED = cast(void*) -1;
102 //const pthread_mutex_t PTHREAD_COND_INITIALIZER = { __LOCK_ALT_INITIALIZER, 0, "", 0 };
106 PTHREAD_CREATE_JOINABLE,
107 PTHREAD_CREATE_DETACHED
112 PTHREAD_INHERIT_SCHED,
113 PTHREAD_EXPLICIT_SCHED
116 //const pthread_mutex_t PTHREAD_MUTEX_INITIALIZER = { 0, 0, null, PTHREAD_MUTEX_NORMAL, { 0, 0 } };
118 const PTHREAD_ONCE_INIT = 0;
122 PTHREAD_PROCESS_PRIVATE,
123 PTHREAD_PROCESS_SHARED
126 else version( darwin )
130 PTHREAD_CANCEL_ENABLE = 1,
131 PTHREAD_CANCEL_DISABLE = 0
136 PTHREAD_CANCEL_DEFERRED = 2,
137 PTHREAD_CANCEL_ASYNCHRONOUS = 0
140 const PTHREAD_CANCELED = cast(void*) -1;
142 //const pthread_mutex_t PTHREAD_COND_INITIALIZER = { __LOCK_ALT_INITIALIZER, 0, "", 0 };
146 PTHREAD_CREATE_JOINABLE = 1,
147 PTHREAD_CREATE_DETACHED = 2
152 PTHREAD_INHERIT_SCHED = 1,
153 PTHREAD_EXPLICIT_SCHED = 2
156 //const pthread_mutex_t PTHREAD_MUTEX_INITIALIZER = { 0, 0, null, PTHREAD_MUTEX_NORMAL, { 0, 0 } };
158 const PTHREAD_ONCE_INIT = 0;
162 PTHREAD_PROCESS_PRIVATE = 2,
163 PTHREAD_PROCESS_SHARED = 1
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);
178 alias void function(void*) _pthread_cleanup_routine;
180 struct _pthread_cleanup_buffer
182 _pthread_cleanup_routine __routine;
185 _pthread_cleanup_buffer* __prev;
188 void _pthread_cleanup_push(_pthread_cleanup_buffer*, _pthread_cleanup_routine, void*);
189 void _pthread_cleanup_pop(_pthread_cleanup_buffer*, int);
191 struct pthread_cleanup
193 _pthread_cleanup_buffer buffer = void;
195 void push()( _pthread_cleanup_routine routine, void* arg )
197 _pthread_cleanup_push( &buffer, routine, arg );
200 void pop()( int execute )
202 _pthread_cleanup_pop( &buffer, execute );
206 else version( darwin )
208 alias void function(void*) _pthread_cleanup_routine;
210 struct _pthread_cleanup_buffer
212 _pthread_cleanup_routine __routine;
214 _pthread_cleanup_buffer* __next;
217 struct pthread_cleanup
219 _pthread_cleanup_buffer buffer = void;
221 void push()( _pthread_cleanup_routine routine, void* arg )
223 pthread_t self = pthread_self();
224 buffer.__routine = routine;
226 buffer.__next = cast(_pthread_cleanup_buffer*) self.__cleanup_stack;
227 self.__cleanup_stack = cast(pthread_handler_rec*) &buffer;
230 void pop()( int execute )
232 pthread_t self = pthread_self();
233 self.__cleanup_stack = cast(pthread_handler_rec*) buffer.__next;
236 buffer.__routine( buffer.__arg );
243 void pthread_cleanup_push(void function(void*), void*);
244 void pthread_cleanup_pop(int);
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();
290 PTHREAD_BARRIER_SERIAL_THREAD
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)
303 const PTHREAD_BARRIER_SERIAL_THREAD = -1;
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);
318 int pthread_condattr_getclock(in pthread_condattr_t*, clockid_t*);
319 int pthread_condattr_setclock(pthread_condattr_t*, clockid_t);
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*);
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*);
346 PTHREAD_MUTEX_DEFAULT
347 PTHREAD_MUTEX_ERRORCHECK
349 PTHREAD_MUTEX_RECURSIVE
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);
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;
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);
373 else version( darwin )
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;
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);
387 else version( freebsd )
391 PTHREAD_MUTEX_ERRORCHECK = 1,
392 PTHREAD_MUTEX_RECURSIVE = 2,
393 PTHREAD_MUTEX_NORMAL = 3,
394 PTHREAD_MUTEX_ADAPTIVE_NP = 4,
395 PTHREAD_MUTEX_TYPE_MAX
397 const PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_ERRORCHECK;
399 int pthread_attr_getguardsize(in pthread_attr_t*, size_t*);
400 int pthread_attr_setguardsize(pthread_attr_t*, size_t);
401 int pthread_getconcurrency();
402 int pthread_mutexattr_gettype(pthread_mutexattr_t*, int*);
403 int pthread_mutexattr_settype(pthread_mutexattr_t*, int);
404 int pthread_setconcurrency(int);
411 int pthread_getcpuclockid(pthread_t, clockid_t*);
416 int pthread_getcpuclockid(pthread_t, clockid_t*);
423 int pthread_mutex_timedlock(pthread_mutex_t*, timespec*);
424 int pthread_rwlock_timedrdlock(pthread_rwlock_t*, in timespec*);
425 int pthread_rwlock_timedwrlock(pthread_rwlock_t*, in timespec*);
430 int pthread_mutex_timedlock(pthread_mutex_t*, timespec*);
431 int pthread_rwlock_timedrdlock(pthread_rwlock_t*, in timespec*);
432 int pthread_rwlock_timedwrlock(pthread_rwlock_t*, in timespec*);
434 else version( darwin )
436 int pthread_mutex_timedlock(pthread_mutex_t*, timespec*);
437 int pthread_rwlock_timedrdlock(pthread_rwlock_t*, in timespec*);
438 int pthread_rwlock_timedwrlock(pthread_rwlock_t*, in timespec*);
442 // Priority (TPI|TPP)
445 PTHREAD_PRIO_INHERIT (TPI)
446 PTHREAD_PRIO_NONE (TPP|TPI)
447 PTHREAD_PRIO_PROTECT (TPI)
449 int pthread_mutex_getprioceiling(in pthread_mutex_t*, int*); (TPP)
450 int pthread_mutex_setprioceiling(pthread_mutex_t*, int, int*); (TPP)
451 int pthread_mutexattr_getprioceiling(pthread_mutexattr_t*, int*); (TPP)
452 int pthread_mutexattr_getprotocol(in pthread_mutexattr_t*, int*); (TPI|TPP)
453 int pthread_mutexattr_setprioceiling(pthread_mutexattr_t*, int); (TPP)
454 int pthread_mutexattr_setprotocol(pthread_mutexattr_t*, int); (TPI|TPP)
461 PTHREAD_SCOPE_PROCESS
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);
479 PTHREAD_SCOPE_SYSTEM,
480 PTHREAD_SCOPE_PROCESS
483 int pthread_attr_getinheritsched(in pthread_attr_t*, int*);
484 int pthread_attr_getschedpolicy(in pthread_attr_t*, int*);
485 int pthread_attr_getscope(in pthread_attr_t*, int*);
486 int pthread_attr_setinheritsched(pthread_attr_t*, int);
487 int pthread_attr_setschedpolicy(pthread_attr_t*, int);
488 int pthread_attr_setscope(pthread_attr_t*, int);
489 int pthread_getschedparam(pthread_t, int*, sched_param*);
490 int pthread_setschedparam(pthread_t, int, in sched_param*);
491 //int pthread_setschedprio(pthread_t, int);
493 else version( darwin )
497 PTHREAD_SCOPE_SYSTEM = 1,
498 PTHREAD_SCOPE_PROCESS = 2
501 int pthread_attr_getinheritsched(in pthread_attr_t*, int*);
502 int pthread_attr_getschedpolicy(in pthread_attr_t*, int*);
503 int pthread_attr_getscope(in pthread_attr_t*, int*);
504 int pthread_attr_setinheritsched(pthread_attr_t*, int);
505 int pthread_attr_setschedpolicy(pthread_attr_t*, int);
506 int pthread_attr_setscope(pthread_attr_t*, int);
507 int pthread_getschedparam(pthread_t, int*, sched_param*);
508 int pthread_setschedparam(pthread_t, int, in sched_param*);
509 //int pthread_setschedprio(pthread_t, int);
511 else version( freebsd )
515 PTHREAD_SCOPE_PROCESS = 0,
516 PTHREAD_SCOPE_SYSTEM = 0x2
519 int pthread_attr_getinheritsched(in pthread_attr_t*, int*);
520 int pthread_attr_getschedpolicy(in pthread_attr_t*, int*);
521 int pthread_attr_getscope(in pthread_attr_t*, int*);
522 int pthread_attr_setinheritsched(pthread_attr_t*, int);
523 int pthread_attr_setschedpolicy(pthread_attr_t*, int);
524 int pthread_attr_setscope(in pthread_attr_t*, int);
525 int pthread_getschedparam(pthread_t, int*, sched_param*);
526 int pthread_setschedparam(pthread_t, int, sched_param*);
527 //int pthread_setschedprio(pthread_t, int);
534 int pthread_attr_getstack(in pthread_attr_t*, void**, size_t*); (TSA|TSS)
535 int pthread_attr_getstackaddr(in pthread_attr_t*, void**); (TSA)
536 int pthread_attr_getstacksize(in pthread_attr_t*, size_t*); (TSS)
537 int pthread_attr_setstack(pthread_attr_t*, void*, size_t); (TSA|TSS)
538 int pthread_attr_setstackaddr(pthread_attr_t*, void*); (TSA)
539 int pthread_attr_setstacksize(pthread_attr_t*, size_t); (TSS)
544 int pthread_attr_getstack(in pthread_attr_t*, void**, size_t*);
545 int pthread_attr_getstackaddr(in pthread_attr_t*, void**);
546 int pthread_attr_getstacksize(in pthread_attr_t*, size_t*);
547 int pthread_attr_setstack(pthread_attr_t*, void*, size_t);
548 int pthread_attr_setstackaddr(pthread_attr_t*, void*);
549 int pthread_attr_setstacksize(pthread_attr_t*, size_t);
551 else version( darwin )
553 int pthread_attr_getstack(in pthread_attr_t*, void**, size_t*);
554 int pthread_attr_getstackaddr(in pthread_attr_t*, void**);
555 int pthread_attr_getstacksize(in pthread_attr_t*, size_t*);
556 int pthread_attr_setstack(pthread_attr_t*, void*, size_t);
557 int pthread_attr_setstackaddr(pthread_attr_t*, void*);
558 int pthread_attr_setstacksize(pthread_attr_t*, size_t);
560 else version( freebsd )
562 int pthread_attr_getstack(in pthread_attr_t*, void**, size_t*);
563 int pthread_attr_getstackaddr(in pthread_attr_t*, void**);
564 int pthread_attr_getstacksize(in pthread_attr_t*, size_t*);
565 int pthread_attr_setstack(pthread_attr_t*, void*, size_t);
566 int pthread_attr_setstackaddr(pthread_attr_t*, void*);
567 int pthread_attr_setstacksize(pthread_attr_t*, size_t);
571 // Shared Synchronization (TSH)
574 int pthread_condattr_getpshared(in pthread_condattr_t*, int*);
575 int pthread_condattr_setpshared(pthread_condattr_t*, int);
576 int pthread_mutexattr_getpshared(in pthread_mutexattr_t*, int*);
577 int pthread_mutexattr_setpshared(pthread_mutexattr_t*, int);
578 int pthread_rwlockattr_getpshared(in pthread_rwlockattr_t*, int*);
579 int pthread_rwlockattr_setpshared(pthread_rwlockattr_t*, int);