libc_private.h revision 111618
182547Smike/*
282547Smike * Copyright (c) 1998 John Birrell <jb@cimlogic.com.au>.
382547Smike * All rights reserved.
482547Smike *
582547Smike * Redistribution and use in source and binary forms, with or without
682547Smike * modification, are permitted provided that the following conditions
782547Smike * are met:
882547Smike * 1. Redistributions of source code must retain the above copyright
982547Smike *    notice, this list of conditions and the following disclaimer.
1082547Smike * 2. Redistributions in binary form must reproduce the above copyright
1182547Smike *    notice, this list of conditions and the following disclaimer in the
1282547Smike *    documentation and/or other materials provided with the distribution.
1382547Smike * 3. All advertising materials mentioning features or use of this software
1482547Smike *    must display the following acknowledgement:
1582547Smike *	This product includes software developed by John Birrell.
1682547Smike * 4. Neither the name of the author nor the names of any co-contributors
1782547Smike *    may be used to endorse or promote products derived from this software
1882547Smike *    without specific prior written permission.
1982547Smike *
2082547Smike * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
2182547Smike * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2282547Smike * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2382547Smike * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2482547Smike * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2582547Smike * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2682547Smike * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2782547Smike * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2882547Smike * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2982547Smike * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3082547Smike * SUCH DAMAGE.
31117280Scharnier *
32117280Scharnier * $FreeBSD: head/lib/libc/include/libc_private.h 111618 2003-02-27 13:40:01Z nectar $
33117280Scharnier *
34149424Spjd * Private definitions for libc, libc_r and libpthread.
35231912Strociny *
36231909Strociny */
3782547Smike
3882547Smike#ifndef _LIBC_PRIVATE_H_
39129983Sphk#define _LIBC_PRIVATE_H_
40149424Spjd
41167700Strhodes/*
42231910Strociny * This global flag is non-zero when a process has created one
43231910Strociny * or more threads. It is used to avoid calling locking functions
4482547Smike * when they are not required.
4582547Smike */
4682547Smikeextern int	__isthreaded;
4782547Smike
48231910Strociny/*
49167700Strhodes * File lock contention is difficult to diagnose without knowing
50231911Strociny * where locks were set. Allow a debug library to be built which
5182547Smike * records the source file and line number of each lock call.
5282547Smike */
5382547Smike#ifdef	_FLOCK_DEBUG
5482547Smike#define _FLOCKFILE(x)	_flockfile_debug(x, __FILE__, __LINE__)
5582547Smike#else
56255521Sjmg#define _FLOCKFILE(x)	_flockfile(x)
57231910Strociny#endif
58231911Strociny
59255521Sjmg/*
60231909Strociny * Macros for locking and unlocking FILEs. These test if the
6182547Smike * process is threaded to avoid locking when not required.
6282547Smike */
63231911Strociny#define	FLOCKFILE(fp)		if (__isthreaded) _FLOCKFILE(fp)
64255521Sjmg#define	FUNLOCKFILE(fp)		if (__isthreaded) _funlockfile(fp)
65255521Sjmg
66255521Sjmg/*
6782547Smike * Indexes into the pthread jump table.
6882547Smike *
6982547Smike * Warning! If you change this type, you must also change the threads
7082547Smike * libraries that reference it (libc_r, libpthread).
7182547Smike */
7282547Smiketypedef enum {
7382547Smike	PJT_COND_BROADCAST,
74167700Strhodes	PJT_COND_DESTROY,
75167700Strhodes	PJT_COND_INIT,
76167700Strhodes	PJT_COND_SIGNAL,
77255521Sjmg	PJT_COND_WAIT,
78255521Sjmg	PJT_GETSPECIFIC,
79255521Sjmg	PJT_KEY_CREATE,
80231911Strociny	PJT_KEY_DELETE,
81231911Strociny	PJT_MAIN_NP,
82231911Strociny	PJT_MUTEX_DESTROY,
83167356Strhodes	PJT_MUTEX_INIT,
84167356Strhodes	PJT_MUTEX_LOCK,
85167356Strhodes	PJT_MUTEX_TRYLOCK,
8682547Smike	PJT_MUTEX_UNLOCK,
8782547Smike	PJT_MUTEXATTR_DESTROY,
8882547Smike	PJT_MUTEXATTR_INIT,
8982547Smike	PJT_MUTEXATTR_SETTYPE,
9082547Smike	PJT_ONCE,
9182547Smike	PJT_RWLOCK_DESTROY,
9282547Smike	PJT_RWLOCK_INIT,
9382547Smike	PJT_RWLOCK_RDLOCK,
9482547Smike	PJT_RWLOCK_TRYRDLOCK,
95167356Strhodes	PJT_RWLOCK_TRYWRLOCK,
96255521Sjmg	PJT_RWLOCK_UNLOCK,
97129983Sphk	PJT_RWLOCK_WRLOCK,
98129983Sphk	PJT_SELF,
99129983Sphk	PJT_SETSPECIFIC,
100129983Sphk	PJT_SIGMASK,
101231909Strociny	PJT_MAX
102149424Spjd} pjt_index_t;
103149424Spjd
104149424Spjdtypedef int (*pthread_func_t)(void);
105149424Spjdtypedef pthread_func_t pthread_func_entry_t[2];
106149424Spjd
107149424Spjdextern pthread_func_entry_t __thr_jtable[];
108129983Sphk
109149424Spjd/*
110129983Sphk * yplib internal interfaces
111255521Sjmg */
112255521Sjmg#ifdef YP
113255521Sjmgint _yp_check(char **);
114255521Sjmg#endif
115255521Sjmg
116255521Sjmg
117255521Sjmg/*
118255521Sjmg * This is a pointer in the C run-time startup code. It is used
119255521Sjmg * by getprogname() and setprogname().
120255521Sjmg */
121255521Sjmgextern const char *__progname;
122255521Sjmg
123129983Sphk#endif /* _LIBC_PRIVATE_H_ */
12482547Smike