pthread.h revision 280820
113547Sjulian/* 213547Sjulian * Copyright (c) 1993, 1994 by Chris Provenzano, proven@mit.edu 335025Sjb * Copyright (c) 1995-1998 by John Birrell <jb@cimlogic.com.au> 413547Sjulian * All rights reserved. 513547Sjulian * 613547Sjulian * Redistribution and use in source and binary forms, with or without 713547Sjulian * modification, are permitted provided that the following conditions 813547Sjulian * are met: 913547Sjulian * 1. Redistributions of source code must retain the above copyright 1013547Sjulian * notice, this list of conditions and the following disclaimer. 1113547Sjulian * 2. Redistributions in binary form must reproduce the above copyright 1213547Sjulian * notice, this list of conditions and the following disclaimer in the 1313547Sjulian * documentation and/or other materials provided with the distribution. 1413547Sjulian * 3. All advertising materials mentioning features or use of this software 1513547Sjulian * must display the following acknowledgement: 1613547Sjulian * This product includes software developed by Chris Provenzano. 1713547Sjulian * 4. The name of Chris Provenzano may not be used to endorse or promote 1813547Sjulian * products derived from this software without specific prior written 1913547Sjulian * permission. 2013547Sjulian * 2113547Sjulian * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO ``AS IS'' AND 2213547Sjulian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2313547Sjulian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2413547Sjulian * ARE DISCLAIMED. IN NO EVENT SHALL CHRIS PROVENZANO BE LIABLE FOR ANY 2513547Sjulian * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 2613547Sjulian * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 2713547Sjulian * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 2813547Sjulian * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2913547Sjulian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3013547Sjulian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3113547Sjulian * SUCH DAMAGE. 3213547Sjulian * 3350473Speter * $FreeBSD: head/include/pthread.h 280820 2015-03-29 20:20:45Z pfg $ 3413547Sjulian */ 3513547Sjulian#ifndef _PTHREAD_H_ 36280820Spfg#define _PTHREAD_H_ 3713547Sjulian 3813547Sjulian/* 3913547Sjulian * Header files. 4013547Sjulian */ 4113547Sjulian#include <sys/cdefs.h> 42146824Srodrigc#include <sys/_pthreadtypes.h> 43149692Sstefanf#include <machine/_limits.h> 44149692Sstefanf#include <machine/_types.h> 45149692Sstefanf#include <sys/_sigset.h> 4644965Sjb#include <sched.h> 47149692Sstefanf#include <time.h> 4813547Sjulian 4913547Sjulian/* 5017706Sjulian * Run-time invariant values: 5113547Sjulian */ 52280820Spfg#define PTHREAD_DESTRUCTOR_ITERATIONS 4 53280820Spfg#define PTHREAD_KEYS_MAX 256 54280820Spfg#define PTHREAD_STACK_MIN __MINSIGSTKSZ 55280820Spfg#define PTHREAD_THREADS_MAX __ULONG_MAX 56280820Spfg#define PTHREAD_BARRIER_SERIAL_THREAD -1 5713547Sjulian 5813547Sjulian/* 5922315Sjulian * Flags for threads and thread attributes. 6022315Sjulian */ 61280820Spfg#define PTHREAD_DETACHED 0x1 62280820Spfg#define PTHREAD_SCOPE_SYSTEM 0x2 63280820Spfg#define PTHREAD_INHERIT_SCHED 0x4 64280820Spfg#define PTHREAD_NOFLOAT 0x8 6522315Sjulian 66280820Spfg#define PTHREAD_CREATE_DETACHED PTHREAD_DETACHED 67280820Spfg#define PTHREAD_CREATE_JOINABLE 0 68280820Spfg#define PTHREAD_SCOPE_PROCESS 0 69280820Spfg#define PTHREAD_EXPLICIT_SCHED 0 7022315Sjulian 7122315Sjulian/* 7238919Salex * Flags for read/write lock attributes 7338919Salex */ 74280820Spfg#define PTHREAD_PROCESS_PRIVATE 0 75280820Spfg#define PTHREAD_PROCESS_SHARED 1 7638919Salex 7738919Salex/* 7853812Salfred * Flags for cancelling threads 7953812Salfred */ 80280820Spfg#define PTHREAD_CANCEL_ENABLE 0 81280820Spfg#define PTHREAD_CANCEL_DISABLE 1 82280820Spfg#define PTHREAD_CANCEL_DEFERRED 0 83280820Spfg#define PTHREAD_CANCEL_ASYNCHRONOUS 2 84280820Spfg#define PTHREAD_CANCELED ((void *) 1) 8553812Salfred 8653812Salfred/* 8713547Sjulian * Flags for once initialization. 8813547Sjulian */ 89280820Spfg#define PTHREAD_NEEDS_INIT 0 90280820Spfg#define PTHREAD_DONE_INIT 1 9113547Sjulian 9213547Sjulian/* 93280820Spfg * Static once initialization values. 9413547Sjulian */ 95280820Spfg#define PTHREAD_ONCE_INIT { PTHREAD_NEEDS_INIT, NULL } 9613547Sjulian 9713547Sjulian/* 98280820Spfg * Static initialization values. 9913547Sjulian */ 100280820Spfg#define PTHREAD_MUTEX_INITIALIZER NULL 101280820Spfg#define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP ((pthread_mutex_t)1) 102280820Spfg#define PTHREAD_COND_INITIALIZER NULL 103280820Spfg#define PTHREAD_RWLOCK_INITIALIZER NULL 10435025Sjb 10535025Sjb/* 10635025Sjb * Default attribute arguments (draft 4, deprecated). 10735025Sjb */ 10822315Sjulian#ifndef PTHREAD_KERNEL 109280820Spfg#define pthread_condattr_default NULL 110280820Spfg#define pthread_mutexattr_default NULL 111280820Spfg#define pthread_attr_default NULL 11213547Sjulian#endif 11313547Sjulian 114280820Spfg#define PTHREAD_PRIO_NONE 0 115280820Spfg#define PTHREAD_PRIO_INHERIT 1 116280820Spfg#define PTHREAD_PRIO_PROTECT 2 11744965Sjb 11844965Sjb/* 11944965Sjb * Mutex types (Single UNIX Specification, Version 2, 1997). 12044965Sjb * 12144965Sjb * Note that a mutex attribute with one of the following types: 12244965Sjb * 12344965Sjb * PTHREAD_MUTEX_NORMAL 12444965Sjb * PTHREAD_MUTEX_RECURSIVE 12544965Sjb * 12644965Sjb * will deviate from POSIX specified semantics. 12744965Sjb */ 12819637Shsuenum pthread_mutextype { 12944965Sjb PTHREAD_MUTEX_ERRORCHECK = 1, /* Default POSIX mutex */ 13044965Sjb PTHREAD_MUTEX_RECURSIVE = 2, /* Recursive mutex */ 13144965Sjb PTHREAD_MUTEX_NORMAL = 3, /* No error checking */ 132173154Skris PTHREAD_MUTEX_ADAPTIVE_NP = 4, /* Adaptive mutex, spins briefly before blocking on lock */ 133149298Sstefanf PTHREAD_MUTEX_TYPE_MAX 13419637Shsu}; 13519637Shsu 136280820Spfg#define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_ERRORCHECK 13741390Seivind 138179662Sdavidxustruct _pthread_cleanup_info { 139179662Sdavidxu __uintptr_t pthread_cleanup_pad[8]; 140179662Sdavidxu}; 141179662Sdavidxu 14213547Sjulian/* 14313547Sjulian * Thread function prototype definitions: 14413547Sjulian */ 14513547Sjulian__BEGIN_DECLS 146149273Sstefanfint pthread_atfork(void (*)(void), void (*)(void), void (*)(void)); 147280636Spfgint pthread_attr_destroy(pthread_attr_t *); 148110636Salfredint pthread_attr_getstack(const pthread_attr_t * __restrict, 149280636Spfg void ** __restrict, size_t * __restrict); 150280636Spfgint pthread_attr_getstacksize(const pthread_attr_t *, size_t *); 15193032Simpint pthread_attr_getguardsize(const pthread_attr_t *, size_t *); 15293032Simpint pthread_attr_getstackaddr(const pthread_attr_t *, void **); 153280636Spfgint pthread_attr_getdetachstate(const pthread_attr_t *, int *); 154280636Spfgint pthread_attr_init(pthread_attr_t *); 155280636Spfgint pthread_attr_setstacksize(pthread_attr_t *, size_t); 156280636Spfgint pthread_attr_setguardsize(pthread_attr_t *, size_t); 157280636Spfgint pthread_attr_setstack(pthread_attr_t *, void *, size_t); 15893032Simpint pthread_attr_setstackaddr(pthread_attr_t *, void *); 159280636Spfgint pthread_attr_setdetachstate(pthread_attr_t *, int); 160119736Sdavidxuint pthread_barrier_destroy(pthread_barrier_t *); 161119736Sdavidxuint pthread_barrier_init(pthread_barrier_t *, 162119736Sdavidxu const pthread_barrierattr_t *, unsigned); 163119736Sdavidxuint pthread_barrier_wait(pthread_barrier_t *); 164119736Sdavidxuint pthread_barrierattr_destroy(pthread_barrierattr_t *); 165119736Sdavidxuint pthread_barrierattr_getpshared(const pthread_barrierattr_t *, 166119736Sdavidxu int *); 167280636Spfgint pthread_barrierattr_init(pthread_barrierattr_t *); 168119736Sdavidxuint pthread_barrierattr_setpshared(pthread_barrierattr_t *, int); 169179662Sdavidxu 170179662Sdavidxu#define pthread_cleanup_push(cleanup_routine, cleanup_arg) \ 171179662Sdavidxu { \ 172179662Sdavidxu struct _pthread_cleanup_info __cleanup_info__; \ 173179662Sdavidxu __pthread_cleanup_push_imp(cleanup_routine, cleanup_arg,\ 174179662Sdavidxu &__cleanup_info__); \ 175179662Sdavidxu { 176179662Sdavidxu 177179662Sdavidxu#define pthread_cleanup_pop(execute) \ 178256925Stijl (void)0; \ 179179662Sdavidxu } \ 180179662Sdavidxu __pthread_cleanup_pop_imp(execute); \ 181179662Sdavidxu } 182179662Sdavidxu 183280636Spfgint pthread_condattr_destroy(pthread_condattr_t *); 184151617Sdavidxuint pthread_condattr_getclock(const pthread_condattr_t *, 185280636Spfg clockid_t *); 186280636Spfgint pthread_condattr_getpshared(const pthread_condattr_t *, int *); 187280636Spfgint pthread_condattr_init(pthread_condattr_t *); 188280636Spfgint pthread_condattr_setclock(pthread_condattr_t *, clockid_t); 189280636Spfgint pthread_condattr_setpshared(pthread_condattr_t *, int); 190280636Spfgint pthread_cond_broadcast(pthread_cond_t *); 191280636Spfgint pthread_cond_destroy(pthread_cond_t *); 19293032Simpint pthread_cond_init(pthread_cond_t *, 193280636Spfg const pthread_condattr_t *); 194280636Spfgint pthread_cond_signal(pthread_cond_t *); 19593032Simpint pthread_cond_timedwait(pthread_cond_t *, 196270943Sed pthread_mutex_t *__mutex, const struct timespec *) 197280636Spfg __requires_exclusive(*__mutex); 198270943Sedint pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *__mutex) 199280636Spfg __requires_exclusive(*__mutex); 20093032Simpint pthread_create(pthread_t *, const pthread_attr_t *, 201280636Spfg void *(*) (void *), void *); 20293032Simpint pthread_detach(pthread_t); 20393032Simpint pthread_equal(pthread_t, pthread_t); 20493032Simpvoid pthread_exit(void *) __dead2; 20593032Simpvoid *pthread_getspecific(pthread_key_t); 206280636Spfgint pthread_getcpuclockid(pthread_t, clockid_t *); 20793032Simpint pthread_join(pthread_t, void **); 20893032Simpint pthread_key_create(pthread_key_t *, 209280636Spfg void (*) (void *)); 21093032Simpint pthread_key_delete(pthread_key_t); 211280636Spfgint pthread_mutexattr_init(pthread_mutexattr_t *); 212280636Spfgint pthread_mutexattr_destroy(pthread_mutexattr_t *); 213151617Sdavidxuint pthread_mutexattr_getpshared(const pthread_mutexattr_t *, 214280636Spfg int *); 215280636Spfgint pthread_mutexattr_gettype(pthread_mutexattr_t *, int *); 216280636Spfgint pthread_mutexattr_settype(pthread_mutexattr_t *, int); 217280636Spfgint pthread_mutexattr_setpshared(pthread_mutexattr_t *, int); 218270943Sedint pthread_mutex_destroy(pthread_mutex_t *__mutex) 219280636Spfg __requires_unlocked(*__mutex); 220270943Sedint pthread_mutex_init(pthread_mutex_t *__mutex, 221270943Sed const pthread_mutexattr_t *) 222280636Spfg __requires_unlocked(*__mutex); 223270943Sedint pthread_mutex_lock(pthread_mutex_t *__mutex) 224280636Spfg __locks_exclusive(*__mutex); 225270943Sedint pthread_mutex_trylock(pthread_mutex_t *__mutex) 226280636Spfg __trylocks_exclusive(0, *__mutex); 227270943Sedint pthread_mutex_timedlock(pthread_mutex_t *__mutex, 228270943Sed const struct timespec *) 229280636Spfg __trylocks_exclusive(0, *__mutex); 230270943Sedint pthread_mutex_unlock(pthread_mutex_t *__mutex) 231280636Spfg __unlocks(*__mutex); 232280636Spfgint pthread_once(pthread_once_t *, void (*) (void)); 233270943Sedint pthread_rwlock_destroy(pthread_rwlock_t *__rwlock) 234280636Spfg __requires_unlocked(*__rwlock); 235270943Sedint pthread_rwlock_init(pthread_rwlock_t *__rwlock, 236270943Sed const pthread_rwlockattr_t *) 237280636Spfg __requires_unlocked(*__rwlock); 238270943Sedint pthread_rwlock_rdlock(pthread_rwlock_t *__rwlock) 239280636Spfg __locks_shared(*__rwlock); 240270943Sedint pthread_rwlock_timedrdlock(pthread_rwlock_t *__rwlock, 241270943Sed const struct timespec *) 242280636Spfg __trylocks_shared(0, *__rwlock); 243270943Sedint pthread_rwlock_timedwrlock(pthread_rwlock_t *__rwlock, 244270943Sed const struct timespec *) 245280636Spfg __trylocks_exclusive(0, *__rwlock); 246270943Sedint pthread_rwlock_tryrdlock(pthread_rwlock_t *__rwlock) 247280636Spfg __trylocks_shared(0, *__rwlock); 248270943Sedint pthread_rwlock_trywrlock(pthread_rwlock_t *__rwlock) 249280636Spfg __trylocks_exclusive(0, *__rwlock); 250270943Sedint pthread_rwlock_unlock(pthread_rwlock_t *__rwlock) 251280636Spfg __unlocks(*__rwlock); 252270943Sedint pthread_rwlock_wrlock(pthread_rwlock_t *__rwlock) 253280636Spfg __locks_exclusive(*__rwlock); 254280636Spfgint pthread_rwlockattr_destroy(pthread_rwlockattr_t *); 255214007Sdavidxuint pthread_rwlockattr_getkind_np(const pthread_rwlockattr_t *, 256214007Sdavidxu int *); 25793032Simpint pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *, 258280636Spfg int *); 259280636Spfgint pthread_rwlockattr_init(pthread_rwlockattr_t *); 260214007Sdavidxuint pthread_rwlockattr_setkind_np(pthread_rwlockattr_t *, int); 261280636Spfgint pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int); 26293032Simppthread_t pthread_self(void); 26393032Simpint pthread_setspecific(pthread_key_t, const void *); 26417706Sjulian 265270943Sedint pthread_spin_init(pthread_spinlock_t *__spin, int) 266270943Sed __requires_unlocked(*__spin); 267270943Sedint pthread_spin_destroy(pthread_spinlock_t *__spin) 268270943Sed __requires_unlocked(*__spin); 269270943Sedint pthread_spin_lock(pthread_spinlock_t *__spin) 270270943Sed __locks_exclusive(*__spin); 271270943Sedint pthread_spin_trylock(pthread_spinlock_t *__spin) 272270943Sed __trylocks_exclusive(0, *__spin); 273270943Sedint pthread_spin_unlock(pthread_spinlock_t *__spin) 274270943Sed __unlocks(*__spin); 27593032Simpint pthread_cancel(pthread_t); 27693032Simpint pthread_setcancelstate(int, int *); 27793032Simpint pthread_setcanceltype(int, int *); 27893032Simpvoid pthread_testcancel(void); 27917706Sjulian 280189828Sdas#if __BSD_VISIBLE 28193032Simpint pthread_getprio(pthread_t); 28293032Simpint pthread_setprio(pthread_t, int); 28393032Simpvoid pthread_yield(void); 284189828Sdas#endif 28544965Sjb 28693032Simpint pthread_mutexattr_getprioceiling(pthread_mutexattr_t *, 28793032Simp int *); 28893032Simpint pthread_mutexattr_setprioceiling(pthread_mutexattr_t *, 28993032Simp int); 29093032Simpint pthread_mutex_getprioceiling(pthread_mutex_t *, int *); 29193032Simpint pthread_mutex_setprioceiling(pthread_mutex_t *, int, int *); 29244965Sjb 29393032Simpint pthread_mutexattr_getprotocol(pthread_mutexattr_t *, int *); 29493032Simpint pthread_mutexattr_setprotocol(pthread_mutexattr_t *, int); 29544965Sjb 29693032Simpint pthread_attr_getinheritsched(const pthread_attr_t *, int *); 29793032Simpint pthread_attr_getschedparam(const pthread_attr_t *, 298280636Spfg struct sched_param *); 299280636Spfgint pthread_attr_getschedpolicy(const pthread_attr_t *, int *); 300280636Spfgint pthread_attr_getscope(const pthread_attr_t *, int *); 30193032Simpint pthread_attr_setinheritsched(pthread_attr_t *, int); 30293032Simpint pthread_attr_setschedparam(pthread_attr_t *, 303280636Spfg const struct sched_param *); 304280636Spfgint pthread_attr_setschedpolicy(pthread_attr_t *, int); 305280636Spfgint pthread_attr_setscope(pthread_attr_t *, int); 30693032Simpint pthread_getschedparam(pthread_t pthread, int *, 307280636Spfg struct sched_param *); 30893032Simpint pthread_setschedparam(pthread_t, int, 309280636Spfg const struct sched_param *); 310189828Sdas#if __XSI_VISIBLE 311113729Sjdpint pthread_getconcurrency(void); 312113729Sjdpint pthread_setconcurrency(int); 313189828Sdas#endif 314179662Sdavidxu 315179662Sdavidxuvoid __pthread_cleanup_push_imp(void (*)(void *), void *, 316179662Sdavidxu struct _pthread_cleanup_info *); 317179662Sdavidxuvoid __pthread_cleanup_pop_imp(int); 31813547Sjulian__END_DECLS 31913547Sjulian 32013547Sjulian#endif 321