1*d44e858cSwiz /* $NetBSD: pthread.h,v 1.5 2003/01/19 19:21:49 wiz Exp $ */ 2c62a74e6Sthorpej 3c62a74e6Sthorpej /*- 4c62a74e6Sthorpej * Copyright (c) 2001 The NetBSD Foundation, Inc. 5c62a74e6Sthorpej * All rights reserved. 6c62a74e6Sthorpej * 7c62a74e6Sthorpej * This code is derived from software contributed to The NetBSD Foundation 8c62a74e6Sthorpej * by Nathan J. Williams. 9c62a74e6Sthorpej * 10c62a74e6Sthorpej * Redistribution and use in source and binary forms, with or without 11c62a74e6Sthorpej * modification, are permitted provided that the following conditions 12c62a74e6Sthorpej * are met: 13c62a74e6Sthorpej * 1. Redistributions of source code must retain the above copyright 14c62a74e6Sthorpej * notice, this list of conditions and the following disclaimer. 15c62a74e6Sthorpej * 2. Redistributions in binary form must reproduce the above copyright 16c62a74e6Sthorpej * notice, this list of conditions and the following disclaimer in the 17c62a74e6Sthorpej * documentation and/or other materials provided with the distribution. 18c62a74e6Sthorpej * 3. All advertising materials mentioning features or use of this software 19c62a74e6Sthorpej * must display the following acknowledgement: 20c62a74e6Sthorpej * This product includes software developed by the NetBSD 21c62a74e6Sthorpej * Foundation, Inc. and its contributors. 22c62a74e6Sthorpej * 4. Neither the name of The NetBSD Foundation nor the names of its 23c62a74e6Sthorpej * contributors may be used to endorse or promote products derived 24c62a74e6Sthorpej * from this software without specific prior written permission. 25c62a74e6Sthorpej * 26c62a74e6Sthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27c62a74e6Sthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28c62a74e6Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29c62a74e6Sthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30c62a74e6Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31c62a74e6Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32c62a74e6Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33c62a74e6Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34c62a74e6Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35c62a74e6Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36c62a74e6Sthorpej * POSSIBILITY OF SUCH DAMAGE. 37c62a74e6Sthorpej */ 38c62a74e6Sthorpej 39c62a74e6Sthorpej #ifndef _LIB_PTHREAD_H 40c62a74e6Sthorpej #define _LIB_PTHREAD_H 41c62a74e6Sthorpej 42c62a74e6Sthorpej #include <sys/cdefs.h> 43c62a74e6Sthorpej 44c62a74e6Sthorpej #include <time.h> /* For timespec */ 45c62a74e6Sthorpej #include <sched.h> 46c62a74e6Sthorpej 47c62a74e6Sthorpej #include "pthread_types.h" 48c62a74e6Sthorpej 49c62a74e6Sthorpej __BEGIN_DECLS 501b36c15fSchristos int pthread_create(pthread_t *, const pthread_attr_t *, 511b36c15fSchristos void *(*)(void *), void *); 521b36c15fSchristos void pthread_exit(void *) __attribute__((__noreturn__)); 531b36c15fSchristos int pthread_join(pthread_t, void **); 541b36c15fSchristos int pthread_equal(pthread_t, pthread_t); 55c62a74e6Sthorpej pthread_t pthread_self(void); 561b36c15fSchristos int pthread_detach(pthread_t); 57c62a74e6Sthorpej 581b36c15fSchristos int pthread_kill(pthread_t, int); 59c62a74e6Sthorpej 60c62a74e6Sthorpej int pthread_getrrtimer_np(void); 61c62a74e6Sthorpej int pthread_setrrtimer_np(int); 62c62a74e6Sthorpej 631b36c15fSchristos int pthread_attr_init(pthread_attr_t *); 641b36c15fSchristos int pthread_attr_destroy(pthread_attr_t *); 651b36c15fSchristos int pthread_attr_getschedparam(const pthread_attr_t *, 661b36c15fSchristos struct sched_param *); 671b36c15fSchristos int pthread_attr_setschedparam(pthread_attr_t *, 681b36c15fSchristos const struct sched_param *); 691b36c15fSchristos int pthread_attr_getstacksize(const pthread_attr_t *, size_t *); 701b36c15fSchristos int pthread_attr_setstacksize(pthread_attr_t *, size_t); 711b36c15fSchristos int pthread_attr_getguardsize(const pthread_attr_t *, size_t *); 721b36c15fSchristos int pthread_attr_setguardsize(pthread_attr_t *, size_t); 731b36c15fSchristos int pthread_attr_getstackaddr(const pthread_attr_t *, void **); 741b36c15fSchristos int pthread_attr_setstackaddr(pthread_attr_t *, void *); 751b36c15fSchristos int pthread_attr_getdetachstate(const pthread_attr_t *, int *); 761b36c15fSchristos int pthread_attr_setdetachstate(pthread_attr_t *, int); 77c62a74e6Sthorpej 781b36c15fSchristos int pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *); 791b36c15fSchristos int pthread_mutex_destroy(pthread_mutex_t *); 801b36c15fSchristos int pthread_mutex_lock(pthread_mutex_t *); 811b36c15fSchristos int pthread_mutex_trylock(pthread_mutex_t *); 821b36c15fSchristos int pthread_mutex_unlock(pthread_mutex_t *); 831b36c15fSchristos int pthread_mutexattr_init(pthread_mutexattr_t *); 841b36c15fSchristos int pthread_mutexattr_destroy(pthread_mutexattr_t *); 851b36c15fSchristos int pthread_mutexattr_gettype(const pthread_mutexattr_t *, int *); 86*d44e858cSwiz int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int); 87c62a74e6Sthorpej 881b36c15fSchristos int pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *); 891b36c15fSchristos int pthread_cond_destroy(pthread_cond_t *); 901b36c15fSchristos int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *); 911b36c15fSchristos int pthread_cond_timedwait(pthread_cond_t *, pthread_mutex_t *, 921b36c15fSchristos const struct timespec *); 931b36c15fSchristos int pthread_cond_signal(pthread_cond_t *); 941b36c15fSchristos int pthread_cond_broadcast(pthread_cond_t *); 951b36c15fSchristos int pthread_condattr_init(pthread_condattr_t *); 961b36c15fSchristos int pthread_condattr_destroy(pthread_condattr_t *); 97c62a74e6Sthorpej 981b36c15fSchristos int pthread_once(pthread_once_t *, void (*)(void)); 99c62a74e6Sthorpej 1001b36c15fSchristos int pthread_key_create(pthread_key_t *, void (*)(void *)); 1011b36c15fSchristos int pthread_key_delete(pthread_key_t); 1021b36c15fSchristos int pthread_setspecific(pthread_key_t, const void *); 1031b36c15fSchristos void* pthread_getspecific(pthread_key_t); 104c62a74e6Sthorpej 1051b36c15fSchristos int pthread_cancel(pthread_t); 1061b36c15fSchristos int pthread_setcancelstate(int, int *); 1071b36c15fSchristos int pthread_setcanceltype(int, int *); 108c62a74e6Sthorpej void pthread_testcancel(void); 109c62a74e6Sthorpej 110c62a74e6Sthorpej struct pthread_cleanup_store { 111c62a74e6Sthorpej void *pad[4]; 112c62a74e6Sthorpej }; 113c62a74e6Sthorpej 114c62a74e6Sthorpej #define pthread_cleanup_push(routine, arg) \ 115c62a74e6Sthorpej { \ 116c62a74e6Sthorpej struct pthread_cleanup_store __store; \ 117c62a74e6Sthorpej pthread__cleanup_push((routine),(arg), &__store); 118c62a74e6Sthorpej 119c62a74e6Sthorpej #define pthread_cleanup_pop(execute) \ 120c62a74e6Sthorpej pthread__cleanup_pop((execute), &__store); \ 121c62a74e6Sthorpej } 122c62a74e6Sthorpej 1231b36c15fSchristos void pthread__cleanup_push(void (*)(void *), void *, void *); 1241b36c15fSchristos void pthread__cleanup_pop(int, void *); 125c62a74e6Sthorpej 1261b36c15fSchristos int pthread_spin_init(pthread_spinlock_t *, int); 1271b36c15fSchristos int pthread_spin_destroy(pthread_spinlock_t *); 1281b36c15fSchristos int pthread_spin_lock(pthread_spinlock_t *); 1291b36c15fSchristos int pthread_spin_trylock(pthread_spinlock_t *); 1301b36c15fSchristos int pthread_spin_unlock(pthread_spinlock_t *); 131c62a74e6Sthorpej 1321b36c15fSchristos int pthread_rwlock_init(pthread_rwlock_t *, 1331b36c15fSchristos const pthread_rwlockattr_t *); 1341b36c15fSchristos int pthread_rwlock_destroy(pthread_rwlock_t *); 1351b36c15fSchristos int pthread_rwlock_rdlock(pthread_rwlock_t *); 1361b36c15fSchristos int pthread_rwlock_tryrdlock(pthread_rwlock_t *); 1371b36c15fSchristos int pthread_rwlock_wrlock(pthread_rwlock_t *); 1381b36c15fSchristos int pthread_rwlock_trywrlock(pthread_rwlock_t *); 1391b36c15fSchristos int pthread_rwlock_timedrdlock(pthread_rwlock_t *, 1401b36c15fSchristos const struct timespec *); 1411b36c15fSchristos int pthread_rwlock_timedwrlock(pthread_rwlock_t *, 1421b36c15fSchristos const struct timespec *); 1431b36c15fSchristos int pthread_rwlock_unlock(pthread_rwlock_t *); 1441b36c15fSchristos int pthread_rwlockattr_init(pthread_rwlockattr_t *); 1451b36c15fSchristos int pthread_rwlockattr_destroy(pthread_rwlockattr_t *); 146c62a74e6Sthorpej 1471b36c15fSchristos int pthread_barrier_init(pthread_barrier_t *, 1481b36c15fSchristos const pthread_barrierattr_t *, unsigned int); 1491b36c15fSchristos int pthread_barrier_wait(pthread_barrier_t *); 1501b36c15fSchristos int pthread_barrier_destroy(pthread_barrier_t *); 1511b36c15fSchristos int pthread_barrierattr_init(pthread_barrierattr_t *); 1521b36c15fSchristos int pthread_barrierattr_destroy(pthread_barrierattr_t *); 153c62a74e6Sthorpej 154c62a74e6Sthorpej int *pthread__errno(void); 155c62a74e6Sthorpej __END_DECLS 156c62a74e6Sthorpej 157c62a74e6Sthorpej #define PTHREAD_CREATE_JOINABLE 0 158c62a74e6Sthorpej #define PTHREAD_CREATE_DETACHED 1 159c62a74e6Sthorpej 160c62a74e6Sthorpej #define PTHREAD_PROCESS_PRIVATE 0 161c62a74e6Sthorpej #define PTHREAD_PROCESS_SHARED 1 162c62a74e6Sthorpej 163c62a74e6Sthorpej #define PTHREAD_CANCEL_DEFERRED 0 164c62a74e6Sthorpej #define PTHREAD_CANCEL_ASYNCHRONOUS 1 165c62a74e6Sthorpej 166c62a74e6Sthorpej #define PTHREAD_CANCEL_ENABLE 0 167c62a74e6Sthorpej #define PTHREAD_CANCEL_DISABLE 1 168c62a74e6Sthorpej 169c62a74e6Sthorpej #define PTHREAD_BARRIER_SERIAL_THREAD 1234567 170c62a74e6Sthorpej 171c62a74e6Sthorpej /* 172c62a74e6Sthorpej * POSIX 1003.1-2001, section 2.5.9.3: "The symbolic constant 173c62a74e6Sthorpej * PTHREAD_CANCELED expands to a constant expression of type (void *) 174c62a74e6Sthorpej * whose value matches no pointer to an object in memory nor the value 175c62a74e6Sthorpej * NULL." 176c62a74e6Sthorpej */ 177c62a74e6Sthorpej #define PTHREAD_CANCELED ((void *) 1) 178c62a74e6Sthorpej 179c62a74e6Sthorpej #define _POSIX_THREADS 180c62a74e6Sthorpej 181c62a74e6Sthorpej #define PTHREAD_DESTRUCTOR_ITERATIONS 4 /* Min. required */ 182c62a74e6Sthorpej #define PTHREAD_KEYS_MAX 256 183c62a74e6Sthorpej #define PTHREAD_STACK_MIN 4096 /* XXX Pulled out of my butt */ 184c62a74e6Sthorpej #define PTHREAD_THREADS_MAX 64 /* Min. required */ 185c62a74e6Sthorpej 186c62a74e6Sthorpej /* 187c62a74e6Sthorpej * Mutex attributes. 188c62a74e6Sthorpej */ 189c62a74e6Sthorpej #define PTHREAD_MUTEX_NORMAL 0 190c62a74e6Sthorpej #define PTHREAD_MUTEX_ERRORCHECK 1 191c62a74e6Sthorpej #define PTHREAD_MUTEX_RECURSIVE 2 192c62a74e6Sthorpej #define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL 193c62a74e6Sthorpej 194c62a74e6Sthorpej #endif /* _LIB_PTHREAD_H */ 195