Mercurial > trustbridge > nss-cmake-static
comparison nspr/pr/include/md/_pth.h @ 0:1e5118fa0cb1
This is NSS with a Cmake Buildsyste
To compile a static NSS library for Windows we've used the
Chromium-NSS fork and added a Cmake buildsystem to compile
it statically for Windows. See README.chromium for chromium
changes and README.trustbridge for our modifications.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 28 Jul 2014 10:47:06 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1e5118fa0cb1 |
---|---|
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | |
2 /* This Source Code Form is subject to the terms of the Mozilla Public | |
3 * License, v. 2.0. If a copy of the MPL was not distributed with this | |
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | |
5 | |
6 #ifndef nspr_pth_defs_h_ | |
7 #define nspr_pth_defs_h_ | |
8 | |
9 /* | |
10 ** Appropriate definitions of entry points not used in a pthreads world | |
11 */ | |
12 #define _PR_MD_BLOCK_CLOCK_INTERRUPTS() | |
13 #define _PR_MD_UNBLOCK_CLOCK_INTERRUPTS() | |
14 #define _PR_MD_DISABLE_CLOCK_INTERRUPTS() | |
15 #define _PR_MD_ENABLE_CLOCK_INTERRUPTS() | |
16 | |
17 /* In good standards fashion, the DCE threads (based on posix-4) are not | |
18 * quite the same as newer posix implementations. These are mostly name | |
19 * changes and small differences, so macros usually do the trick | |
20 */ | |
21 #ifdef _PR_DCETHREADS | |
22 #define _PT_PTHREAD_MUTEXATTR_INIT pthread_mutexattr_create | |
23 #define _PT_PTHREAD_MUTEXATTR_DESTROY pthread_mutexattr_delete | |
24 #define _PT_PTHREAD_MUTEX_INIT(m, a) pthread_mutex_init(&(m), a) | |
25 #define _PT_PTHREAD_MUTEX_IS_LOCKED(m) (0 == pthread_mutex_trylock(&(m))) | |
26 #define _PT_PTHREAD_CONDATTR_INIT pthread_condattr_create | |
27 #define _PT_PTHREAD_COND_INIT(m, a) pthread_cond_init(&(m), a) | |
28 #define _PT_PTHREAD_CONDATTR_DESTROY pthread_condattr_delete | |
29 | |
30 /* Notes about differences between DCE threads and pthreads 10: | |
31 * 1. pthread_mutex_trylock returns 1 when it locks the mutex | |
32 * 0 when it does not. The latest pthreads has a set of errno-like | |
33 * return values. | |
34 * 2. return values from pthread_cond_timedwait are different. | |
35 * | |
36 * | |
37 * | |
38 */ | |
39 #elif defined(BSDI) | |
40 /* | |
41 * Mutex and condition attributes are not supported. The attr | |
42 * argument to pthread_mutex_init() and pthread_cond_init() must | |
43 * be passed as NULL. | |
44 * | |
45 * The memset calls in _PT_PTHREAD_MUTEX_INIT and _PT_PTHREAD_COND_INIT | |
46 * are to work around BSDI's using a single bit to indicate a mutex | |
47 * or condition variable is initialized. This entire BSDI section | |
48 * will go away when BSDI releases updated threads libraries for | |
49 * BSD/OS 3.1 and 4.0. | |
50 */ | |
51 #define _PT_PTHREAD_MUTEXATTR_INIT(x) 0 | |
52 #define _PT_PTHREAD_MUTEXATTR_DESTROY(x) /* */ | |
53 #define _PT_PTHREAD_MUTEX_INIT(m, a) (memset(&(m), 0, sizeof(m)), \ | |
54 pthread_mutex_init(&(m), NULL)) | |
55 #define _PT_PTHREAD_MUTEX_IS_LOCKED(m) (EBUSY == pthread_mutex_trylock(&(m))) | |
56 #define _PT_PTHREAD_CONDATTR_INIT(x) 0 | |
57 #define _PT_PTHREAD_CONDATTR_DESTROY(x) /* */ | |
58 #define _PT_PTHREAD_COND_INIT(m, a) (memset(&(m), 0, sizeof(m)), \ | |
59 pthread_cond_init(&(m), NULL)) | |
60 #else | |
61 #define _PT_PTHREAD_MUTEXATTR_INIT pthread_mutexattr_init | |
62 #define _PT_PTHREAD_MUTEXATTR_DESTROY pthread_mutexattr_destroy | |
63 #define _PT_PTHREAD_MUTEX_INIT(m, a) pthread_mutex_init(&(m), &(a)) | |
64 #if defined(FREEBSD) | |
65 #define _PT_PTHREAD_MUTEX_IS_LOCKED(m) pt_pthread_mutex_is_locked(&(m)) | |
66 #else | |
67 #define _PT_PTHREAD_MUTEX_IS_LOCKED(m) (EBUSY == pthread_mutex_trylock(&(m))) | |
68 #endif | |
69 #if defined(ANDROID) | |
70 /* Conditional attribute init and destroy aren't implemented in bionic. */ | |
71 #define _PT_PTHREAD_CONDATTR_INIT(x) 0 | |
72 #define _PT_PTHREAD_CONDATTR_DESTROY(x) /* */ | |
73 #else | |
74 #define _PT_PTHREAD_CONDATTR_INIT pthread_condattr_init | |
75 #define _PT_PTHREAD_CONDATTR_DESTROY pthread_condattr_destroy | |
76 #endif | |
77 #define _PT_PTHREAD_COND_INIT(m, a) pthread_cond_init(&(m), &(a)) | |
78 #endif | |
79 | |
80 /* The pthreads standard does not specify an invalid value for the | |
81 * pthread_t handle. (0 is usually an invalid pthread identifier | |
82 * but there are exceptions, for example, DG/UX.) These macros | |
83 * define a way to set the handle to or compare the handle with an | |
84 * invalid identifier. These macros are not portable and may be | |
85 * more of a problem as we adapt to more pthreads implementations. | |
86 * They are only used in the PRMonitor functions. Do not use them | |
87 * in new code. | |
88 * | |
89 * Unfortunately some of our clients depend on certain properties | |
90 * of our PRMonitor implementation, preventing us from replacing | |
91 * it by a portable implementation. | |
92 * - High-performance servers like the fact that PR_EnterMonitor | |
93 * only calls PR_Lock and PR_ExitMonitor only calls PR_Unlock. | |
94 * (A portable implementation would use a PRLock and a PRCondVar | |
95 * to implement the recursive lock in a monitor and call both | |
96 * PR_Lock and PR_Unlock in PR_EnterMonitor and PR_ExitMonitor.) | |
97 * Unfortunately this forces us to read the monitor owner field | |
98 * without holding a lock. | |
99 * - One way to make it safe to read the monitor owner field | |
100 * without holding a lock is to make that field a PRThread* | |
101 * (one should be able to read a pointer with a single machine | |
102 * instruction). However, PR_GetCurrentThread calls calloc if | |
103 * it is called by a thread that was not created by NSPR. The | |
104 * malloc tracing tools in the Mozilla client use PRMonitor for | |
105 * locking in their malloc, calloc, and free functions. If | |
106 * PR_EnterMonitor calls any of these functions, infinite | |
107 * recursion ensues. | |
108 */ | |
109 #if defined(_PR_DCETHREADS) | |
110 #define _PT_PTHREAD_INVALIDATE_THR_HANDLE(t) \ | |
111 memset(&(t), 0, sizeof(pthread_t)) | |
112 #define _PT_PTHREAD_THR_HANDLE_IS_INVALID(t) \ | |
113 (!memcmp(&(t), &pt_zero_tid, sizeof(pthread_t))) | |
114 #define _PT_PTHREAD_COPY_THR_HANDLE(st, dt) (dt) = (st) | |
115 #elif defined(IRIX) || defined(OSF1) || defined(AIX) || defined(SOLARIS) \ | |
116 || defined(LINUX) || defined(__GNU__) || defined(__GLIBC__) \ | |
117 || defined(HPUX) || defined(FREEBSD) \ | |
118 || defined(NETBSD) || defined(OPENBSD) || defined(BSDI) \ | |
119 || defined(NTO) || defined(DARWIN) \ | |
120 || defined(UNIXWARE) || defined(RISCOS) || defined(SYMBIAN) | |
121 #define _PT_PTHREAD_INVALIDATE_THR_HANDLE(t) (t) = 0 | |
122 #define _PT_PTHREAD_THR_HANDLE_IS_INVALID(t) (t) == 0 | |
123 #define _PT_PTHREAD_COPY_THR_HANDLE(st, dt) (dt) = (st) | |
124 #else | |
125 #error "pthreads is not supported for this architecture" | |
126 #endif | |
127 | |
128 #if defined(_PR_DCETHREADS) | |
129 #define _PT_PTHREAD_ATTR_INIT pthread_attr_create | |
130 #define _PT_PTHREAD_ATTR_DESTROY pthread_attr_delete | |
131 #define _PT_PTHREAD_CREATE(t, a, f, r) pthread_create(t, a, f, r) | |
132 #define _PT_PTHREAD_KEY_CREATE pthread_keycreate | |
133 #define _PT_PTHREAD_ATTR_SETSCHEDPOLICY pthread_attr_setsched | |
134 #define _PT_PTHREAD_ATTR_GETSTACKSIZE(a, s) \ | |
135 (*(s) = pthread_attr_getstacksize(*(a)), 0) | |
136 #define _PT_PTHREAD_GETSPECIFIC(k, r) \ | |
137 pthread_getspecific((k), (pthread_addr_t *) &(r)) | |
138 #elif defined(_PR_PTHREADS) | |
139 #define _PT_PTHREAD_ATTR_INIT pthread_attr_init | |
140 #define _PT_PTHREAD_ATTR_DESTROY pthread_attr_destroy | |
141 #define _PT_PTHREAD_CREATE(t, a, f, r) pthread_create(t, &a, f, r) | |
142 #define _PT_PTHREAD_KEY_CREATE pthread_key_create | |
143 #define _PT_PTHREAD_ATTR_SETSCHEDPOLICY pthread_attr_setschedpolicy | |
144 #define _PT_PTHREAD_ATTR_GETSTACKSIZE(a, s) pthread_attr_getstacksize(a, s) | |
145 #define _PT_PTHREAD_GETSPECIFIC(k, r) (r) = pthread_getspecific(k) | |
146 #else | |
147 #error "Cannot determine pthread strategy" | |
148 #endif | |
149 | |
150 #if defined(_PR_DCETHREADS) | |
151 #define _PT_PTHREAD_EXPLICIT_SCHED _PT_PTHREAD_DEFAULT_SCHED | |
152 #endif | |
153 | |
154 /* | |
155 * pthread_mutex_trylock returns different values in DCE threads and | |
156 * pthreads. | |
157 */ | |
158 #if defined(_PR_DCETHREADS) | |
159 #define PT_TRYLOCK_SUCCESS 1 | |
160 #define PT_TRYLOCK_BUSY 0 | |
161 #else | |
162 #define PT_TRYLOCK_SUCCESS 0 | |
163 #define PT_TRYLOCK_BUSY EBUSY | |
164 #endif | |
165 | |
166 /* | |
167 * These platforms don't have sigtimedwait() | |
168 */ | |
169 #if (defined(AIX) && !defined(AIX4_3_PLUS)) \ | |
170 || defined(LINUX) || defined(__GNU__)|| defined(__GLIBC__) \ | |
171 || defined(FREEBSD) || defined(NETBSD) || defined(OPENBSD) \ | |
172 || defined(BSDI) || defined(UNIXWARE) \ | |
173 || defined(DARWIN) || defined(SYMBIAN) | |
174 #define PT_NO_SIGTIMEDWAIT | |
175 #endif | |
176 | |
177 #if defined(OSF1) | |
178 #define PT_PRIO_MIN PRI_OTHER_MIN | |
179 #define PT_PRIO_MAX PRI_OTHER_MAX | |
180 #elif defined(IRIX) | |
181 #include <sys/sched.h> | |
182 #define PT_PRIO_MIN PX_PRIO_MIN | |
183 #define PT_PRIO_MAX PX_PRIO_MAX | |
184 #elif defined(AIX) | |
185 #include <sys/priv.h> | |
186 #include <sys/sched.h> | |
187 #ifndef PTHREAD_CREATE_JOINABLE | |
188 #define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED | |
189 #endif | |
190 #define PT_PRIO_MIN DEFAULT_PRIO | |
191 #define PT_PRIO_MAX DEFAULT_PRIO | |
192 #elif defined(HPUX) | |
193 | |
194 #if defined(_PR_DCETHREADS) | |
195 #define PT_PRIO_MIN PRI_OTHER_MIN | |
196 #define PT_PRIO_MAX PRI_OTHER_MAX | |
197 #else /* defined(_PR_DCETHREADS) */ | |
198 #include <sys/sched.h> | |
199 #define PT_PRIO_MIN sched_get_priority_min(SCHED_OTHER) | |
200 #define PT_PRIO_MAX sched_get_priority_max(SCHED_OTHER) | |
201 #endif /* defined(_PR_DCETHREADS) */ | |
202 | |
203 #elif defined(LINUX) || defined(__GNU__) || defined(__GLIBC__) \ | |
204 || defined(FREEBSD) || defined(SYMBIAN) | |
205 #define PT_PRIO_MIN sched_get_priority_min(SCHED_OTHER) | |
206 #define PT_PRIO_MAX sched_get_priority_max(SCHED_OTHER) | |
207 #elif defined(NTO) | |
208 /* | |
209 * Neutrino has functions that return the priority range but | |
210 * they return invalid numbers, so I just hard coded these here | |
211 * for now. Jerry.Kirk@Nexarecorp.com | |
212 */ | |
213 #define PT_PRIO_MIN 0 | |
214 #define PT_PRIO_MAX 30 | |
215 #elif defined(SOLARIS) | |
216 /* | |
217 * Solaris doesn't seem to have macros for the min/max priorities. | |
218 * The range of 0-127 is mentioned in the pthread_setschedparam(3T) | |
219 * man pages, and pthread_setschedparam indeed allows 0-127. However, | |
220 * pthread_attr_setschedparam does not allow 0; it allows 1-127. | |
221 */ | |
222 #define PT_PRIO_MIN 1 | |
223 #define PT_PRIO_MAX 127 | |
224 #elif defined(OPENBSD) | |
225 #define PT_PRIO_MIN 0 | |
226 #define PT_PRIO_MAX 31 | |
227 #elif defined(NETBSD) \ | |
228 || defined(BSDI) || defined(DARWIN) || defined(UNIXWARE) \ | |
229 || defined(RISCOS) /* XXX */ | |
230 #define PT_PRIO_MIN 0 | |
231 #define PT_PRIO_MAX 126 | |
232 #else | |
233 #error "pthreads is not supported for this architecture" | |
234 #endif | |
235 | |
236 /* | |
237 * The _PT_PTHREAD_YIELD function is called from a signal handler. | |
238 * Needed for garbage collection -- Look at PR_Suspend/PR_Resume | |
239 * implementation. | |
240 */ | |
241 #if defined(_PR_DCETHREADS) | |
242 #define _PT_PTHREAD_YIELD() pthread_yield() | |
243 #elif defined(OSF1) | |
244 /* | |
245 * sched_yield can't be called from a signal handler. Must use | |
246 * the _np version. | |
247 */ | |
248 #define _PT_PTHREAD_YIELD() pthread_yield_np() | |
249 #elif defined(AIX) | |
250 extern int (*_PT_aix_yield_fcn)(); | |
251 #define _PT_PTHREAD_YIELD() (*_PT_aix_yield_fcn)() | |
252 #elif defined(IRIX) | |
253 #include <time.h> | |
254 #define _PT_PTHREAD_YIELD() \ | |
255 PR_BEGIN_MACRO \ | |
256 struct timespec onemillisec = {0}; \ | |
257 onemillisec.tv_nsec = 1000000L; \ | |
258 nanosleep(&onemillisec,NULL); \ | |
259 PR_END_MACRO | |
260 #elif defined(HPUX) || defined(SOLARIS) \ | |
261 || defined(LINUX) || defined(__GNU__) || defined(__GLIBC__) \ | |
262 || defined(FREEBSD) || defined(NETBSD) || defined(OPENBSD) \ | |
263 || defined(BSDI) || defined(NTO) || defined(DARWIN) \ | |
264 || defined(UNIXWARE) || defined(RISCOS) || defined(SYMBIAN) | |
265 #define _PT_PTHREAD_YIELD() sched_yield() | |
266 #else | |
267 #error "Need to define _PT_PTHREAD_YIELD for this platform" | |
268 #endif | |
269 | |
270 #endif /* nspr_pth_defs_h_ */ |