pthread.h revision 53812
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 53812 1999-11-28 05:38:13Z alfred $ 3413547Sjulian */ 3513547Sjulian#ifndef _PTHREAD_H_ 3613547Sjulian#define _PTHREAD_H_ 3713547Sjulian 3813547Sjulian/* 3913547Sjulian * Header files. 4013547Sjulian */ 4113547Sjulian#include <sys/cdefs.h> 4213547Sjulian#include <sys/types.h> 4313547Sjulian#include <sys/time.h> 4417706Sjulian#include <sys/signal.h> 4517706Sjulian#include <limits.h> 4644965Sjb#include <sched.h> 4713547Sjulian 4813547Sjulian/* 4917706Sjulian * Run-time invariant values: 5013547Sjulian */ 5117706Sjulian#define PTHREAD_DESTRUCTOR_ITERATIONS 4 5217706Sjulian#define PTHREAD_KEYS_MAX 256 5317706Sjulian#define PTHREAD_STACK_MIN 1024 5417706Sjulian#define PTHREAD_THREADS_MAX ULONG_MAX 5513547Sjulian 5613547Sjulian/* 5717706Sjulian * Compile time symbolic constants for portability specifications: 5817706Sjulian * 5917706Sjulian * Note that those commented out are not currently supported by the 6017706Sjulian * implementation. 6113547Sjulian */ 6217706Sjulian#define _POSIX_THREADS 6317706Sjulian#define _POSIX_THREAD_ATTR_STACKADDR 6417706Sjulian#define _POSIX_THREAD_ATTR_STACKSIZE 6544965Sjb#define _POSIX_THREAD_PRIORITY_SCHEDULING 6644965Sjb#define _POSIX_THREAD_PRIO_INHERIT 6744965Sjb#define _POSIX_THREAD_PRIO_PROTECT 6817706Sjulian/* #define _POSIX_THREAD_PROCESS_SHARED */ 6917706Sjulian#define _POSIX_THREAD_SAFE_FUNCTIONS 7013547Sjulian 7113547Sjulian/* 7222315Sjulian * Flags for threads and thread attributes. 7322315Sjulian */ 7422315Sjulian#define PTHREAD_DETACHED 0x1 7522315Sjulian#define PTHREAD_SCOPE_SYSTEM 0x2 7622315Sjulian#define PTHREAD_INHERIT_SCHED 0x4 7722315Sjulian#define PTHREAD_NOFLOAT 0x8 7822315Sjulian 7922315Sjulian#define PTHREAD_CREATE_DETACHED PTHREAD_DETACHED 8022315Sjulian#define PTHREAD_CREATE_JOINABLE 0 8122315Sjulian#define PTHREAD_SCOPE_PROCESS 0 8222315Sjulian#define PTHREAD_EXPLICIT_SCHED 0 8322315Sjulian 8422315Sjulian/* 8538919Salex * Flags for read/write lock attributes 8638919Salex */ 8738919Salex#define PTHREAD_PROCESS_PRIVATE 0 8838919Salex#define PTHREAD_PROCESS_SHARED 1 8938919Salex 9038919Salex/* 9153812Salfred * Flags for cancelling threads 9253812Salfred */ 9353812Salfred#define PTHREAD_CANCEL_ENABLE 0 9453812Salfred#define PTHREAD_CANCEL_DISABLE 1 9553812Salfred#define PTHREAD_CANCEL_DEFERRED 0 9653812Salfred#define PTHREAD_CANCEL_ASYNCHRONOUS 2 9753812Salfred#define PTHREAD_CANCELED ((void *) 1) 9853812Salfred 9953812Salfred/* 10017706Sjulian * Forward structure definitions. 10117706Sjulian * 10217706Sjulian * These are mostly opaque to the user. 10313547Sjulian */ 10417706Sjulianstruct pthread; 10517706Sjulianstruct pthread_attr; 10617706Sjulianstruct pthread_cond; 10717706Sjulianstruct pthread_cond_attr; 10817706Sjulianstruct pthread_mutex; 10917706Sjulianstruct pthread_mutex_attr; 11017706Sjulianstruct pthread_once; 11138919Salexstruct pthread_rwlock; 11238919Salexstruct pthread_rwlockattr; 11313547Sjulian 11413547Sjulian/* 11517706Sjulian * Primitive system data type definitions required by P1003.1c. 11617706Sjulian * 11717706Sjulian * Note that P1003.1c specifies that there are no defined comparison 11817706Sjulian * or assignment operators for the types pthread_attr_t, pthread_cond_t, 11917706Sjulian * pthread_condattr_t, pthread_mutex_t, pthread_mutexattr_t. 12013547Sjulian */ 12117706Sjuliantypedef struct pthread *pthread_t; 12217706Sjuliantypedef struct pthread_attr *pthread_attr_t; 12317706Sjuliantypedef struct pthread_mutex *pthread_mutex_t; 12417706Sjuliantypedef struct pthread_mutex_attr *pthread_mutexattr_t; 12517706Sjuliantypedef struct pthread_cond *pthread_cond_t; 12617706Sjuliantypedef struct pthread_cond_attr *pthread_condattr_t; 12717706Sjuliantypedef int pthread_key_t; 12817706Sjuliantypedef struct pthread_once pthread_once_t; 12938919Salextypedef struct pthread_rwlock *pthread_rwlock_t; 13038919Salextypedef struct pthread_rwlockattr *pthread_rwlockattr_t; 13113547Sjulian 13213547Sjulian/* 13317706Sjulian * Additional type definitions: 13417706Sjulian * 13517706Sjulian * Note that P1003.1c reserves the prefixes pthread_ and PTHREAD_ for 13617706Sjulian * use in header symbols. 13713547Sjulian */ 13817706Sjuliantypedef void *pthread_addr_t; 13925519Sbdetypedef void *(*pthread_startroutine_t) __P((void *)); 14013547Sjulian 14113547Sjulian/* 14213547Sjulian * Once definitions. 14313547Sjulian */ 14413547Sjulianstruct pthread_once { 14517706Sjulian int state; 14617706Sjulian pthread_mutex_t mutex; 14713547Sjulian}; 14813547Sjulian 14913547Sjulian/* 15013547Sjulian * Flags for once initialization. 15113547Sjulian */ 15213547Sjulian#define PTHREAD_NEEDS_INIT 0 15313547Sjulian#define PTHREAD_DONE_INIT 1 15413547Sjulian 15513547Sjulian/* 15613547Sjulian * Static once initialization values. 15713547Sjulian */ 15817706Sjulian#define PTHREAD_ONCE_INIT { PTHREAD_NEEDS_INIT, NULL } 15913547Sjulian 16013547Sjulian/* 16135025Sjb * Static initialization values. 16213547Sjulian */ 16335025Sjb#define PTHREAD_MUTEX_INITIALIZER NULL 16435025Sjb#define PTHREAD_COND_INITIALIZER NULL 16538919Salex#define PTHREAD_RWLOCK_INITIALIZER NULL 16635025Sjb 16735025Sjb/* 16835025Sjb * Default attribute arguments (draft 4, deprecated). 16935025Sjb */ 17022315Sjulian#ifndef PTHREAD_KERNEL 17113547Sjulian#define pthread_condattr_default NULL 17213547Sjulian#define pthread_mutexattr_default NULL 17313547Sjulian#define pthread_attr_default NULL 17413547Sjulian#endif 17513547Sjulian 17644965Sjb#define PTHREAD_PRIO_NONE 0 17744965Sjb#ifdef _POSIX_THREAD_PRIO_PROTECT 17844965Sjb#define PTHREAD_PRIO_INHERIT 1 17944965Sjb#define PTHREAD_PRIO_PROTECT 2 18044965Sjb#endif 18144965Sjb 18244965Sjb/* 18344965Sjb * Mutex types (Single UNIX Specification, Version 2, 1997). 18444965Sjb * 18544965Sjb * Note that a mutex attribute with one of the following types: 18644965Sjb * 18744965Sjb * PTHREAD_MUTEX_NORMAL 18844965Sjb * PTHREAD_MUTEX_RECURSIVE 18944965Sjb * MUTEX_TYPE_FAST (deprecated) 19044965Sjb * MUTEX_TYPE_COUNTING_FAST (deprecated) 19144965Sjb * 19244965Sjb * will deviate from POSIX specified semantics. 19344965Sjb */ 19419637Shsuenum pthread_mutextype { 19544965Sjb PTHREAD_MUTEX_ERRORCHECK = 1, /* Default POSIX mutex */ 19644965Sjb PTHREAD_MUTEX_RECURSIVE = 2, /* Recursive mutex */ 19744965Sjb PTHREAD_MUTEX_NORMAL = 3, /* No error checking */ 19819637Shsu MUTEX_TYPE_MAX 19919637Shsu}; 20019637Shsu 20144965Sjb#define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_ERRORCHECK 20244965Sjb#define MUTEX_TYPE_FAST PTHREAD_MUTEX_NORMAL 20341390Seivind#define MUTEX_TYPE_COUNTING_FAST PTHREAD_MUTEX_RECURSIVE 20441390Seivind 20513547Sjulian/* 20613547Sjulian * Thread function prototype definitions: 20713547Sjulian */ 20813547Sjulian__BEGIN_DECLS 20917706Sjulianint pthread_attr_destroy __P((pthread_attr_t *)); 21017706Sjulianint pthread_attr_getstacksize __P((pthread_attr_t *, size_t *)); 21117706Sjulianint pthread_attr_getstackaddr __P((pthread_attr_t *, void **)); 21217706Sjulianint pthread_attr_getdetachstate __P((pthread_attr_t *, int *)); 21317706Sjulianint pthread_attr_init __P((pthread_attr_t *)); 21417706Sjulianint pthread_attr_setstacksize __P((pthread_attr_t *, size_t)); 21517706Sjulianint pthread_attr_setstackaddr __P((pthread_attr_t *, void *)); 21617706Sjulianint pthread_attr_setdetachstate __P((pthread_attr_t *, int)); 21749307Srsevoid pthread_cleanup_pop __P((int)); 21849307Srsevoid pthread_cleanup_push __P((void (*) (void *), 21917706Sjulian void *routine_arg)); 22049307Srseint pthread_condattr_destroy __P((pthread_condattr_t *)); 22149307Srseint pthread_condattr_init __P((pthread_condattr_t *)); 22244965Sjb 22344965Sjb#if defined(_POSIX_THREAD_PROCESS_SHARED) 22449307Srseint pthread_condattr_getpshared __P((pthread_condattr_t *, 22549307Srse int *)); 22649307Srseint pthread_condattr_setpshared __P((pthread_condattr_t *, 22749307Srse int)); 22844965Sjb#endif 22944965Sjb 23017706Sjulianint pthread_cond_broadcast __P((pthread_cond_t *)); 23117706Sjulianint pthread_cond_destroy __P((pthread_cond_t *)); 23217706Sjulianint pthread_cond_init __P((pthread_cond_t *, 23317706Sjulian const pthread_condattr_t *)); 23417706Sjulianint pthread_cond_signal __P((pthread_cond_t *)); 23517706Sjulianint pthread_cond_timedwait __P((pthread_cond_t *, 23649307Srse pthread_mutex_t *, const struct timespec *)); 23717706Sjulianint pthread_cond_wait __P((pthread_cond_t *, pthread_mutex_t *)); 23817706Sjulianint pthread_create __P((pthread_t *, const pthread_attr_t *, 23949307Srse void *(*) (void *), void *)); 24031985Salexint pthread_detach __P((pthread_t)); 24117706Sjulianint pthread_equal __P((pthread_t, pthread_t)); 24217706Sjulianvoid pthread_exit __P((void *)); 24319637Shsuvoid *pthread_getspecific __P((pthread_key_t)); 24417706Sjulianint pthread_join __P((pthread_t, void **)); 24517706Sjulianint pthread_key_create __P((pthread_key_t *, 24649307Srse void (*) (void *))); 24717706Sjulianint pthread_key_delete __P((pthread_key_t)); 24817706Sjulianint pthread_kill __P((struct pthread *, int)); 24944965Sjbint pthread_mutexattr_init __P((pthread_mutexattr_t *)); 25017706Sjulianint pthread_mutexattr_destroy __P((pthread_mutexattr_t *)); 25141390Seivindint pthread_mutexattr_settype __P((pthread_mutexattr_t *, int)); 25217706Sjulianint pthread_mutex_destroy __P((pthread_mutex_t *)); 25317706Sjulianint pthread_mutex_init __P((pthread_mutex_t *, 25417706Sjulian const pthread_mutexattr_t *)); 25517706Sjulianint pthread_mutex_lock __P((pthread_mutex_t *)); 25617706Sjulianint pthread_mutex_trylock __P((pthread_mutex_t *)); 25717706Sjulianint pthread_mutex_unlock __P((pthread_mutex_t *)); 25817706Sjulianint pthread_once __P((pthread_once_t *, 25949307Srse void (*) (void))); 26038919Salexint pthread_rwlock_destroy __P((pthread_rwlock_t *)); 26138919Salexint pthread_rwlock_init __P((pthread_rwlock_t *, 26238919Salex const pthread_rwlockattr_t *)); 26338919Salexint pthread_rwlock_rdlock __P((pthread_rwlock_t *)); 26438919Salexint pthread_rwlock_tryrdlock __P((pthread_rwlock_t *)); 26538919Salexint pthread_rwlock_trywrlock __P((pthread_rwlock_t *)); 26638919Salexint pthread_rwlock_unlock __P((pthread_rwlock_t *)); 26738919Salexint pthread_rwlock_wrlock __P((pthread_rwlock_t *)); 26838919Salexint pthread_rwlockattr_init __P((pthread_rwlockattr_t *)); 26938919Salexint pthread_rwlockattr_getpshared __P((const pthread_rwlockattr_t *, 27038919Salex int *)); 27138919Salexint pthread_rwlockattr_setpshared __P((pthread_rwlockattr_t *, 27238919Salex int *)); 27338919Salexint pthread_rwlockattr_destroy __P((pthread_rwlockattr_t *)); 27417706Sjulianpthread_t pthread_self __P((void)); 27517706Sjulianint pthread_setspecific __P((pthread_key_t, const void *)); 27617706Sjulianint pthread_sigmask __P((int, const sigset_t *, sigset_t *)); 27717706Sjulian 27849127Sdeischenint pthread_cancel __P((pthread_t)); 27949127Sdeischenint pthread_setcancelstate __P((int, int *)); 28049127Sdeischenint pthread_setcanceltype __P((int, int *)); 28149127Sdeischenvoid pthread_testcancel __P((void)); 28217706Sjulian 28317706Sjulianint pthread_getprio __P((pthread_t)); 28417706Sjulianint pthread_setprio __P((pthread_t, int)); 28517706Sjulianvoid pthread_yield __P((void)); 28644965Sjb 28744965Sjb#if defined(_POSIX_THREAD_PROCESS_SHARED) 28844965Sjbint pthread_mutexattr_getpshared __P((pthread_mutexattr_t *, 28944965Sjb int *pshared)); 29044965Sjbint pthread_mutexattr_setpshared __P((pthread_mutexattr_t *, 29144965Sjb int pshared)); 29244965Sjb#endif 29344965Sjb 29444965Sjb#if defined(_POSIX_THREAD_PRIO_PROTECT) 29544965Sjbint pthread_mutexattr_getprioceiling __P((pthread_mutexattr_t *, 29649307Srse int *)); 29744965Sjbint pthread_mutexattr_setprioceiling __P((pthread_mutexattr_t *, 29849307Srse int)); 29944965Sjbint pthread_mutex_getprioceiling __P((pthread_mutex_t *, int *)); 30044965Sjbint pthread_mutex_setprioceiling __P((pthread_mutex_t *, int, int *)); 30144965Sjb#endif 30244965Sjb 30344965Sjb#if defined(_POSIX_THREAD_PRIO_PROTECT) || defined (_POSIX_THREAD_PRIO_INHERIT) 30444965Sjbint pthread_mutexattr_getprotocol __P((pthread_mutexattr_t *, 30549307Srse int *)); 30644965Sjbint pthread_mutexattr_setprotocol __P((pthread_mutexattr_t *, 30749307Srse int)); 30844965Sjb#endif 30944965Sjb 31044965Sjb#if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) 31153812Salfredint pthread_attr_getinheritsched __P((const pthread_attr_t *, int *)); 31253812Salfredint pthread_attr_getschedparam __P((const pthread_attr_t *, 31344965Sjb struct sched_param *)); 31453812Salfredint pthread_attr_getschedpolicy __P((const pthread_attr_t *, int *)); 31553812Salfredint pthread_attr_getscope __P((const pthread_attr_t *, int *)); 31644965Sjbint pthread_attr_setinheritsched __P((pthread_attr_t *, int)); 31744965Sjbint pthread_attr_setschedparam __P((pthread_attr_t *, 31844965Sjb struct sched_param *)); 31944965Sjbint pthread_attr_setschedpolicy __P((pthread_attr_t *, int)); 32044965Sjbint pthread_attr_setscope __P((pthread_attr_t *, int)); 32149307Srseint pthread_getschedparam __P((pthread_t pthread, int *, 32249307Srse struct sched_param *)); 32349307Srseint pthread_setschedparam __P((pthread_t, int, 32453812Salfred const struct sched_param *)); 32544965Sjb#endif 32644965Sjb 32717706Sjulianint pthread_attr_setfloatstate __P((pthread_attr_t *, int)); 32817706Sjulianint pthread_attr_getfloatstate __P((pthread_attr_t *, int *)); 32917706Sjulianint pthread_attr_setcleanup __P((pthread_attr_t *, 33049307Srse void (*) (void *), void *)); 33113547Sjulian__END_DECLS 33213547Sjulian 33313547Sjulian#endif 334