pthread.h revision 50473
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 50473 1999-08-27 23:45:13Z peter $
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/*
9117706Sjulian * Forward structure definitions.
9217706Sjulian *
9317706Sjulian * These are mostly opaque to the user.
9413547Sjulian */
9517706Sjulianstruct pthread;
9617706Sjulianstruct pthread_attr;
9717706Sjulianstruct pthread_cond;
9817706Sjulianstruct pthread_cond_attr;
9917706Sjulianstruct pthread_mutex;
10017706Sjulianstruct pthread_mutex_attr;
10117706Sjulianstruct pthread_once;
10238919Salexstruct pthread_rwlock;
10338919Salexstruct pthread_rwlockattr;
10413547Sjulian
10513547Sjulian/*
10617706Sjulian * Primitive system data type definitions required by P1003.1c.
10717706Sjulian *
10817706Sjulian * Note that P1003.1c specifies that there are no defined comparison
10917706Sjulian * or assignment operators for the types pthread_attr_t, pthread_cond_t,
11017706Sjulian * pthread_condattr_t, pthread_mutex_t, pthread_mutexattr_t.
11113547Sjulian */
11217706Sjuliantypedef struct	pthread			*pthread_t;
11317706Sjuliantypedef struct	pthread_attr		*pthread_attr_t;
11417706Sjuliantypedef struct	pthread_mutex		*pthread_mutex_t;
11517706Sjuliantypedef struct	pthread_mutex_attr	*pthread_mutexattr_t;
11617706Sjuliantypedef struct	pthread_cond		*pthread_cond_t;
11717706Sjuliantypedef struct	pthread_cond_attr	*pthread_condattr_t;
11817706Sjuliantypedef int     			pthread_key_t;
11917706Sjuliantypedef struct	pthread_once		pthread_once_t;
12038919Salextypedef struct	pthread_rwlock		*pthread_rwlock_t;
12138919Salextypedef struct	pthread_rwlockattr	*pthread_rwlockattr_t;
12213547Sjulian
12313547Sjulian/*
12417706Sjulian * Additional type definitions:
12517706Sjulian *
12617706Sjulian * Note that P1003.1c reserves the prefixes pthread_ and PTHREAD_ for
12717706Sjulian * use in header symbols.
12813547Sjulian */
12917706Sjuliantypedef void	*pthread_addr_t;
13025519Sbdetypedef void	*(*pthread_startroutine_t) __P((void *));
13113547Sjulian
13213547Sjulian/*
13313547Sjulian * Once definitions.
13413547Sjulian */
13513547Sjulianstruct pthread_once {
13617706Sjulian	int		state;
13717706Sjulian	pthread_mutex_t	mutex;
13813547Sjulian};
13913547Sjulian
14013547Sjulian/*
14113547Sjulian * Flags for once initialization.
14213547Sjulian */
14313547Sjulian#define PTHREAD_NEEDS_INIT  0
14413547Sjulian#define PTHREAD_DONE_INIT   1
14513547Sjulian
14613547Sjulian/*
14713547Sjulian * Static once initialization values.
14813547Sjulian */
14917706Sjulian#define PTHREAD_ONCE_INIT   { PTHREAD_NEEDS_INIT, NULL }
15013547Sjulian
15113547Sjulian/*
15235025Sjb * Static initialization values.
15313547Sjulian */
15435025Sjb#define PTHREAD_MUTEX_INITIALIZER	NULL
15535025Sjb#define PTHREAD_COND_INITIALIZER	NULL
15638919Salex#define PTHREAD_RWLOCK_INITIALIZER	NULL
15735025Sjb
15835025Sjb/*
15935025Sjb * Default attribute arguments (draft 4, deprecated).
16035025Sjb */
16122315Sjulian#ifndef PTHREAD_KERNEL
16213547Sjulian#define pthread_condattr_default    NULL
16313547Sjulian#define pthread_mutexattr_default   NULL
16413547Sjulian#define pthread_attr_default        NULL
16513547Sjulian#endif
16613547Sjulian
16744965Sjb#define PTHREAD_PRIO_NONE	0
16844965Sjb#ifdef _POSIX_THREAD_PRIO_PROTECT
16944965Sjb#define PTHREAD_PRIO_INHERIT	1
17044965Sjb#define PTHREAD_PRIO_PROTECT	2
17144965Sjb#endif
17244965Sjb
17344965Sjb/*
17444965Sjb * Mutex types (Single UNIX Specification, Version 2, 1997).
17544965Sjb *
17644965Sjb * Note that a mutex attribute with one of the following types:
17744965Sjb *
17844965Sjb *	PTHREAD_MUTEX_NORMAL
17944965Sjb *	PTHREAD_MUTEX_RECURSIVE
18044965Sjb *      MUTEX_TYPE_FAST (deprecated)
18144965Sjb *	MUTEX_TYPE_COUNTING_FAST (deprecated)
18244965Sjb *
18344965Sjb * will deviate from POSIX specified semantics.
18444965Sjb */
18519637Shsuenum pthread_mutextype {
18644965Sjb	PTHREAD_MUTEX_ERRORCHECK	= 1,	/* Default POSIX mutex */
18744965Sjb	PTHREAD_MUTEX_RECURSIVE		= 2,	/* Recursive mutex */
18844965Sjb	PTHREAD_MUTEX_NORMAL		= 3,	/* No error checking */
18919637Shsu	MUTEX_TYPE_MAX
19019637Shsu};
19119637Shsu
19244965Sjb#define PTHREAD_MUTEX_DEFAULT		PTHREAD_MUTEX_ERRORCHECK
19344965Sjb#define MUTEX_TYPE_FAST			PTHREAD_MUTEX_NORMAL
19441390Seivind#define MUTEX_TYPE_COUNTING_FAST	PTHREAD_MUTEX_RECURSIVE
19541390Seivind
19613547Sjulian/*
19713547Sjulian * Thread function prototype definitions:
19813547Sjulian */
19913547Sjulian__BEGIN_DECLS
20017706Sjulianint		pthread_attr_destroy __P((pthread_attr_t *));
20117706Sjulianint		pthread_attr_getstacksize __P((pthread_attr_t *, size_t *));
20217706Sjulianint		pthread_attr_getstackaddr __P((pthread_attr_t *, void **));
20317706Sjulianint		pthread_attr_getdetachstate __P((pthread_attr_t *, int *));
20417706Sjulianint		pthread_attr_init __P((pthread_attr_t *));
20517706Sjulianint		pthread_attr_setstacksize __P((pthread_attr_t *, size_t));
20617706Sjulianint		pthread_attr_setstackaddr __P((pthread_attr_t *, void *));
20717706Sjulianint		pthread_attr_setdetachstate __P((pthread_attr_t *, int));
20849307Srsevoid		pthread_cleanup_pop __P((int));
20949307Srsevoid		pthread_cleanup_push __P((void (*) (void *),
21017706Sjulian			void *routine_arg));
21149307Srseint		pthread_condattr_destroy __P((pthread_condattr_t *));
21249307Srseint		pthread_condattr_init __P((pthread_condattr_t *));
21344965Sjb
21444965Sjb#if defined(_POSIX_THREAD_PROCESS_SHARED)
21549307Srseint		pthread_condattr_getpshared __P((pthread_condattr_t *,
21649307Srse			int *));
21749307Srseint		pthread_condattr_setpshared __P((pthread_condattr_t *,
21849307Srse			int));
21944965Sjb#endif
22044965Sjb
22117706Sjulianint		pthread_cond_broadcast __P((pthread_cond_t *));
22217706Sjulianint		pthread_cond_destroy __P((pthread_cond_t *));
22317706Sjulianint		pthread_cond_init __P((pthread_cond_t *,
22417706Sjulian			const pthread_condattr_t *));
22517706Sjulianint		pthread_cond_signal __P((pthread_cond_t *));
22617706Sjulianint		pthread_cond_timedwait __P((pthread_cond_t *,
22749307Srse			pthread_mutex_t *, const struct timespec *));
22817706Sjulianint		pthread_cond_wait __P((pthread_cond_t *, pthread_mutex_t *));
22917706Sjulianint		pthread_create __P((pthread_t *, const pthread_attr_t *,
23049307Srse			void *(*) (void *), void *));
23131985Salexint		pthread_detach __P((pthread_t));
23217706Sjulianint		pthread_equal __P((pthread_t, pthread_t));
23317706Sjulianvoid		pthread_exit __P((void *));
23419637Shsuvoid		*pthread_getspecific __P((pthread_key_t));
23517706Sjulianint		pthread_join __P((pthread_t, void **));
23617706Sjulianint		pthread_key_create __P((pthread_key_t *,
23749307Srse			void (*) (void *)));
23817706Sjulianint		pthread_key_delete __P((pthread_key_t));
23917706Sjulianint		pthread_kill __P((struct pthread *, int));
24044965Sjbint		pthread_mutexattr_init __P((pthread_mutexattr_t *));
24117706Sjulianint		pthread_mutexattr_destroy __P((pthread_mutexattr_t *));
24241390Seivindint		pthread_mutexattr_settype __P((pthread_mutexattr_t *, int));
24317706Sjulianint		pthread_mutex_destroy __P((pthread_mutex_t *));
24417706Sjulianint		pthread_mutex_init __P((pthread_mutex_t *,
24517706Sjulian			const pthread_mutexattr_t *));
24617706Sjulianint		pthread_mutex_lock __P((pthread_mutex_t *));
24717706Sjulianint		pthread_mutex_trylock __P((pthread_mutex_t *));
24817706Sjulianint		pthread_mutex_unlock __P((pthread_mutex_t *));
24917706Sjulianint		pthread_once __P((pthread_once_t *,
25049307Srse			void (*) (void)));
25138919Salexint		pthread_rwlock_destroy __P((pthread_rwlock_t *));
25238919Salexint		pthread_rwlock_init __P((pthread_rwlock_t *,
25338919Salex			const pthread_rwlockattr_t *));
25438919Salexint		pthread_rwlock_rdlock __P((pthread_rwlock_t *));
25538919Salexint		pthread_rwlock_tryrdlock __P((pthread_rwlock_t *));
25638919Salexint		pthread_rwlock_trywrlock __P((pthread_rwlock_t *));
25738919Salexint		pthread_rwlock_unlock __P((pthread_rwlock_t *));
25838919Salexint		pthread_rwlock_wrlock __P((pthread_rwlock_t *));
25938919Salexint		pthread_rwlockattr_init __P((pthread_rwlockattr_t *));
26038919Salexint		pthread_rwlockattr_getpshared __P((const pthread_rwlockattr_t *,
26138919Salex			int *));
26238919Salexint		pthread_rwlockattr_setpshared __P((pthread_rwlockattr_t *,
26338919Salex			int *));
26438919Salexint		pthread_rwlockattr_destroy __P((pthread_rwlockattr_t *));
26517706Sjulianpthread_t	pthread_self __P((void));
26617706Sjulianint		pthread_setspecific __P((pthread_key_t, const void *));
26717706Sjulianint		pthread_sigmask __P((int, const sigset_t *, sigset_t *));
26817706Sjulian
26949127Sdeischen#ifdef NOT_YET
27049127Sdeischenint		pthread_cancel __P((pthread_t));
27149127Sdeischenint		pthread_setcancelstate __P((int, int *));
27249127Sdeischenint		pthread_setcanceltype __P((int, int *));
27349127Sdeischenvoid		pthread_testcancel __P((void));
27449127Sdeischen#endif
27517706Sjulian
27617706Sjulianint		pthread_getprio __P((pthread_t));
27717706Sjulianint		pthread_setprio __P((pthread_t, int));
27817706Sjulianvoid		pthread_yield __P((void));
27944965Sjb
28044965Sjb#if defined(_POSIX_THREAD_PROCESS_SHARED)
28144965Sjbint		pthread_mutexattr_getpshared __P((pthread_mutexattr_t *,
28244965Sjb			int *pshared));
28344965Sjbint		pthread_mutexattr_setpshared __P((pthread_mutexattr_t *,
28444965Sjb			int pshared));
28544965Sjb#endif
28644965Sjb
28744965Sjb#if defined(_POSIX_THREAD_PRIO_PROTECT)
28844965Sjbint		pthread_mutexattr_getprioceiling __P((pthread_mutexattr_t *,
28949307Srse			int *));
29044965Sjbint		pthread_mutexattr_setprioceiling __P((pthread_mutexattr_t *,
29149307Srse			int));
29244965Sjbint		pthread_mutex_getprioceiling __P((pthread_mutex_t *, int *));
29344965Sjbint		pthread_mutex_setprioceiling __P((pthread_mutex_t *, int, int *));
29444965Sjb#endif
29544965Sjb
29644965Sjb#if defined(_POSIX_THREAD_PRIO_PROTECT) || defined (_POSIX_THREAD_PRIO_INHERIT)
29744965Sjbint		pthread_mutexattr_getprotocol __P((pthread_mutexattr_t *,
29849307Srse			int *));
29944965Sjbint		pthread_mutexattr_setprotocol __P((pthread_mutexattr_t *,
30049307Srse			int));
30144965Sjb#endif
30244965Sjb
30344965Sjb#if defined(_POSIX_THREAD_PRIORITY_SCHEDULING)
30444965Sjbint		pthread_attr_getinheritsched __P((pthread_attr_t *, int *));
30544965Sjbint		pthread_attr_getschedparam __P((pthread_attr_t *,
30644965Sjb			struct sched_param *));
30744965Sjbint		pthread_attr_getschedpolicy __P((pthread_attr_t *, int *));
30844965Sjbint		pthread_attr_getscope __P((pthread_attr_t *, int *));
30944965Sjbint		pthread_attr_setinheritsched __P((pthread_attr_t *, int));
31044965Sjbint		pthread_attr_setschedparam __P((pthread_attr_t *,
31144965Sjb			struct sched_param *));
31244965Sjbint		pthread_attr_setschedpolicy __P((pthread_attr_t *, int));
31344965Sjbint		pthread_attr_setscope __P((pthread_attr_t *, int));
31449307Srseint		pthread_getschedparam __P((pthread_t pthread, int *,
31549307Srse			struct sched_param *));
31649307Srseint		pthread_setschedparam __P((pthread_t, int,
31749307Srse			struct sched_param *));
31844965Sjb#endif
31944965Sjb
32017706Sjulianint		pthread_attr_setfloatstate __P((pthread_attr_t *, int));
32117706Sjulianint		pthread_attr_getfloatstate __P((pthread_attr_t *, int *));
32217706Sjulianint		pthread_attr_setcleanup __P((pthread_attr_t *,
32349307Srse			void (*) (void *), void *));
32413547Sjulian__END_DECLS
32513547Sjulian
32613547Sjulian#endif
327