summaryrefslogtreecommitdiff
path: root/src/lib/libc/include/thread_private.h
diff options
context:
space:
mode:
authormarc <>2002-11-05 22:19:55 +0000
committermarc <>2002-11-05 22:19:55 +0000
commit46d7850737001c91bbb8e55a40aa9db06e2285ff (patch)
treef8fddac020c667341da9d9d290f231141b047d5d /src/lib/libc/include/thread_private.h
parentc8b772af00b03eb1dd9425663fd4b7f60c9693bb (diff)
downloadopenbsd-46d7850737001c91bbb8e55a40aa9db06e2285ff.tar.gz
openbsd-46d7850737001c91bbb8e55a40aa9db06e2285ff.tar.bz2
openbsd-46d7850737001c91bbb8e55a40aa9db06e2285ff.zip
thread safe libc -- 2nd try. OK miod@, millert@
Thanks to miod@ for m68k and vax fixes
Diffstat (limited to 'src/lib/libc/include/thread_private.h')
-rw-r--r--src/lib/libc/include/thread_private.h70
1 files changed, 30 insertions, 40 deletions
diff --git a/src/lib/libc/include/thread_private.h b/src/lib/libc/include/thread_private.h
index 89faade556..0b0be6cb38 100644
--- a/src/lib/libc/include/thread_private.h
+++ b/src/lib/libc/include/thread_private.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: thread_private.h,v 1.13 2002/11/03 23:58:39 marc Exp $ */ 1/* $OpenBSD: thread_private.h,v 1.14 2002/11/05 22:19:55 marc Exp $ */
2 2
3#ifndef _THREAD_PRIVATE_H_ 3#ifndef _THREAD_PRIVATE_H_
4#define _THREAD_PRIVATE_H_ 4#define _THREAD_PRIVATE_H_
@@ -18,19 +18,7 @@ extern int __isthreaded;
18 * Use WEAK_NAME(n) to get a libc-private name for n (_weak_n), 18 * Use WEAK_NAME(n) to get a libc-private name for n (_weak_n),
19 * WEAK_ALIAS(n) to generate the weak symbol n pointing to _weak_n, 19 * WEAK_ALIAS(n) to generate the weak symbol n pointing to _weak_n,
20 * WEAK_PROTOTYPE(n) to generate a prototype for _weak_n (based on n). 20 * WEAK_PROTOTYPE(n) to generate a prototype for _weak_n (based on n).
21 *
22 * If the symbol _NO_WEAK_ALIASES is defined, then symbols will be
23 */ 21 */
24
25#ifdef _NO_WEAK_ALIASES
26#ifdef _THREAD_SAFE
27#define WEAK_NAME(name) __CONCAT(_weak,name)
28#else
29#define WEAK_NAME(name) name
30#endif
31#define WEAK_ALIAS(name) /* unavailable */
32#define WEAK_PROTOTYPE(name) /* unnecessary */
33#else /* !_NO_WEAK_ALIASES */
34#define WEAK_NAME(name) __CONCAT(_weak_,name) 22#define WEAK_NAME(name) __CONCAT(_weak_,name)
35#define WEAK_ALIAS(name) __weak_alias(name, WEAK_NAME(name)) 23#define WEAK_ALIAS(name) __weak_alias(name, WEAK_NAME(name))
36#ifdef __GNUC__ 24#ifdef __GNUC__
@@ -38,7 +26,6 @@ extern int __isthreaded;
38#else 26#else
39#define WEAK_PROTOTYPE(name) /* typeof() only in gcc */ 27#define WEAK_PROTOTYPE(name) /* typeof() only in gcc */
40#endif 28#endif
41#endif /* !_NO_WEAK_ALIASES */
42 29
43/* 30/*
44 * These macros help in making persistent storage thread-specific. 31 * These macros help in making persistent storage thread-specific.
@@ -62,7 +49,7 @@ struct _thread_private_key_struct {
62void _libc_private_storage_lock(pthread_mutex_t *); 49void _libc_private_storage_lock(pthread_mutex_t *);
63void _libc_private_storage_unlock(pthread_mutex_t *); 50void _libc_private_storage_unlock(pthread_mutex_t *);
64void * _libc_private_storage(volatile struct _thread_private_key_struct *, 51void * _libc_private_storage(volatile struct _thread_private_key_struct *,
65 void *, size_t, void *); 52 void *, size_t, void *);
66 53
67/* Declare a module mutex. */ 54/* Declare a module mutex. */
68#define _THREAD_PRIVATE_MUTEX(name) \ 55#define _THREAD_PRIVATE_MUTEX(name) \
@@ -97,18 +84,7 @@ void * _libc_private_storage(volatile struct _thread_private_key_struct *,
97 */ 84 */
98#define _THREAD_PRIVATE(keyname, storage, error) \ 85#define _THREAD_PRIVATE(keyname, storage, error) \
99 _libc_private_storage(&__THREAD_KEY_NAME(keyname), \ 86 _libc_private_storage(&__THREAD_KEY_NAME(keyname), \
100 &(storage), sizeof (storage), error) 87 &(storage), sizeof (storage), error)
101
102/*
103 * Macros for locking and unlocking FILEs. These test if the
104 * process is threaded to avoid locking when not required.
105 */
106#ifdef _FLOCK_DEBUG
107#define FLOCKFILE(fp) _flockfile_debug(fp, __FILE__, __LINE__)
108#else
109#define FLOCKFILE(fp) flockfile(fp)
110#endif
111#define FUNLOCKFILE(fp) funlockfile(fp)
112 88
113/* 89/*
114 * File descriptor locking definitions. 90 * File descriptor locking definitions.
@@ -117,19 +93,33 @@ void * _libc_private_storage(volatile struct _thread_private_key_struct *,
117#define FD_WRITE 0x2 93#define FD_WRITE 0x2
118#define FD_RDWR (FD_READ | FD_WRITE) 94#define FD_RDWR (FD_READ | FD_WRITE)
119 95
120#ifdef _LOCK_DEBUG 96#define _FD_LOCK(_fd,_type,_ts) \
121#define _FD_LOCK(_fd,_type,_ts) _thread_fd_lock_debug(_fd, _type, \ 97 _thread_fd_lock(_fd, _type, _ts, __FILE__, __LINE__)
122 _ts, __FILE__, __LINE__) 98#define _FD_UNLOCK(_fd,_type) \
123#define _FD_UNLOCK(_fd,_type) _thread_fd_unlock_debug(_fd, _type, \ 99 _thread_fd_unlock(_fd, _type, __FILE__, __LINE__)
124 __FILE__, __LINE__)
125#else
126#define _FD_LOCK(_fd,_type,_ts) _thread_fd_lock(_fd, _type, _ts)
127#define _FD_UNLOCK(_fd,_type) _thread_fd_unlock(_fd, _type)
128#endif
129 100
130int _thread_fd_lock(int, int, struct timespec *); 101int _thread_fd_lock(int, int, struct timespec *, const char *, int);
131int _thread_fd_lock_debug(int, int, struct timespec *, char *, int); 102void _thread_fd_unlock(int, int, const char *, int);
132void _thread_fd_unlock(int, int); 103
133void _thread_fd_unlock_debug(int, int, char *, int); 104/*
105 * malloc lock/unlock definitions
106 */
107# define _MALLOC_LOCK() do { \
108 if (__isthreaded) \
109 _thread_malloc_lock(); \
110 } while (0)
111# define _MALLOC_UNLOCK() do { \
112 if (__isthreaded) \
113 _thread_malloc_unlock();\
114 } while (0)
115# define _MALLOC_LOCK_INIT()do { \
116 if (__isthreaded) \
117 _thread_malloc_init();\
118 } while (0)
119
120
121void _thread_malloc_init(void);
122void _thread_malloc_lock(void);
123void _thread_malloc_unlock(void);
134 124
135#endif /* _THREAD_PRIVATE_H_ */ 125#endif /* _THREAD_PRIVATE_H_ */