pthread.h revision 38919
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 * 3313547Sjulian */ 3413547Sjulian#ifndef _PTHREAD_H_ 3513547Sjulian#define _PTHREAD_H_ 3613547Sjulian 3713547Sjulian/* 3813547Sjulian * Header files. 3913547Sjulian */ 4013547Sjulian#include <sys/cdefs.h> 4113547Sjulian#include <sys/types.h> 4213547Sjulian#include <sys/time.h> 4317706Sjulian#include <sys/signal.h> 4417706Sjulian#include <limits.h> 4513547Sjulian 4613547Sjulian/* 4717706Sjulian * Run-time invariant values: 4813547Sjulian */ 4917706Sjulian#define PTHREAD_DESTRUCTOR_ITERATIONS 4 5017706Sjulian#define PTHREAD_KEYS_MAX 256 5117706Sjulian#define PTHREAD_STACK_MIN 1024 5217706Sjulian#define PTHREAD_THREADS_MAX ULONG_MAX 5313547Sjulian 5413547Sjulian/* 5517706Sjulian * Compile time symbolic constants for portability specifications: 5617706Sjulian * 5717706Sjulian * Note that those commented out are not currently supported by the 5817706Sjulian * implementation. 5913547Sjulian */ 6017706Sjulian#define _POSIX_THREADS 6117706Sjulian#define _POSIX_THREAD_ATTR_STACKADDR 6217706Sjulian#define _POSIX_THREAD_ATTR_STACKSIZE 6323364Salex/* #define _POSIX_THREAD_PRIORITY_SCHEDULING */ 6417706Sjulian/* #define _POSIX_THREAD_PRIO_INHERIT */ 6517706Sjulian/* #define _POSIX_THREAD_PRIO_PROTECT */ 6617706Sjulian/* #define _POSIX_THREAD_PROCESS_SHARED */ 6717706Sjulian#define _POSIX_THREAD_SAFE_FUNCTIONS 6813547Sjulian 6913547Sjulian/* 7022315Sjulian * Flags for threads and thread attributes. 7122315Sjulian */ 7222315Sjulian#define PTHREAD_DETACHED 0x1 7322315Sjulian#define PTHREAD_SCOPE_SYSTEM 0x2 7422315Sjulian#define PTHREAD_INHERIT_SCHED 0x4 7522315Sjulian#define PTHREAD_NOFLOAT 0x8 7622315Sjulian 7722315Sjulian#define PTHREAD_CREATE_DETACHED PTHREAD_DETACHED 7822315Sjulian#define PTHREAD_CREATE_JOINABLE 0 7922315Sjulian#define PTHREAD_SCOPE_PROCESS 0 8022315Sjulian#define PTHREAD_EXPLICIT_SCHED 0 8122315Sjulian 8222315Sjulian/* 8338919Salex * Flags for read/write lock attributes 8438919Salex */ 8538919Salex#define PTHREAD_PROCESS_PRIVATE 0 8638919Salex#define PTHREAD_PROCESS_SHARED 1 8738919Salex 8838919Salex/* 8917706Sjulian * Forward structure definitions. 9017706Sjulian * 9117706Sjulian * These are mostly opaque to the user. 9213547Sjulian */ 9317706Sjulianstruct pthread; 9417706Sjulianstruct pthread_attr; 9517706Sjulianstruct pthread_cond; 9617706Sjulianstruct pthread_cond_attr; 9717706Sjulianstruct pthread_mutex; 9817706Sjulianstruct pthread_mutex_attr; 9917706Sjulianstruct pthread_once; 10038919Salexstruct pthread_rwlock; 10138919Salexstruct pthread_rwlockattr; 10217706Sjulianstruct sched_param; 10313547Sjulian 10413547Sjulian/* 10517706Sjulian * Primitive system data type definitions required by P1003.1c. 10617706Sjulian * 10717706Sjulian * Note that P1003.1c specifies that there are no defined comparison 10817706Sjulian * or assignment operators for the types pthread_attr_t, pthread_cond_t, 10917706Sjulian * pthread_condattr_t, pthread_mutex_t, pthread_mutexattr_t. 11013547Sjulian */ 11117706Sjuliantypedef struct pthread *pthread_t; 11217706Sjuliantypedef struct pthread_attr *pthread_attr_t; 11317706Sjuliantypedef struct pthread_mutex *pthread_mutex_t; 11417706Sjuliantypedef struct pthread_mutex_attr *pthread_mutexattr_t; 11517706Sjuliantypedef struct pthread_cond *pthread_cond_t; 11617706Sjuliantypedef struct pthread_cond_attr *pthread_condattr_t; 11717706Sjuliantypedef int pthread_key_t; 11817706Sjuliantypedef struct pthread_once pthread_once_t; 11938919Salextypedef struct pthread_rwlock *pthread_rwlock_t; 12038919Salextypedef struct pthread_rwlockattr *pthread_rwlockattr_t; 12113547Sjulian 12213547Sjulian/* 12317706Sjulian * Additional type definitions: 12417706Sjulian * 12517706Sjulian * Note that P1003.1c reserves the prefixes pthread_ and PTHREAD_ for 12617706Sjulian * use in header symbols. 12713547Sjulian */ 12817706Sjuliantypedef void *pthread_addr_t; 12925519Sbdetypedef void *(*pthread_startroutine_t) __P((void *)); 13013547Sjulian 13113547Sjulian/* 13213547Sjulian * Once definitions. 13313547Sjulian */ 13413547Sjulianstruct pthread_once { 13517706Sjulian int state; 13617706Sjulian pthread_mutex_t mutex; 13713547Sjulian}; 13813547Sjulian 13913547Sjulian/* 14013547Sjulian * Flags for once initialization. 14113547Sjulian */ 14213547Sjulian#define PTHREAD_NEEDS_INIT 0 14313547Sjulian#define PTHREAD_DONE_INIT 1 14413547Sjulian 14513547Sjulian/* 14613547Sjulian * Static once initialization values. 14713547Sjulian */ 14817706Sjulian#define PTHREAD_ONCE_INIT { PTHREAD_NEEDS_INIT, NULL } 14913547Sjulian 15013547Sjulian/* 15135025Sjb * Static initialization values. 15213547Sjulian */ 15335025Sjb#define PTHREAD_MUTEX_INITIALIZER NULL 15435025Sjb#define PTHREAD_COND_INITIALIZER NULL 15538919Salex#define PTHREAD_RWLOCK_INITIALIZER NULL 15635025Sjb 15735025Sjb/* 15835025Sjb * Default attribute arguments (draft 4, deprecated). 15935025Sjb */ 16022315Sjulian#ifndef PTHREAD_KERNEL 16113547Sjulian#define pthread_condattr_default NULL 16213547Sjulian#define pthread_mutexattr_default NULL 16313547Sjulian#define pthread_attr_default NULL 16413547Sjulian#endif 16513547Sjulian 16619637Shsuenum pthread_mutextype { 16719637Shsu MUTEX_TYPE_FAST = 1, 16819637Shsu MUTEX_TYPE_COUNTING_FAST = 2, /* Recursive */ 16919637Shsu MUTEX_TYPE_MAX 17019637Shsu}; 17119637Shsu 17213547Sjulian/* 17313547Sjulian * Thread function prototype definitions: 17413547Sjulian */ 17513547Sjulian__BEGIN_DECLS 17617706Sjulianint pthread_attr_destroy __P((pthread_attr_t *)); 17717706Sjulianint pthread_attr_getinheritsched __P((pthread_attr_t *, int *)); 17817706Sjulianint pthread_attr_getschedparam __P((pthread_attr_t *, 17917706Sjulian struct sched_param *)); 18017706Sjulianint pthread_attr_getschedpolicy __P((pthread_attr_t *, int *)); 18117706Sjulianint pthread_attr_getscope __P((pthread_attr_t *, int *)); 18217706Sjulianint pthread_attr_getstacksize __P((pthread_attr_t *, size_t *)); 18317706Sjulianint pthread_attr_getstackaddr __P((pthread_attr_t *, void **)); 18417706Sjulianint pthread_attr_getdetachstate __P((pthread_attr_t *, int *)); 18517706Sjulianint pthread_attr_init __P((pthread_attr_t *)); 18617706Sjulianint pthread_attr_setinheritsched __P((pthread_attr_t *, int)); 18717706Sjulianint pthread_attr_setschedparam __P((pthread_attr_t *, 18817706Sjulian struct sched_param *)); 18917706Sjulianint pthread_attr_setschedpolicy __P((pthread_attr_t *, int)); 19017706Sjulianint pthread_attr_setscope __P((pthread_attr_t *, int)); 19117706Sjulianint pthread_attr_setstacksize __P((pthread_attr_t *, size_t)); 19217706Sjulianint pthread_attr_setstackaddr __P((pthread_attr_t *, void *)); 19317706Sjulianint pthread_attr_setdetachstate __P((pthread_attr_t *, int)); 19417706Sjulianvoid pthread_cleanup_pop __P((int execute)); 19522315Sjulianvoid pthread_cleanup_push __P((void (*routine) (void *), 19617706Sjulian void *routine_arg)); 19717706Sjulianint pthread_condattr_destroy __P((pthread_condattr_t *attr)); 19817706Sjulianint pthread_condattr_init __P((pthread_condattr_t *attr)); 19917706Sjulianint pthread_condattr_getpshared __P((pthread_condattr_t *attr, 20017706Sjulian int *pshared)); 20117706Sjulianint pthread_condattr_setpshared __P((pthread_condattr_t *attr, 20217706Sjulian int pshared)); 20317706Sjulianint pthread_cond_broadcast __P((pthread_cond_t *)); 20417706Sjulianint pthread_cond_destroy __P((pthread_cond_t *)); 20517706Sjulianint pthread_cond_init __P((pthread_cond_t *, 20617706Sjulian const pthread_condattr_t *)); 20717706Sjulianint pthread_cond_signal __P((pthread_cond_t *)); 20817706Sjulianint pthread_cond_timedwait __P((pthread_cond_t *, 20917706Sjulian pthread_mutex_t *, const struct timespec * abstime)); 21017706Sjulianint pthread_cond_wait __P((pthread_cond_t *, pthread_mutex_t *)); 21117706Sjulianint pthread_create __P((pthread_t *, const pthread_attr_t *, 21217706Sjulian void *(*start_routine) (void *), void *)); 21331985Salexint pthread_detach __P((pthread_t)); 21417706Sjulianint pthread_equal __P((pthread_t, pthread_t)); 21517706Sjulianvoid pthread_exit __P((void *)); 21619637Shsuvoid *pthread_getspecific __P((pthread_key_t)); 21717706Sjulianint pthread_join __P((pthread_t, void **)); 21817706Sjulianint pthread_key_create __P((pthread_key_t *, 21917706Sjulian void (*routine) (void *))); 22017706Sjulianint pthread_key_delete __P((pthread_key_t)); 22117706Sjulianint pthread_kill __P((struct pthread *, int)); 22217706Sjulianint pthread_mutexattr_destroy __P((pthread_mutexattr_t *)); 22317706Sjulianint pthread_mutexattr_getprioceiling __P((pthread_mutexattr_t *, 22417706Sjulian int *prioceiling)); 22517706Sjulianint pthread_mutexattr_getprotocol __P((pthread_mutexattr_t *, 22617706Sjulian int *protocol)); 22717706Sjulianint pthread_mutexattr_getpshared __P((pthread_mutexattr_t *, 22817706Sjulian int *pshared)); 22917706Sjulianint pthread_mutexattr_init __P((pthread_mutexattr_t *)); 23017706Sjulianint pthread_mutexattr_setprioceiling __P((pthread_mutexattr_t *, 23117706Sjulian int prioceiling)); 23217706Sjulianint pthread_mutexattr_setprotocol __P((pthread_mutexattr_t *, 23317706Sjulian int protocol)); 23417706Sjulianint pthread_mutexattr_setpshared __P((pthread_mutexattr_t *, 23517706Sjulian int pshared)); 23617706Sjulianint pthread_mutex_destroy __P((pthread_mutex_t *)); 23717706Sjulianint pthread_mutex_getprioceiling __P((pthread_mutex_t *)); 23817706Sjulianint pthread_mutex_init __P((pthread_mutex_t *, 23917706Sjulian const pthread_mutexattr_t *)); 24017706Sjulianint pthread_mutex_lock __P((pthread_mutex_t *)); 24117706Sjulianint pthread_mutex_setprioceiling __P((pthread_mutex_t *)); 24217706Sjulianint pthread_mutex_trylock __P((pthread_mutex_t *)); 24317706Sjulianint pthread_mutex_unlock __P((pthread_mutex_t *)); 24417706Sjulianint pthread_once __P((pthread_once_t *, 24517706Sjulian void (*init_routine) (void))); 24638919Salexint pthread_rwlock_destroy __P((pthread_rwlock_t *)); 24738919Salexint pthread_rwlock_init __P((pthread_rwlock_t *, 24838919Salex const pthread_rwlockattr_t *)); 24938919Salexint pthread_rwlock_rdlock __P((pthread_rwlock_t *)); 25038919Salexint pthread_rwlock_tryrdlock __P((pthread_rwlock_t *)); 25138919Salexint pthread_rwlock_trywrlock __P((pthread_rwlock_t *)); 25238919Salexint pthread_rwlock_unlock __P((pthread_rwlock_t *)); 25338919Salexint pthread_rwlock_wrlock __P((pthread_rwlock_t *)); 25438919Salexint pthread_rwlockattr_init __P((pthread_rwlockattr_t *)); 25538919Salexint pthread_rwlockattr_getpshared __P((const pthread_rwlockattr_t *, 25638919Salex int *)); 25738919Salexint pthread_rwlockattr_setpshared __P((pthread_rwlockattr_t *, 25838919Salex int *)); 25938919Salexint pthread_rwlockattr_destroy __P((pthread_rwlockattr_t *)); 26017706Sjulianpthread_t pthread_self __P((void)); 26117706Sjulianint pthread_setcancelstate __P((int, int *)); 26217706Sjulianint pthread_setcanceltype __P((int, int *)); 26317706Sjulianint pthread_setspecific __P((pthread_key_t, const void *)); 26417706Sjulianint pthread_sigmask __P((int, const sigset_t *, sigset_t *)); 26517706Sjulianint pthread_testcancel __P((void)); 26617706Sjulian 26717706Sjulian 26817706Sjulianint pthread_getprio __P((pthread_t)); 26917706Sjulianint pthread_setprio __P((pthread_t, int)); 27017706Sjulianvoid pthread_yield __P((void)); 27117706Sjulianint pthread_setschedparam __P((pthread_t pthread, int policy, 27217706Sjulian struct sched_param * param)); 27317706Sjulianint pthread_getschedparam __P((pthread_t pthread, int *policy, 27417706Sjulian struct sched_param * param)); 27517706Sjulianint pthread_attr_setfloatstate __P((pthread_attr_t *, int)); 27617706Sjulianint pthread_attr_getfloatstate __P((pthread_attr_t *, int *)); 27717706Sjulianint pthread_attr_setcleanup __P((pthread_attr_t *, 27817706Sjulian void (*routine) (void *), void *)); 27913547Sjulian__END_DECLS 28013547Sjulian 28113547Sjulian#endif 282