diff options
Diffstat (limited to 'src/lib/libc/include')
-rw-r--r-- | src/lib/libc/include/ctype_private.h | 7 | ||||
-rw-r--r-- | src/lib/libc/include/namespace.h | 18 | ||||
-rw-r--r-- | src/lib/libc/include/thread_private.h | 138 |
3 files changed, 163 insertions, 0 deletions
diff --git a/src/lib/libc/include/ctype_private.h b/src/lib/libc/include/ctype_private.h new file mode 100644 index 0000000000..39cc792ea4 --- /dev/null +++ b/src/lib/libc/include/ctype_private.h | |||
@@ -0,0 +1,7 @@ | |||
1 | /* $OpenBSD: ctype_private.h,v 1.1 2005/08/08 05:53:00 espie Exp $ */ | ||
2 | /* Written by Marc Espie, public domain */ | ||
3 | #define CTYPE_NUM_CHARS 256 | ||
4 | extern const char _C_ctype_[]; | ||
5 | extern const short _C_toupper_[]; | ||
6 | extern const short _C_tolower_[]; | ||
7 | |||
diff --git a/src/lib/libc/include/namespace.h b/src/lib/libc/include/namespace.h new file mode 100644 index 0000000000..4a51f15ddf --- /dev/null +++ b/src/lib/libc/include/namespace.h | |||
@@ -0,0 +1,18 @@ | |||
1 | /* $OpenBSD: namespace.h,v 1.2 1996/08/19 08:28:08 tholo Exp $ */ | ||
2 | |||
3 | #define catclose _catclose | ||
4 | #define catgets _catgets | ||
5 | #define catopen _catopen | ||
6 | #define err _err | ||
7 | #define errx _errx | ||
8 | #define strtoq _strtoq | ||
9 | #define strtouq _strtouq | ||
10 | #define sys_errlist _sys_errlist | ||
11 | #define sys_nerr _sys_nerr | ||
12 | #define sys_siglist _sys_siglist | ||
13 | #define verr _verr | ||
14 | #define verrx _verrx | ||
15 | #define vwarn _vwarn | ||
16 | #define vwarnx _vwarnx | ||
17 | #define warn _warn | ||
18 | #define warnx _warnx | ||
diff --git a/src/lib/libc/include/thread_private.h b/src/lib/libc/include/thread_private.h new file mode 100644 index 0000000000..5fbbf592a4 --- /dev/null +++ b/src/lib/libc/include/thread_private.h | |||
@@ -0,0 +1,138 @@ | |||
1 | /* $OpenBSD: thread_private.h,v 1.18 2006/02/22 07:16:31 otto Exp $ */ | ||
2 | |||
3 | /* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */ | ||
4 | |||
5 | #ifndef _THREAD_PRIVATE_H_ | ||
6 | #define _THREAD_PRIVATE_H_ | ||
7 | |||
8 | /* | ||
9 | * This file defines the thread library interface to libc. Thread | ||
10 | * libraries must implement the functions described here for proper | ||
11 | * inter-operation with libc. libc contains weak versions of the | ||
12 | * described functions for operation in a non-threaded environment. | ||
13 | */ | ||
14 | |||
15 | /* | ||
16 | * This variable is 0 until a second thread is created. | ||
17 | */ | ||
18 | extern int __isthreaded; | ||
19 | |||
20 | /* | ||
21 | * Weak symbols are used in libc so that the thread library can | ||
22 | * efficiently wrap libc functions. | ||
23 | * | ||
24 | * Use WEAK_NAME(n) to get a libc-private name for n (_weak_n), | ||
25 | * WEAK_ALIAS(n) to generate the weak symbol n pointing to _weak_n, | ||
26 | * WEAK_PROTOTYPE(n) to generate a prototype for _weak_n (based on n). | ||
27 | */ | ||
28 | #define WEAK_NAME(name) __CONCAT(_weak_,name) | ||
29 | #define WEAK_ALIAS(name) __weak_alias(name, WEAK_NAME(name)) | ||
30 | #ifdef __GNUC__ | ||
31 | #define WEAK_PROTOTYPE(name) __typeof__(name) WEAK_NAME(name) | ||
32 | #else | ||
33 | #define WEAK_PROTOTYPE(name) /* typeof() only in gcc */ | ||
34 | #endif | ||
35 | |||
36 | /* | ||
37 | * helper macro to make unique names in the thread namespace | ||
38 | */ | ||
39 | #define __THREAD_NAME(name) __CONCAT(_thread_tagname_,name) | ||
40 | |||
41 | /* | ||
42 | * helper functions that exist as (weak) null functions in libc and | ||
43 | * (strong) functions in the thread library. These functions: | ||
44 | * | ||
45 | * _thread_tag_lock: | ||
46 | * lock the mutex associated with the given tag. If the given | ||
47 | * tag is NULL a tag is first allocated. | ||
48 | * | ||
49 | * _thread_tag_unlock: | ||
50 | * unlock the mutex associated with the given tag. If the given | ||
51 | * tag is NULL a tag is first allocated. | ||
52 | * | ||
53 | * _thread_tag_storage: | ||
54 | * return a pointer to per thread instance of data associated | ||
55 | * with the given tag. If the given tag is NULL a tag is first | ||
56 | * allocated. | ||
57 | */ | ||
58 | void _thread_tag_lock(void **); | ||
59 | void _thread_tag_unlock(void **); | ||
60 | void *_thread_tag_storage(void **, void *, size_t, void *); | ||
61 | |||
62 | /* | ||
63 | * Macros used in libc to access thread mutex, keys, and per thread storage. | ||
64 | * _THREAD_PRIVATE_KEY and _THREAD_PRIVATE_MUTEX are different macros for | ||
65 | * historical reasons. They do the same thing, define a static variable | ||
66 | * keyed by 'name' that identifies a mutex and a key to identify per thread | ||
67 | * data. | ||
68 | */ | ||
69 | #define _THREAD_PRIVATE_KEY(name) \ | ||
70 | static void *__THREAD_NAME(name) | ||
71 | #define _THREAD_PRIVATE_MUTEX(name) \ | ||
72 | static void *__THREAD_NAME(name) | ||
73 | #define _THREAD_PRIVATE_MUTEX_LOCK(name) \ | ||
74 | _thread_tag_lock(&(__THREAD_NAME(name))) | ||
75 | #define _THREAD_PRIVATE_MUTEX_UNLOCK(name) \ | ||
76 | _thread_tag_unlock(&(__THREAD_NAME(name))) | ||
77 | #define _THREAD_PRIVATE(keyname, storage, error) \ | ||
78 | _thread_tag_storage(&(__THREAD_NAME(keyname)), &(storage), \ | ||
79 | sizeof (storage), error) | ||
80 | /* | ||
81 | * Resolver code is special cased in that it uses global keys. | ||
82 | */ | ||
83 | extern void *__THREAD_NAME(_res); | ||
84 | extern void *__THREAD_NAME(_res_ext); | ||
85 | extern void *__THREAD_NAME(serv_mutex); | ||
86 | |||
87 | /* | ||
88 | * File descriptor locking definitions. | ||
89 | */ | ||
90 | #define FD_READ 0x1 | ||
91 | #define FD_WRITE 0x2 | ||
92 | #define FD_RDWR (FD_READ | FD_WRITE) | ||
93 | |||
94 | struct timespec; | ||
95 | int _thread_fd_lock(int, int, struct timespec *); | ||
96 | void _thread_fd_unlock(int, int); | ||
97 | |||
98 | /* | ||
99 | * Macros are used in libc code for historical (debug) reasons. | ||
100 | * Define them here. | ||
101 | */ | ||
102 | #define _FD_LOCK(_fd,_type,_ts) _thread_fd_lock(_fd, _type, _ts) | ||
103 | #define _FD_UNLOCK(_fd,_type) _thread_fd_unlock(_fd, _type) | ||
104 | |||
105 | |||
106 | /* | ||
107 | * malloc lock/unlock prototypes and definitions | ||
108 | */ | ||
109 | void _thread_malloc_init(void); | ||
110 | void _thread_malloc_lock(void); | ||
111 | void _thread_malloc_unlock(void); | ||
112 | |||
113 | #define _MALLOC_LOCK() do { \ | ||
114 | if (__isthreaded) \ | ||
115 | _thread_malloc_lock(); \ | ||
116 | } while (0) | ||
117 | #define _MALLOC_UNLOCK() do { \ | ||
118 | if (__isthreaded) \ | ||
119 | _thread_malloc_unlock();\ | ||
120 | } while (0) | ||
121 | #define _MALLOC_LOCK_INIT() do { \ | ||
122 | if (__isthreaded) \ | ||
123 | _thread_malloc_init();\ | ||
124 | } while (0) | ||
125 | |||
126 | void _thread_atexit_lock(void); | ||
127 | void _thread_atexit_unlock(void); | ||
128 | |||
129 | #define _ATEXIT_LOCK() do { \ | ||
130 | if (__isthreaded) \ | ||
131 | _thread_atexit_lock(); \ | ||
132 | } while (0) | ||
133 | #define _ATEXIT_UNLOCK() do { \ | ||
134 | if (__isthreaded) \ | ||
135 | _thread_atexit_unlock();\ | ||
136 | } while (0) | ||
137 | |||
138 | #endif /* _THREAD_PRIVATE_H_ */ | ||