diff options
| author | d <> | 1999-01-06 05:19:32 +0000 |
|---|---|---|
| committer | d <> | 1999-01-06 05:19:32 +0000 |
| commit | 4865b13e8e7bce02c55a40a6d1e505a6485483b6 (patch) | |
| tree | 034c28696c967fb8ec32df42cce81d4bd3f5c7f8 /src/lib/libc/include/thread_private.h | |
| parent | 13215bc3b7babd9ef92e2e94f0ed0104529722b2 (diff) | |
| download | openbsd-4865b13e8e7bce02c55a40a6d1e505a6485483b6.tar.gz openbsd-4865b13e8e7bce02c55a40a6d1e505a6485483b6.tar.bz2 openbsd-4865b13e8e7bce02c55a40a6d1e505a6485483b6.zip | |
clean
Diffstat (limited to 'src/lib/libc/include/thread_private.h')
| -rw-r--r-- | src/lib/libc/include/thread_private.h | 74 |
1 files changed, 39 insertions, 35 deletions
diff --git a/src/lib/libc/include/thread_private.h b/src/lib/libc/include/thread_private.h index a7f7749078..0027468269 100644 --- a/src/lib/libc/include/thread_private.h +++ b/src/lib/libc/include/thread_private.h | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | * Support for thread-safety in libc and libc_r common code using macros | 3 | * Support for thread-safety in libc and libc_r common code using macros |
| 4 | * to declare thread-safe data structures. | 4 | * to declare thread-safe data structures. |
| 5 | * | 5 | * |
| 6 | * $OpenBSD: thread_private.h,v 1.1 1998/11/20 11:18:41 d Exp $ | 6 | * $OpenBSD: thread_private.h,v 1.2 1999/01/06 05:19:32 d Exp $ |
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | #ifndef _THREAD_PRIVATE_H_ | 9 | #ifndef _THREAD_PRIVATE_H_ |
| @@ -14,8 +14,8 @@ | |||
| 14 | * Copyright (c) 1998 John Birrell <jb@cimlogic.com.au>. | 14 | * Copyright (c) 1998 John Birrell <jb@cimlogic.com.au>. |
| 15 | * All rights reserved. | 15 | * All rights reserved. |
| 16 | * | 16 | * |
| 17 | * $Id: thread_private.h,v 1.1 1998/11/20 11:18:41 d Exp $ | 17 | * $Id: thread_private.h,v 1.2 1999/01/06 05:19:32 d Exp $ |
| 18 | * $OpenBSD: thread_private.h,v 1.1 1998/11/20 11:18:41 d Exp $ | 18 | * $OpenBSD: thread_private.h,v 1.2 1999/01/06 05:19:32 d Exp $ |
| 19 | */ | 19 | */ |
| 20 | 20 | ||
| 21 | /* | 21 | /* |
| @@ -32,6 +32,30 @@ extern volatile int __isthreaded; | |||
| 32 | #include <pthread.h> | 32 | #include <pthread.h> |
| 33 | #include "pthread_private.h" | 33 | #include "pthread_private.h" |
| 34 | 34 | ||
| 35 | /* | ||
| 36 | * File lock contention is difficult to diagnose without knowing | ||
| 37 | * where locks were set. Allow a debug library to be built which | ||
| 38 | * records the source file and line number of each lock call. | ||
| 39 | */ | ||
| 40 | #ifdef _FLOCK_DEBUG | ||
| 41 | #define _FLOCKFILE(x) _flockfile_debug(x, __FILE__, __LINE__) | ||
| 42 | #else | ||
| 43 | #define _FLOCKFILE(x) flockfile(x) | ||
| 44 | #endif | ||
| 45 | |||
| 46 | /* | ||
| 47 | * These macros help in making persistent storage thread-specific. | ||
| 48 | * Libc makes extensive use of private static data structures | ||
| 49 | * that hold state across function invocation, and these macros | ||
| 50 | * are no-ops when _THREAD_SAFE is not defined. | ||
| 51 | * In a thread-safe library, the static variables are used only for | ||
| 52 | * initialising the per-thread instances of the state variables. | ||
| 53 | */ | ||
| 54 | |||
| 55 | /* | ||
| 56 | * Give names to the private variables used to hold per-thread | ||
| 57 | * data structures. | ||
| 58 | */ | ||
| 35 | #ifdef __STDC__ | 59 | #ifdef __STDC__ |
| 36 | #define __THREAD_MUTEXP_NAME(name) _thread_mutexp_inst__ ## name | 60 | #define __THREAD_MUTEXP_NAME(name) _thread_mutexp_inst__ ## name |
| 37 | #define __THREAD_MUTEX_NAME(name) _thread_mutex_inst__ ## name | 61 | #define __THREAD_MUTEX_NAME(name) _thread_mutex_inst__ ## name |
| @@ -45,7 +69,6 @@ extern volatile int __isthreaded; | |||
| 45 | /* | 69 | /* |
| 46 | * Mutex declare, lock and unlock macros. | 70 | * Mutex declare, lock and unlock macros. |
| 47 | */ | 71 | */ |
| 48 | |||
| 49 | #define _THREAD_PRIVATE_MUTEX(name) \ | 72 | #define _THREAD_PRIVATE_MUTEX(name) \ |
| 50 | static struct pthread_mutex __THREAD_MUTEXP_NAME(name) = \ | 73 | static struct pthread_mutex __THREAD_MUTEXP_NAME(name) = \ |
| 51 | PTHREAD_MUTEX_STATIC_INITIALIZER; \ | 74 | PTHREAD_MUTEX_STATIC_INITIALIZER; \ |
| @@ -59,16 +82,7 @@ extern volatile int __isthreaded; | |||
| 59 | pthread_mutex_unlock(&__THREAD_MUTEX_NAME(name)) | 82 | pthread_mutex_unlock(&__THREAD_MUTEX_NAME(name)) |
| 60 | 83 | ||
| 61 | /* | 84 | /* |
| 62 | * These macros help in making persistent storage thread-specific. | 85 | * A mutexed data structure used to hold the persistent state's key. |
| 63 | * Libc makes extensive use of private static data structures | ||
| 64 | * that hold state across function invocation, and these macros | ||
| 65 | * are no-ops when _THREAD_SAFE is not defined. | ||
| 66 | * In a thread-safe library, the static variables are used only for | ||
| 67 | * initialising the per-thread instances of the state variables. | ||
| 68 | */ | ||
| 69 | |||
| 70 | /* | ||
| 71 | * a mutexed data structure used to hold the persistent state's key | ||
| 72 | */ | 86 | */ |
| 73 | struct _thread_private_key_struct { | 87 | struct _thread_private_key_struct { |
| 74 | struct pthread_mutex lockd; | 88 | struct pthread_mutex lockd; |
| @@ -138,11 +152,17 @@ struct _thread_private_key_struct { | |||
| 138 | __p; \ | 152 | __p; \ |
| 139 | }) | 153 | }) |
| 140 | 154 | ||
| 141 | #else | 155 | /* |
| 156 | * Macros for locking and unlocking FILEs. These test if the | ||
| 157 | * process is threaded to avoid locking when not required. | ||
| 158 | */ | ||
| 159 | #define FLOCKFILE(fp) if (__isthreaded) _FLOCKFILE(fp) | ||
| 160 | #define FUNLOCKFILE(fp) if (__isthreaded) funlockfile(fp) | ||
| 142 | 161 | ||
| 162 | #else /* !_THREAD_SAFE */ | ||
| 143 | 163 | ||
| 144 | /* | 164 | /* |
| 145 | * do-nothing macros for single-threaded case | 165 | * Do-nothing macros for single-threaded case. |
| 146 | */ | 166 | */ |
| 147 | #define _FD_LOCK(f,o,p) (0) | 167 | #define _FD_LOCK(f,o,p) (0) |
| 148 | #define _FD_UNLOCK(f,o) /* nothing */ | 168 | #define _FD_UNLOCK(f,o) /* nothing */ |
| @@ -151,25 +171,9 @@ struct _thread_private_key_struct { | |||
| 151 | #define _THREAD_PRIVATE_MUTEX(_name) /* nothing */ | 171 | #define _THREAD_PRIVATE_MUTEX(_name) /* nothing */ |
| 152 | #define _THREAD_PRIVATE_MUTEX_LOCK(_name) /* nothing */ | 172 | #define _THREAD_PRIVATE_MUTEX_LOCK(_name) /* nothing */ |
| 153 | #define _THREAD_PRIVATE_MUTEX_UNLOCK(_name) /* nothing */ | 173 | #define _THREAD_PRIVATE_MUTEX_UNLOCK(_name) /* nothing */ |
| 174 | #define FLOCKFILE(fp) /* nothing */ | ||
| 175 | #define FUNLOCKFILE(fp) /* nothing */ | ||
| 154 | 176 | ||
| 155 | #endif | 177 | #endif /* !_THREAD_SAFE */ |
| 156 | |||
| 157 | /* | ||
| 158 | * File lock contention is difficult to diagnose without knowing | ||
| 159 | * where locks were set. Allow a debug library to be built which | ||
| 160 | * records the source file and line number of each lock call. | ||
| 161 | */ | ||
| 162 | #ifdef _FLOCK_DEBUG | ||
| 163 | #define _FLOCKFILE(x) _flockfile_debug(x, __FILE__, __LINE__) | ||
| 164 | #else | ||
| 165 | #define _FLOCKFILE(x) flockfile(x) | ||
| 166 | #endif | ||
| 167 | |||
| 168 | /* | ||
| 169 | * Macros for locking and unlocking FILEs. These test if the | ||
| 170 | * process is threaded to avoid locking when not required. | ||
| 171 | */ | ||
| 172 | #define FLOCKFILE(fp) if (__isthreaded) _FLOCKFILE(fp) | ||
| 173 | #define FUNLOCKFILE(fp) if (__isthreaded) funlockfile(fp) | ||
| 174 | 178 | ||
| 175 | #endif _THREAD_PRIVATE_H_ | 179 | #endif _THREAD_PRIVATE_H_ |
