pthread.h revision 151617
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 151617 2005-10-24 05:53:54Z davidxu $
3413547Sjulian */
3513547Sjulian#ifndef _PTHREAD_H_
3613547Sjulian#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 */
5217706Sjulian#define PTHREAD_DESTRUCTOR_ITERATIONS		4
5317706Sjulian#define PTHREAD_KEYS_MAX			256
54149692Sstefanf#define PTHREAD_STACK_MIN			__MINSIGSTKSZ
55149692Sstefanf#define PTHREAD_THREADS_MAX			__ULONG_MAX
56119736Sdavidxu#define PTHREAD_BARRIER_SERIAL_THREAD		-1
5713547Sjulian
5813547Sjulian/*
5922315Sjulian * Flags for threads and thread attributes.
6022315Sjulian */
6122315Sjulian#define PTHREAD_DETACHED            0x1
6222315Sjulian#define PTHREAD_SCOPE_SYSTEM        0x2
6322315Sjulian#define PTHREAD_INHERIT_SCHED       0x4
6422315Sjulian#define PTHREAD_NOFLOAT             0x8
6522315Sjulian
6622315Sjulian#define PTHREAD_CREATE_DETACHED     PTHREAD_DETACHED
6722315Sjulian#define PTHREAD_CREATE_JOINABLE     0
6822315Sjulian#define PTHREAD_SCOPE_PROCESS       0
6922315Sjulian#define PTHREAD_EXPLICIT_SCHED      0
7022315Sjulian
7122315Sjulian/*
7238919Salex * Flags for read/write lock attributes
7338919Salex */
7438919Salex#define PTHREAD_PROCESS_PRIVATE     0
7538919Salex#define PTHREAD_PROCESS_SHARED      1
7638919Salex
7738919Salex/*
7853812Salfred * Flags for cancelling threads
7953812Salfred */
8053812Salfred#define PTHREAD_CANCEL_ENABLE		0
8153812Salfred#define PTHREAD_CANCEL_DISABLE		1
8253812Salfred#define PTHREAD_CANCEL_DEFERRED		0
8353812Salfred#define PTHREAD_CANCEL_ASYNCHRONOUS	2
8453812Salfred#define PTHREAD_CANCELED		((void *) 1)
8553812Salfred
8653812Salfred/*
8713547Sjulian * Flags for once initialization.
8813547Sjulian */
8913547Sjulian#define PTHREAD_NEEDS_INIT  0
9013547Sjulian#define PTHREAD_DONE_INIT   1
9113547Sjulian
9213547Sjulian/*
9313547Sjulian * Static once initialization values.
9413547Sjulian */
9517706Sjulian#define PTHREAD_ONCE_INIT   { PTHREAD_NEEDS_INIT, NULL }
9613547Sjulian
9713547Sjulian/*
9835025Sjb * Static initialization values.
9913547Sjulian */
10035025Sjb#define PTHREAD_MUTEX_INITIALIZER	NULL
10135025Sjb#define PTHREAD_COND_INITIALIZER	NULL
10238919Salex#define PTHREAD_RWLOCK_INITIALIZER	NULL
10335025Sjb
10435025Sjb/*
10535025Sjb * Default attribute arguments (draft 4, deprecated).
10635025Sjb */
10722315Sjulian#ifndef PTHREAD_KERNEL
10813547Sjulian#define pthread_condattr_default    NULL
10913547Sjulian#define pthread_mutexattr_default   NULL
11013547Sjulian#define pthread_attr_default        NULL
11113547Sjulian#endif
11213547Sjulian
11344965Sjb#define PTHREAD_PRIO_NONE	0
11444965Sjb#define PTHREAD_PRIO_INHERIT	1
11544965Sjb#define PTHREAD_PRIO_PROTECT	2
11644965Sjb
11744965Sjb/*
11844965Sjb * Mutex types (Single UNIX Specification, Version 2, 1997).
11944965Sjb *
12044965Sjb * Note that a mutex attribute with one of the following types:
12144965Sjb *
12244965Sjb *	PTHREAD_MUTEX_NORMAL
12344965Sjb *	PTHREAD_MUTEX_RECURSIVE
12444965Sjb *
12544965Sjb * will deviate from POSIX specified semantics.
12644965Sjb */
12719637Shsuenum pthread_mutextype {
12844965Sjb	PTHREAD_MUTEX_ERRORCHECK	= 1,	/* Default POSIX mutex */
12944965Sjb	PTHREAD_MUTEX_RECURSIVE		= 2,	/* Recursive mutex */
13044965Sjb	PTHREAD_MUTEX_NORMAL		= 3,	/* No error checking */
131149298Sstefanf	PTHREAD_MUTEX_TYPE_MAX
13219637Shsu};
13319637Shsu
13444965Sjb#define PTHREAD_MUTEX_DEFAULT		PTHREAD_MUTEX_ERRORCHECK
13541390Seivind
13613547Sjulian/*
13713547Sjulian * Thread function prototype definitions:
13813547Sjulian */
13913547Sjulian__BEGIN_DECLS
140149273Sstefanfint		pthread_atfork(void (*)(void), void (*)(void), void (*)(void));
14193032Simpint		pthread_attr_destroy(pthread_attr_t *);
142110636Salfredint		pthread_attr_getstack(const pthread_attr_t * __restrict,
143149273Sstefanf			void ** __restrict, size_t * __restrict);
14493032Simpint		pthread_attr_getstacksize(const pthread_attr_t *, size_t *);
14593032Simpint		pthread_attr_getguardsize(const pthread_attr_t *, size_t *);
14693032Simpint		pthread_attr_getstackaddr(const pthread_attr_t *, void **);
14793032Simpint		pthread_attr_getdetachstate(const pthread_attr_t *, int *);
14893032Simpint		pthread_attr_init(pthread_attr_t *);
14993032Simpint		pthread_attr_setstacksize(pthread_attr_t *, size_t);
15093032Simpint		pthread_attr_setguardsize(pthread_attr_t *, size_t);
151110636Salfredint		pthread_attr_setstack(pthread_attr_t *, void *, size_t);
15293032Simpint		pthread_attr_setstackaddr(pthread_attr_t *, void *);
15393032Simpint		pthread_attr_setdetachstate(pthread_attr_t *, int);
154119736Sdavidxuint		pthread_barrier_destroy(pthread_barrier_t *);
155119736Sdavidxuint		pthread_barrier_init(pthread_barrier_t *,
156119736Sdavidxu			const pthread_barrierattr_t *, unsigned);
157119736Sdavidxuint		pthread_barrier_wait(pthread_barrier_t *);
158119736Sdavidxuint		pthread_barrierattr_destroy(pthread_barrierattr_t *);
159119736Sdavidxuint		pthread_barrierattr_getpshared(const pthread_barrierattr_t *,
160119736Sdavidxu			int *);
161119736Sdavidxuint		pthread_barrierattr_init(pthread_barrierattr_t *);
162119736Sdavidxuint		pthread_barrierattr_setpshared(pthread_barrierattr_t *, int);
16393032Simpvoid		pthread_cleanup_pop(int);
164149273Sstefanfvoid		pthread_cleanup_push(void (*) (void *), void *);
16593032Simpint		pthread_condattr_destroy(pthread_condattr_t *);
166151617Sdavidxuint		pthread_condattr_getclock(const pthread_condattr_t *,
167151617Sdavidxu			clockid_t *);
168151617Sdavidxuint		pthread_condattr_getpshared(const pthread_condattr_t *, int *);
16993032Simpint		pthread_condattr_init(pthread_condattr_t *);
170151617Sdavidxuint		pthread_condattr_setclock(pthread_condattr_t *, clockid_t);
171151617Sdavidxuint		pthread_condattr_setpshared(pthread_condattr_t *, int);
17293032Simpint		pthread_cond_broadcast(pthread_cond_t *);
17393032Simpint		pthread_cond_destroy(pthread_cond_t *);
17493032Simpint		pthread_cond_init(pthread_cond_t *,
17593032Simp			const pthread_condattr_t *);
17693032Simpint		pthread_cond_signal(pthread_cond_t *);
17793032Simpint		pthread_cond_timedwait(pthread_cond_t *,
17893032Simp			pthread_mutex_t *, const struct timespec *);
17993032Simpint		pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *);
18093032Simpint		pthread_create(pthread_t *, const pthread_attr_t *,
18193032Simp			void *(*) (void *), void *);
18293032Simpint		pthread_detach(pthread_t);
18393032Simpint		pthread_equal(pthread_t, pthread_t);
18493032Simpvoid		pthread_exit(void *) __dead2;
18593032Simpvoid		*pthread_getspecific(pthread_key_t);
18693032Simpint		pthread_join(pthread_t, void **);
18793032Simpint		pthread_key_create(pthread_key_t *,
18893032Simp			void (*) (void *));
18993032Simpint		pthread_key_delete(pthread_key_t);
19093032Simpint		pthread_kill(pthread_t, int);
19193032Simpint		pthread_mutexattr_init(pthread_mutexattr_t *);
19293032Simpint		pthread_mutexattr_destroy(pthread_mutexattr_t *);
193151617Sdavidxuint		pthread_mutexattr_getpshared(const pthread_mutexattr_t *,
194151617Sdavidxu			int *);
19593032Simpint		pthread_mutexattr_gettype(pthread_mutexattr_t *, int *);
19693032Simpint		pthread_mutexattr_settype(pthread_mutexattr_t *, int);
197151617Sdavidxuint		pthread_mutexattr_setpshared(pthread_mutexattr_t *, int);
19893032Simpint		pthread_mutex_destroy(pthread_mutex_t *);
19993032Simpint		pthread_mutex_init(pthread_mutex_t *,
20093032Simp			const pthread_mutexattr_t *);
20193032Simpint		pthread_mutex_lock(pthread_mutex_t *);
20293032Simpint		pthread_mutex_trylock(pthread_mutex_t *);
203119736Sdavidxuint		pthread_mutex_timedlock(pthread_mutex_t *,
204119736Sdavidxu			const struct timespec *);
20593032Simpint		pthread_mutex_unlock(pthread_mutex_t *);
20693032Simpint		pthread_once(pthread_once_t *, void (*) (void));
20793032Simpint		pthread_rwlock_destroy(pthread_rwlock_t *);
20893032Simpint		pthread_rwlock_init(pthread_rwlock_t *,
20993032Simp			const pthread_rwlockattr_t *);
21093032Simpint		pthread_rwlock_rdlock(pthread_rwlock_t *);
211119790Sdavidxuint		pthread_rwlock_timedrdlock(pthread_rwlock_t *,
212119790Sdavidxu			const struct timespec *);
213139902Sdavidxuint		pthread_rwlock_timedwrlock(pthread_rwlock_t *,
214119790Sdavidxu			const struct timespec *);
21593032Simpint		pthread_rwlock_tryrdlock(pthread_rwlock_t *);
21693032Simpint		pthread_rwlock_trywrlock(pthread_rwlock_t *);
21793032Simpint		pthread_rwlock_unlock(pthread_rwlock_t *);
21893032Simpint		pthread_rwlock_wrlock(pthread_rwlock_t *);
21993032Simpint		pthread_rwlockattr_init(pthread_rwlockattr_t *);
22093032Simpint		pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *,
22193032Simp			int *);
22293032Simpint		pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int);
22393032Simpint		pthread_rwlockattr_destroy(pthread_rwlockattr_t *);
22493032Simppthread_t	pthread_self(void);
22593032Simpint		pthread_setspecific(pthread_key_t, const void *);
226149692Sstefanfint		pthread_sigmask(int, const __sigset_t *, __sigset_t *);
22717706Sjulian
228119909Sdavidxuint		pthread_spin_init(pthread_spinlock_t *, int);
229119909Sdavidxuint		pthread_spin_destroy(pthread_spinlock_t *);
230119909Sdavidxuint		pthread_spin_lock(pthread_spinlock_t *);
231119909Sdavidxuint		pthread_spin_trylock(pthread_spinlock_t *);
232119909Sdavidxuint		pthread_spin_unlock(pthread_spinlock_t *);
23393032Simpint		pthread_cancel(pthread_t);
23493032Simpint		pthread_setcancelstate(int, int *);
23593032Simpint		pthread_setcanceltype(int, int *);
23693032Simpvoid		pthread_testcancel(void);
23717706Sjulian
23893032Simpint		pthread_getprio(pthread_t);
23993032Simpint		pthread_setprio(pthread_t, int);
24093032Simpvoid		pthread_yield(void);
24144965Sjb
24293032Simpint		pthread_mutexattr_getprioceiling(pthread_mutexattr_t *,
24393032Simp			int *);
24493032Simpint		pthread_mutexattr_setprioceiling(pthread_mutexattr_t *,
24593032Simp			int);
24693032Simpint		pthread_mutex_getprioceiling(pthread_mutex_t *, int *);
24793032Simpint		pthread_mutex_setprioceiling(pthread_mutex_t *, int, int *);
24844965Sjb
24993032Simpint		pthread_mutexattr_getprotocol(pthread_mutexattr_t *, int *);
25093032Simpint		pthread_mutexattr_setprotocol(pthread_mutexattr_t *, int);
25144965Sjb
25293032Simpint		pthread_attr_getinheritsched(const pthread_attr_t *, int *);
25393032Simpint		pthread_attr_getschedparam(const pthread_attr_t *,
25493032Simp			struct sched_param *);
25593032Simpint		pthread_attr_getschedpolicy(const pthread_attr_t *, int *);
25693032Simpint		pthread_attr_getscope(const pthread_attr_t *, int *);
25793032Simpint		pthread_attr_setinheritsched(pthread_attr_t *, int);
25893032Simpint		pthread_attr_setschedparam(pthread_attr_t *,
25993032Simp			const struct sched_param *);
26093032Simpint		pthread_attr_setschedpolicy(pthread_attr_t *, int);
26193032Simpint		pthread_attr_setscope(pthread_attr_t *, int);
26293032Simpint		pthread_getschedparam(pthread_t pthread, int *,
26393032Simp			struct sched_param *);
26493032Simpint		pthread_setschedparam(pthread_t, int,
26593032Simp			const struct sched_param *);
266113729Sjdpint		pthread_getconcurrency(void);
267113729Sjdpint		pthread_setconcurrency(int);
26813547Sjulian__END_DECLS
26913547Sjulian
27013547Sjulian#endif
271