libc_private.h revision 133754
1234370Sjasone/* 2234370Sjasone * Copyright (c) 1998 John Birrell <jb@cimlogic.com.au>. 3234370Sjasone * All rights reserved. 4234370Sjasone * 5234370Sjasone * Redistribution and use in source and binary forms, with or without 6234370Sjasone * modification, are permitted provided that the following conditions 7234370Sjasone * are met: 8245868Sjasone * 1. Redistributions of source code must retain the above copyright 9234370Sjasone * notice, this list of conditions and the following disclaimer. 10234370Sjasone * 2. Redistributions in binary form must reproduce the above copyright 11234370Sjasone * notice, this list of conditions and the following disclaimer in the 12234370Sjasone * documentation and/or other materials provided with the distribution. 13234370Sjasone * 3. All advertising materials mentioning features or use of this software 14234370Sjasone * must display the following acknowledgement: 15234370Sjasone * This product includes software developed by John Birrell. 16234370Sjasone * 4. Neither the name of the author nor the names of any co-contributors 17234370Sjasone * may be used to endorse or promote products derived from this software 18234370Sjasone * without specific prior written permission. 19234370Sjasone * 20234370Sjasone * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 21234370Sjasone * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22234370Sjasone * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23234370Sjasone * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24234370Sjasone * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25234370Sjasone * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26234370Sjasone * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27234370Sjasone * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28234370Sjasone * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29234370Sjasone * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30234370Sjasone * SUCH DAMAGE. 31234370Sjasone * 32234370Sjasone * $FreeBSD: head/lib/libc/include/libc_private.h 133754 2004-08-15 16:18:52Z dfr $ 33234370Sjasone * 34234370Sjasone * Private definitions for libc, libc_r and libpthread. 35234370Sjasone * 36234370Sjasone */ 37234370Sjasone 38234370Sjasone#ifndef _LIBC_PRIVATE_H_ 39234370Sjasone#define _LIBC_PRIVATE_H_ 40234370Sjasone 41234370Sjasone/* 42234370Sjasone * This global flag is non-zero when a process has created one 43234370Sjasone * or more threads. It is used to avoid calling locking functions 44234370Sjasone * when they are not required. 45234370Sjasone */ 46234370Sjasoneextern int __isthreaded; 47234370Sjasone 48234370Sjasone/* 49234370Sjasone * File lock contention is difficult to diagnose without knowing 50234370Sjasone * where locks were set. Allow a debug library to be built which 51234370Sjasone * records the source file and line number of each lock call. 52234370Sjasone */ 53234370Sjasone#ifdef _FLOCK_DEBUG 54234370Sjasone#define _FLOCKFILE(x) _flockfile_debug(x, __FILE__, __LINE__) 55234370Sjasone#else 56234370Sjasone#define _FLOCKFILE(x) _flockfile(x) 57234370Sjasone#endif 58234370Sjasone 59234370Sjasone/* 60234370Sjasone * Macros for locking and unlocking FILEs. These test if the 61234370Sjasone * process is threaded to avoid locking when not required. 62234370Sjasone */ 63234370Sjasone#define FLOCKFILE(fp) if (__isthreaded) _FLOCKFILE(fp) 64234370Sjasone#define FUNLOCKFILE(fp) if (__isthreaded) _funlockfile(fp) 65234370Sjasone 66234370Sjasone/* 67234370Sjasone * Indexes into the pthread jump table. 68234370Sjasone * 69234370Sjasone * Warning! If you change this type, you must also change the threads 70234370Sjasone * libraries that reference it (libc_r, libpthread). 71234370Sjasone */ 72234370Sjasonetypedef enum { 73234370Sjasone PJT_COND_BROADCAST, 74234370Sjasone PJT_COND_DESTROY, 75234370Sjasone PJT_COND_INIT, 76234370Sjasone PJT_COND_SIGNAL, 77234370Sjasone PJT_COND_WAIT, 78245868Sjasone PJT_GETSPECIFIC, 79234370Sjasone PJT_KEY_CREATE, 80245868Sjasone PJT_KEY_DELETE, 81234370Sjasone PJT_MAIN_NP, 82234370Sjasone PJT_MUTEX_DESTROY, 83234370Sjasone PJT_MUTEX_INIT, 84234370Sjasone PJT_MUTEX_LOCK, 85234370Sjasone PJT_MUTEX_TRYLOCK, 86234370Sjasone PJT_MUTEX_UNLOCK, 87234370Sjasone PJT_MUTEXATTR_DESTROY, 88234370Sjasone PJT_MUTEXATTR_INIT, 89 PJT_MUTEXATTR_SETTYPE, 90 PJT_ONCE, 91 PJT_RWLOCK_DESTROY, 92 PJT_RWLOCK_INIT, 93 PJT_RWLOCK_RDLOCK, 94 PJT_RWLOCK_TRYRDLOCK, 95 PJT_RWLOCK_TRYWRLOCK, 96 PJT_RWLOCK_UNLOCK, 97 PJT_RWLOCK_WRLOCK, 98 PJT_SELF, 99 PJT_SETSPECIFIC, 100 PJT_SIGMASK, 101 PJT_MAX 102} pjt_index_t; 103 104typedef int (*pthread_func_t)(void); 105typedef pthread_func_t pthread_func_entry_t[2]; 106 107extern pthread_func_entry_t __thr_jtable[]; 108 109/* 110 * yplib internal interfaces 111 */ 112#ifdef YP 113int _yp_check(char **); 114#endif 115 116/* 117 * Initialise TLS for static programs 118 */ 119void _init_tls(void); 120 121/* 122 * Set the TLS thread pointer 123 */ 124void _set_tp(void *tp); 125 126/* 127 * This is a pointer in the C run-time startup code. It is used 128 * by getprogname() and setprogname(). 129 */ 130extern const char *__progname; 131 132/* 133 * This is the lock to make malloc() thread-safe. It is externalized 134 * so that thread libraries can protect malloc across fork(). 135 */ 136extern struct _spinlock *__malloc_lock; 137 138#endif /* _LIBC_PRIVATE_H_ */ 139