pthread.h revision 19637
113547Sjulian/*
213547Sjulian * Copyright (c) 1993, 1994 by Chris Provenzano, proven@mit.edu
313547Sjulian * Copyright (c) 1995 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
6317706Sjulian#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/*
7017706Sjulian * Forward structure definitions.
7117706Sjulian *
7217706Sjulian * These are mostly opaque to the user.
7313547Sjulian */
7417706Sjulianstruct pthread;
7517706Sjulianstruct pthread_attr;
7617706Sjulianstruct pthread_cond;
7717706Sjulianstruct pthread_cond_attr;
7817706Sjulianstruct pthread_mutex;
7917706Sjulianstruct pthread_mutex_attr;
8017706Sjulianstruct pthread_once;
8117706Sjulianstruct sched_param;
8213547Sjulian
8313547Sjulian/*
8417706Sjulian * Primitive system data type definitions required by P1003.1c.
8517706Sjulian *
8617706Sjulian * Note that P1003.1c specifies that there are no defined comparison
8717706Sjulian * or assignment operators for the types pthread_attr_t, pthread_cond_t,
8817706Sjulian * pthread_condattr_t, pthread_mutex_t, pthread_mutexattr_t.
8913547Sjulian */
9017706Sjuliantypedef struct	pthread			*pthread_t;
9117706Sjuliantypedef struct	pthread_attr		*pthread_attr_t;
9217706Sjuliantypedef struct	pthread_mutex		*pthread_mutex_t;
9317706Sjuliantypedef struct	pthread_mutex_attr	*pthread_mutexattr_t;
9417706Sjuliantypedef struct	pthread_cond		*pthread_cond_t;
9517706Sjuliantypedef struct	pthread_cond_attr	*pthread_condattr_t;
9617706Sjuliantypedef int     			pthread_key_t;
9717706Sjuliantypedef struct	pthread_once		pthread_once_t;
9813547Sjulian
9913547Sjulian/*
10017706Sjulian * Additional type definitions:
10117706Sjulian *
10217706Sjulian * Note that P1003.1c reserves the prefixes pthread_ and PTHREAD_ for
10317706Sjulian * use in header symbols.
10413547Sjulian */
10517706Sjuliantypedef void	*pthread_addr_t;
10617706Sjuliantypedef void	*(*pthread_startroutine_t) (void *);
10713547Sjulian
10813547Sjulian/*
10913547Sjulian * Once definitions.
11013547Sjulian */
11113547Sjulianstruct pthread_once {
11217706Sjulian	int		state;
11317706Sjulian	pthread_mutex_t	mutex;
11413547Sjulian};
11513547Sjulian
11613547Sjulian/*
11713547Sjulian * Flags for once initialization.
11813547Sjulian */
11913547Sjulian#define PTHREAD_NEEDS_INIT  0
12013547Sjulian#define PTHREAD_DONE_INIT   1
12113547Sjulian
12213547Sjulian/*
12313547Sjulian * Static once initialization values.
12413547Sjulian */
12517706Sjulian#define PTHREAD_ONCE_INIT   { PTHREAD_NEEDS_INIT, NULL }
12613547Sjulian
12713547Sjulian/*
12813547Sjulian * Default attribute arguments.
12913547Sjulian */
13013547Sjulian#define pthread_condattr_default    NULL
13119637Shsu#ifndef PTHREAD_KERNEL
13213547Sjulian#define pthread_mutexattr_default   NULL
13313547Sjulian#define pthread_attr_default        NULL
13413547Sjulian#endif
13513547Sjulian
13619637Shsuenum pthread_mutextype {
13719637Shsu	MUTEX_TYPE_FAST			= 1,
13819637Shsu	MUTEX_TYPE_COUNTING_FAST	= 2,	/* Recursive */
13919637Shsu	MUTEX_TYPE_MAX
14019637Shsu};
14119637Shsu
14213547Sjulian/*
14313547Sjulian * Thread function prototype definitions:
14413547Sjulian */
14513547Sjulian__BEGIN_DECLS
14617706Sjulianint		pthread_attr_destroy __P((pthread_attr_t *));
14717706Sjulianint		pthread_attr_getinheritsched __P((pthread_attr_t *, int *));
14817706Sjulianint		pthread_attr_getschedparam __P((pthread_attr_t *,
14917706Sjulian			struct sched_param *));
15017706Sjulianint		pthread_attr_getschedpolicy __P((pthread_attr_t *, int *));
15117706Sjulianint		pthread_attr_getscope __P((pthread_attr_t *, int *));
15217706Sjulianint		pthread_attr_getstacksize __P((pthread_attr_t *, size_t *));
15317706Sjulianint		pthread_attr_getstackaddr __P((pthread_attr_t *, void **));
15417706Sjulianint		pthread_attr_getdetachstate __P((pthread_attr_t *, int *));
15517706Sjulianint		pthread_attr_init __P((pthread_attr_t *));
15617706Sjulianint		pthread_attr_setinheritsched __P((pthread_attr_t *, int));
15717706Sjulianint		pthread_attr_setschedparam __P((pthread_attr_t *,
15817706Sjulian			struct sched_param *));
15917706Sjulianint		pthread_attr_setschedpolicy __P((pthread_attr_t *, int));
16017706Sjulianint		pthread_attr_setscope __P((pthread_attr_t *, int));
16117706Sjulianint		pthread_attr_setstacksize __P((pthread_attr_t *, size_t));
16217706Sjulianint		pthread_attr_setstackaddr __P((pthread_attr_t *, void *));
16317706Sjulianint		pthread_attr_setdetachstate __P((pthread_attr_t *, int));
16417706Sjulianvoid		pthread_cleanup_pop __P((int execute));
16517706Sjulianint		pthread_cleanup_push __P((void (*routine) (void *),
16617706Sjulian			void *routine_arg));
16717706Sjulianint		pthread_condattr_destroy __P((pthread_condattr_t *attr));
16817706Sjulianint		pthread_condattr_init __P((pthread_condattr_t *attr));
16917706Sjulianint		pthread_condattr_getpshared __P((pthread_condattr_t *attr,
17017706Sjulian			int *pshared));
17117706Sjulianint		pthread_condattr_setpshared __P((pthread_condattr_t *attr,
17217706Sjulian			int pshared));
17317706Sjulianint		pthread_cond_broadcast __P((pthread_cond_t *));
17417706Sjulianint		pthread_cond_destroy __P((pthread_cond_t *));
17517706Sjulianint		pthread_cond_init __P((pthread_cond_t *,
17617706Sjulian			const pthread_condattr_t *));
17717706Sjulianint		pthread_cond_signal __P((pthread_cond_t *));
17817706Sjulianint		pthread_cond_timedwait __P((pthread_cond_t *,
17917706Sjulian			pthread_mutex_t *, const struct timespec * abstime));
18017706Sjulianint		pthread_cond_wait __P((pthread_cond_t *, pthread_mutex_t *));
18117706Sjulianint		pthread_create __P((pthread_t *, const pthread_attr_t *,
18217706Sjulian			void *(*start_routine) (void *), void *));
18317706Sjulianint		pthread_detach __P((pthread_t *));
18417706Sjulianint		pthread_equal __P((pthread_t, pthread_t));
18517706Sjulianvoid		pthread_exit __P((void *));
18619637Shsuvoid		*pthread_getspecific __P((pthread_key_t));
18717706Sjulianint		pthread_join __P((pthread_t, void **));
18817706Sjulianint		pthread_key_create __P((pthread_key_t *,
18917706Sjulian			void (*routine) (void *)));
19017706Sjulianint		pthread_key_delete __P((pthread_key_t));
19117706Sjulianint		pthread_kill __P((struct pthread *, int));
19217706Sjulianint		pthread_mutexattr_destroy __P((pthread_mutexattr_t *));
19317706Sjulianint		pthread_mutexattr_getprioceiling __P((pthread_mutexattr_t *,
19417706Sjulian			int *prioceiling));
19517706Sjulianint		pthread_mutexattr_getprotocol __P((pthread_mutexattr_t *,
19617706Sjulian			int *protocol));
19717706Sjulianint		pthread_mutexattr_getpshared __P((pthread_mutexattr_t *,
19817706Sjulian			int *pshared));
19917706Sjulianint		pthread_mutexattr_init __P((pthread_mutexattr_t *));
20017706Sjulianint		pthread_mutexattr_setprioceiling __P((pthread_mutexattr_t *,
20117706Sjulian			int prioceiling));
20217706Sjulianint		pthread_mutexattr_setprotocol __P((pthread_mutexattr_t *,
20317706Sjulian			int protocol));
20417706Sjulianint		pthread_mutexattr_setpshared __P((pthread_mutexattr_t *,
20517706Sjulian			int pshared));
20617706Sjulianint		pthread_mutex_destroy __P((pthread_mutex_t *));
20717706Sjulianint		pthread_mutex_getprioceiling __P((pthread_mutex_t *));
20817706Sjulianint		pthread_mutex_init __P((pthread_mutex_t *,
20917706Sjulian			const pthread_mutexattr_t *));
21017706Sjulianint		pthread_mutex_lock __P((pthread_mutex_t *));
21117706Sjulianint		pthread_mutex_setprioceiling __P((pthread_mutex_t *));
21217706Sjulianint		pthread_mutex_trylock __P((pthread_mutex_t *));
21317706Sjulianint		pthread_mutex_unlock __P((pthread_mutex_t *));
21417706Sjulianint		pthread_once __P((pthread_once_t *,
21517706Sjulian			void (*init_routine) (void)));
21617706Sjulianpthread_t	pthread_self __P((void));
21717706Sjulianint		pthread_setcancelstate __P((int, int *));
21817706Sjulianint		pthread_setcanceltype __P((int, int *));
21917706Sjulianint		pthread_setspecific __P((pthread_key_t, const void *));
22017706Sjulianint		pthread_sigmask __P((int, const sigset_t *, sigset_t *));
22117706Sjulianint		pthread_testcancel __P((void));
22217706Sjulian
22317706Sjulian
22417706Sjulianint		pthread_getprio __P((pthread_t));
22517706Sjulianint		pthread_setprio __P((pthread_t, int));
22617706Sjulianvoid		pthread_yield __P((void));
22717706Sjulianint		pthread_setschedparam __P((pthread_t pthread, int policy,
22817706Sjulian			struct sched_param * param));
22917706Sjulianint		pthread_getschedparam __P((pthread_t pthread, int *policy,
23017706Sjulian			struct sched_param * param));
23117706Sjulianint		pthread_attr_setfloatstate __P((pthread_attr_t *, int));
23217706Sjulianint		pthread_attr_getfloatstate __P((pthread_attr_t *, int *));
23317706Sjulianint		pthread_attr_setcleanup __P((pthread_attr_t *,
23417706Sjulian			void (*routine) (void *), void *));
23513547Sjulian__END_DECLS
23613547Sjulian
23713547Sjulian#endif
238