+++ /dev/null
-/* $NetBSD: reentrant.h,v 1.10 2004/12/14 00:23:19 nathanw Exp $ */\r
-\r
-/*-\r
- * Copyright (c) 1997, 1998, 2003 The NetBSD Foundation, Inc.\r
- * All rights reserved.\r
- *\r
- * This code is derived from software contributed to The NetBSD Foundation\r
- * by J.T. Conklin, by Nathan J. Williams, and by Jason R. Thorpe.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * 1. Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * 2. Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- * 3. All advertising materials mentioning features or use of this software\r
- * must display the following acknowledgement:\r
- * This product includes software developed by the NetBSD\r
- * Foundation, Inc. and its contributors.\r
- * 4. Neither the name of The NetBSD Foundation nor the names of its\r
- * contributors may be used to endorse or promote products derived\r
- * from this software without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS\r
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS\r
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
- * POSSIBILITY OF SUCH DAMAGE.\r
- */\r
-\r
-/*\r
- * Requirements:\r
- * \r
- * 1. The thread safe mechanism should be lightweight so the library can\r
- * be used by non-threaded applications without unreasonable overhead.\r
- * \r
- * 2. There should be no dependency on a thread engine for non-threaded\r
- * applications.\r
- * \r
- * 3. There should be no dependency on any particular thread engine.\r
- * \r
- * 4. The library should be able to be compiled without support for thread\r
- * safety.\r
- * \r
- * \r
- * Rationale:\r
- * \r
- * One approach for thread safety is to provide discrete versions of the\r
- * library: one thread safe, the other not. The disadvantage of this is\r
- * that libc is rather large, and two copies of a library which are 99%+\r
- * identical is not an efficent use of resources.\r
- * \r
- * Another approach is to provide a single thread safe library. However,\r
- * it should not add significant run time or code size overhead to non-\r
- * threaded applications.\r
- * \r
- * Since the NetBSD C library is used in other projects, it should be\r
- * easy to replace the mutual exclusion primitives with ones provided by\r
- * another system. Similarly, it should also be easy to remove all\r
- * support for thread safety completely if the target environment does\r
- * not support threads.\r
- * \r
- * \r
- * Implementation Details:\r
- * \r
- * The thread primitives used by the library (mutex_t, mutex_lock, etc.)\r
- * are macros which expand to the cooresponding primitives provided by\r
- * the thread engine or to nothing. The latter is used so that code is\r
- * not unreasonably cluttered with #ifdefs when all thread safe support\r
- * is removed.\r
- * \r
- * The thread macros can be directly mapped to the mutex primitives from\r
- * pthreads, however it should be reasonably easy to wrap another mutex\r
- * implementation so it presents a similar interface.\r
- * \r
- * The thread functions operate by dispatching to symbols which are, by\r
- * default, weak-aliased to no-op functions in thread-stub/thread-stub.c\r
- * (some uses of thread operations are conditional on __isthreaded, but\r
- * not all of them are).\r
- *\r
- * When the thread library is linked in, it provides strong-alias versions\r
- * of those symbols which dispatch to its own real thread operations.\r
- *\r
- */\r
-\r
-#ifdef _REENTRANT\r
-\r
-/*\r
- * Abtract thread interface for thread-safe libraries. These routines\r
- * will use stubs in libc if the application is not linked against the\r
- * pthread library, and the real function in the pthread library if it\r
- * is.\r
- */\r
-\r
-#include <pthread.h>\r
-#include <signal.h>\r
-\r
-#define mutex_t pthread_mutex_t\r
-#define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER\r
-\r
-#define mutexattr_t pthread_mutexattr_t\r
-\r
-#define MUTEX_TYPE_NORMAL PTHREAD_MUTEX_NORMAL\r
-#define MUTEX_TYPE_ERRORCHECK PTHREAD_MUTEX_ERRORCHECK\r
-#define MUTEX_TYPE_RECURSIVE PTHREAD_MUTEX_RECURSIVE\r
-\r
-#define cond_t pthread_cond_t\r
-#define COND_INITIALIZER PTHREAD_COND_INITIALIZER\r
-\r
-#define condattr_t pthread_condattr_t\r
-\r
-#define rwlock_t pthread_rwlock_t\r
-#define RWLOCK_INITIALIZER PTHREAD_RWLOCK_INITIALIZER\r
-\r
-#define rwlockattr_t pthread_rwlockattr_t\r
-\r
-#define thread_key_t pthread_key_t\r
-\r
-#define thr_t pthread_t\r
-\r
-#define thrattr_t pthread_attr_t\r
-\r
-#define once_t pthread_once_t\r
-#define ONCE_INITIALIZER PTHREAD_ONCE_INIT\r
-\r
-#ifndef __LIBC_THREAD_STUBS\r
-\r
-__BEGIN_DECLS\r
-int __libc_mutex_init(mutex_t *, const mutexattr_t *);\r
-int __libc_mutex_lock(mutex_t *);\r
-int __libc_mutex_trylock(mutex_t *);\r
-int __libc_mutex_unlock(mutex_t *);\r
-int __libc_mutex_destroy(mutex_t *);\r
-\r
-int __libc_mutexattr_init(mutexattr_t *);\r
-int __libc_mutexattr_settype(mutexattr_t *, int);\r
-int __libc_mutexattr_destroy(mutexattr_t *);\r
-__END_DECLS\r
-\r
-#define mutex_init(m, a) __libc_mutex_init((m), (a))\r
-#define mutex_lock(m) __libc_mutex_lock((m))\r
-#define mutex_trylock(m) __libc_mutex_trylock((m))\r
-#define mutex_unlock(m) __libc_mutex_unlock((m))\r
-#define mutex_destroy(m) __libc_mutex_destroy((m))\r
-\r
-#define mutexattr_init(ma) __libc_mutexattr_init((ma))\r
-#define mutexattr_settype(ma, t) __libc_mutexattr_settype((ma), (t))\r
-#define mutexattr_destroy(ma) __libc_mutexattr_destroy((ma))\r
-\r
-__BEGIN_DECLS\r
-int __libc_cond_init(cond_t *, const condattr_t *);\r
-int __libc_cond_signal(cond_t *);\r
-int __libc_cond_broadcast(cond_t *);\r
-int __libc_cond_wait(cond_t *, mutex_t *);\r
-int __libc_cond_timedwait(cond_t *, mutex_t *, const struct timespec *);\r
-int __libc_cond_destroy(cond_t *);\r
-__END_DECLS\r
-\r
-#define cond_init(c, t, a) __libc_cond_init((c), (a))\r
-#define cond_signal(c) __libc_cond_signal((c))\r
-#define cond_broadcast(c) __libc_cond_broadcast((c))\r
-#define cond_wait(c, m) __libc_cond_wait((c), (m))\r
-#define cond_timedwait(c, m, t) __libc_cond_timedwait((c), (m), (t))\r
-#define cond_destroy(c) __libc_cond_destroy((c))\r
-\r
-__BEGIN_DECLS\r
-int __libc_rwlock_init(rwlock_t *, const rwlockattr_t *);\r
-int __libc_rwlock_rdlock(rwlock_t *);\r
-int __libc_rwlock_wrlock(rwlock_t *);\r
-int __libc_rwlock_tryrdlock(rwlock_t *);\r
-int __libc_rwlock_trywrlock(rwlock_t *);\r
-int __libc_rwlock_unlock(rwlock_t *);\r
-int __libc_rwlock_destroy(rwlock_t *);\r
-__END_DECLS\r
-\r
-#define rwlock_init(l, a) __libc_rwlock_init((l), (a))\r
-#define rwlock_rdlock(l) __libc_rwlock_rdlock((l))\r
-#define rwlock_wrlock(l) __libc_rwlock_wrlock((l))\r
-#define rwlock_tryrdlock(l) __libc_rwlock_tryrdlock((l))\r
-#define rwlock_trywrlock(l) __libc_rwlock_trywrlock((l))\r
-#define rwlock_unlock(l) __libc_rwlock_unlock((l))\r
-#define rwlock_destroy(l) __libc_rwlock_destroy((l))\r
-\r
-__BEGIN_DECLS\r
-int __libc_thr_keycreate(thread_key_t *, void (*)(void *));\r
-int __libc_thr_setspecific(thread_key_t, const void *);\r
-void *__libc_thr_getspecific(thread_key_t);\r
-int __libc_thr_keydelete(thread_key_t);\r
-__END_DECLS\r
-\r
-#define thr_keycreate(k, d) __libc_thr_keycreate((k), (d))\r
-#define thr_setspecific(k, p) __libc_thr_setspecific((k), (p))\r
-#define thr_getspecific(k) __libc_thr_getspecific((k))\r
-#define thr_keydelete(k) __libc_thr_keydelete((k))\r
-\r
-__BEGIN_DECLS\r
-int __libc_thr_once(once_t *, void (*)(void));\r
-int __libc_thr_sigsetmask(int, const sigset_t *, sigset_t *);\r
-thr_t __libc_thr_self(void);\r
-int __libc_thr_yield(void);\r
-void __libc_thr_create(thr_t *, const thrattr_t *,\r
- void *(*)(void *), void *);\r
-void __libc_thr_exit(void *) __attribute__((__noreturn__));\r
-int *__libc_thr_errno(void);\r
-int __libc_thr_setcancelstate(int, int *);\r
-\r
-extern int __isthreaded;\r
-__END_DECLS\r
-\r
-#define thr_once(o, f) __libc_thr_once((o), (f))\r
-#define thr_sigsetmask(f, n, o) __libc_thr_sigsetmask((f), (n), (o))\r
-#define thr_self() __libc_thr_self()\r
-#define thr_yield() __libc_thr_yield()\r
-#define thr_create(tp, ta, f, a) __libc_thr_create((tp), (ta), (f), (a))\r
-#define thr_exit(v) __libc_thr_exit((v))\r
-#define thr_errno() __libc_thr_errno()\r
-#define thr_enabled() (__isthreaded)\r
-#define thr_setcancelstate(n, o) __libc_thr_setcancelstate((n),(o))\r
-#endif /* __LIBC_THREAD_STUBS */\r
-\r
-#define FLOCKFILE(fp) __flockfile_internal(fp, 1)\r
-#define FUNLOCKFILE(fp) __funlockfile_internal(fp, 1)\r
-\r
-#else /* _REENTRANT */\r
-\r
-#define mutex_init(m, a)\r
-#define mutex_lock(m)\r
-#define mutex_trylock(m)\r
-#define mutex_unlock(m)\r
-#define mutex_destroy(m)\r
-\r
-#define cond_init(c, t, a)\r
-#define cond_signal(c)\r
-#define cond_broadcast(c)\r
-#define cond_wait(c, m)\r
-#define cond_timedwait(c, m, t)\r
-#define cond_destroy(c)\r
-\r
-#define rwlock_init(l, a)\r
-#define rwlock_rdlock(l)\r
-#define rwlock_wrlock(l)\r
-#define rwlock_tryrdlock(l)\r
-#define rwlock_trywrlock(l)\r
-#define rwlock_unlock(l)\r
-#define rwlock_destroy(l)\r
-\r
-#define thr_keycreate(k, d)\r
-#define thr_setspecific(k, p)\r
-#define thr_getspecific(k)\r
-#define thr_keydelete(k)\r
-\r
-#define thr_once(o, f)\r
-#define thr_sigsetmask(f, n, o)\r
-#define thr_self()\r
-#define thr_errno()\r
-\r
-#define FLOCKFILE(fp) \r
-#define FUNLOCKFILE(fp) \r
-\r
-#endif /* _REENTRANT */\r