diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/include/thread_private.h | 74 |
1 files changed, 39 insertions, 35 deletions
diff --git a/lib/libc/include/thread_private.h b/lib/libc/include/thread_private.h index a7f77490780..0027468269b 100644 --- a/lib/libc/include/thread_private.h +++ b/lib/libc/include/thread_private.h @@ -3,7 +3,7 @@ * Support for thread-safety in libc and libc_r common code using macros * to declare thread-safe data structures. * - * $OpenBSD: thread_private.h,v 1.1 1998/11/20 11:18:41 d Exp $ + * $OpenBSD: thread_private.h,v 1.2 1999/01/06 05:19:32 d Exp $ */ #ifndef _THREAD_PRIVATE_H_ @@ -14,8 +14,8 @@ * Copyright (c) 1998 John Birrell <jb@cimlogic.com.au>. * All rights reserved. * - * $Id: thread_private.h,v 1.1 1998/11/20 11:18:41 d Exp $ - * $OpenBSD: thread_private.h,v 1.1 1998/11/20 11:18:41 d Exp $ + * $Id: thread_private.h,v 1.2 1999/01/06 05:19:32 d Exp $ + * $OpenBSD: thread_private.h,v 1.2 1999/01/06 05:19:32 d Exp $ */ /* @@ -32,6 +32,30 @@ extern volatile int __isthreaded; #include <pthread.h> #include "pthread_private.h" +/* + * File lock contention is difficult to diagnose without knowing + * where locks were set. Allow a debug library to be built which + * records the source file and line number of each lock call. + */ +#ifdef _FLOCK_DEBUG +#define _FLOCKFILE(x) _flockfile_debug(x, __FILE__, __LINE__) +#else +#define _FLOCKFILE(x) flockfile(x) +#endif + +/* + * These macros help in making persistent storage thread-specific. + * Libc makes extensive use of private static data structures + * that hold state across function invocation, and these macros + * are no-ops when _THREAD_SAFE is not defined. + * In a thread-safe library, the static variables are used only for + * initialising the per-thread instances of the state variables. + */ + +/* + * Give names to the private variables used to hold per-thread + * data structures. + */ #ifdef __STDC__ #define __THREAD_MUTEXP_NAME(name) _thread_mutexp_inst__ ## name #define __THREAD_MUTEX_NAME(name) _thread_mutex_inst__ ## name @@ -45,7 +69,6 @@ extern volatile int __isthreaded; /* * Mutex declare, lock and unlock macros. */ - #define _THREAD_PRIVATE_MUTEX(name) \ static struct pthread_mutex __THREAD_MUTEXP_NAME(name) = \ PTHREAD_MUTEX_STATIC_INITIALIZER; \ @@ -59,16 +82,7 @@ extern volatile int __isthreaded; pthread_mutex_unlock(&__THREAD_MUTEX_NAME(name)) /* - * These macros help in making persistent storage thread-specific. - * Libc makes extensive use of private static data structures - * that hold state across function invocation, and these macros - * are no-ops when _THREAD_SAFE is not defined. - * In a thread-safe library, the static variables are used only for - * initialising the per-thread instances of the state variables. - */ - -/* - * a mutexed data structure used to hold the persistent state's key + * A mutexed data structure used to hold the persistent state's key. */ struct _thread_private_key_struct { struct pthread_mutex lockd; @@ -138,11 +152,17 @@ struct _thread_private_key_struct { __p; \ }) -#else +/* + * Macros for locking and unlocking FILEs. These test if the + * process is threaded to avoid locking when not required. + */ +#define FLOCKFILE(fp) if (__isthreaded) _FLOCKFILE(fp) +#define FUNLOCKFILE(fp) if (__isthreaded) funlockfile(fp) +#else /* !_THREAD_SAFE */ /* - * do-nothing macros for single-threaded case + * Do-nothing macros for single-threaded case. */ #define _FD_LOCK(f,o,p) (0) #define _FD_UNLOCK(f,o) /* nothing */ @@ -151,25 +171,9 @@ struct _thread_private_key_struct { #define _THREAD_PRIVATE_MUTEX(_name) /* nothing */ #define _THREAD_PRIVATE_MUTEX_LOCK(_name) /* nothing */ #define _THREAD_PRIVATE_MUTEX_UNLOCK(_name) /* nothing */ +#define FLOCKFILE(fp) /* nothing */ +#define FUNLOCKFILE(fp) /* nothing */ -#endif - -/* - * File lock contention is difficult to diagnose without knowing - * where locks were set. Allow a debug library to be built which - * records the source file and line number of each lock call. - */ -#ifdef _FLOCK_DEBUG -#define _FLOCKFILE(x) _flockfile_debug(x, __FILE__, __LINE__) -#else -#define _FLOCKFILE(x) flockfile(x) -#endif - -/* - * Macros for locking and unlocking FILEs. These test if the - * process is threaded to avoid locking when not required. - */ -#define FLOCKFILE(fp) if (__isthreaded) _FLOCKFILE(fp) -#define FUNLOCKFILE(fp) if (__isthreaded) funlockfile(fp) +#endif /* !_THREAD_SAFE */ #endif _THREAD_PRIVATE_H_ |