VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/pr/include/md/_pth.h@ 5300

Last change on this file since 5300 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.8 KB
Line 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is the Netscape Portable Runtime (NSPR).
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38#ifndef nspr_pth_defs_h_
39#define nspr_pth_defs_h_
40
41/*
42** Appropriate definitions of entry points not used in a pthreads world
43*/
44#define _PR_MD_BLOCK_CLOCK_INTERRUPTS()
45#define _PR_MD_UNBLOCK_CLOCK_INTERRUPTS()
46#define _PR_MD_DISABLE_CLOCK_INTERRUPTS()
47#define _PR_MD_ENABLE_CLOCK_INTERRUPTS()
48
49/* In good standards fashion, the DCE threads (based on posix-4) are not
50 * quite the same as newer posix implementations. These are mostly name
51 * changes and small differences, so macros usually do the trick
52 */
53#ifdef _PR_DCETHREADS
54#define _PT_PTHREAD_MUTEXATTR_INIT pthread_mutexattr_create
55#define _PT_PTHREAD_MUTEXATTR_DESTROY pthread_mutexattr_delete
56#define _PT_PTHREAD_MUTEX_INIT(m, a) pthread_mutex_init(&(m), a)
57#define _PT_PTHREAD_MUTEX_IS_LOCKED(m) (0 == pthread_mutex_trylock(&(m)))
58#define _PT_PTHREAD_CONDATTR_INIT pthread_condattr_create
59#define _PT_PTHREAD_COND_INIT(m, a) pthread_cond_init(&(m), a)
60#define _PT_PTHREAD_CONDATTR_DESTROY pthread_condattr_delete
61
62/* Notes about differences between DCE threads and pthreads 10:
63 * 1. pthread_mutex_trylock returns 1 when it locks the mutex
64 * 0 when it does not. The latest pthreads has a set of errno-like
65 * return values.
66 * 2. return values from pthread_cond_timedwait are different.
67 *
68 *
69 *
70 */
71#elif defined(BSDI)
72/*
73 * Mutex and condition attributes are not supported. The attr
74 * argument to pthread_mutex_init() and pthread_cond_init() must
75 * be passed as NULL.
76 *
77 * The memset calls in _PT_PTHREAD_MUTEX_INIT and _PT_PTHREAD_COND_INIT
78 * are to work around BSDI's using a single bit to indicate a mutex
79 * or condition variable is initialized. This entire BSDI section
80 * will go away when BSDI releases updated threads libraries for
81 * BSD/OS 3.1 and 4.0.
82 */
83#define _PT_PTHREAD_MUTEXATTR_INIT(x) 0
84#define _PT_PTHREAD_MUTEXATTR_DESTROY(x) /* */
85#define _PT_PTHREAD_MUTEX_INIT(m, a) (memset(&(m), 0, sizeof(m)), \
86 pthread_mutex_init(&(m), NULL))
87#define _PT_PTHREAD_MUTEX_IS_LOCKED(m) (EBUSY == pthread_mutex_trylock(&(m)))
88#define _PT_PTHREAD_CONDATTR_INIT(x) 0
89#define _PT_PTHREAD_CONDATTR_DESTROY(x) /* */
90#define _PT_PTHREAD_COND_INIT(m, a) (memset(&(m), 0, sizeof(m)), \
91 pthread_cond_init(&(m), NULL))
92#else
93#define _PT_PTHREAD_MUTEXATTR_INIT pthread_mutexattr_init
94#define _PT_PTHREAD_MUTEXATTR_DESTROY pthread_mutexattr_destroy
95#define _PT_PTHREAD_MUTEX_INIT(m, a) pthread_mutex_init(&(m), &(a))
96#define _PT_PTHREAD_MUTEX_IS_LOCKED(m) (EBUSY == pthread_mutex_trylock(&(m)))
97#if defined(DARWIN)
98#define _PT_PTHREAD_CONDATTR_INIT(x) 0
99#else
100#define _PT_PTHREAD_CONDATTR_INIT pthread_condattr_init
101#endif
102#define _PT_PTHREAD_CONDATTR_DESTROY pthread_condattr_destroy
103#define _PT_PTHREAD_COND_INIT(m, a) pthread_cond_init(&(m), &(a))
104#endif
105
106/* The pthreads standard does not specify an invalid value for the
107 * pthread_t handle. (0 is usually an invalid pthread identifier
108 * but there are exceptions, for example, DG/UX.) These macros
109 * define a way to set the handle to or compare the handle with an
110 * invalid identifier. These macros are not portable and may be
111 * more of a problem as we adapt to more pthreads implementations.
112 * They are only used in the PRMonitor functions. Do not use them
113 * in new code.
114 *
115 * Unfortunately some of our clients depend on certain properties
116 * of our PRMonitor implementation, preventing us from replacing
117 * it by a portable implementation.
118 * - High-performance servers like the fact that PR_EnterMonitor
119 * only calls PR_Lock and PR_ExitMonitor only calls PR_Unlock.
120 * (A portable implementation would use a PRLock and a PRCondVar
121 * to implement the recursive lock in a monitor and call both
122 * PR_Lock and PR_Unlock in PR_EnterMonitor and PR_ExitMonitor.)
123 * Unfortunately this forces us to read the monitor owner field
124 * without holding a lock.
125 * - One way to make it safe to read the monitor owner field
126 * without holding a lock is to make that field a PRThread*
127 * (one should be able to read a pointer with a single machine
128 * instruction). However, PR_GetCurrentThread calls calloc if
129 * it is called by a thread that was not created by NSPR. The
130 * malloc tracing tools in the Mozilla client use PRMonitor for
131 * locking in their malloc, calloc, and free functions. If
132 * PR_EnterMonitor calls any of these functions, infinite
133 * recursion ensues.
134 */
135#if defined(_PR_DCETHREADS)
136#define _PT_PTHREAD_INVALIDATE_THR_HANDLE(t) \
137 memset(&(t), 0, sizeof(pthread_t))
138#define _PT_PTHREAD_THR_HANDLE_IS_INVALID(t) \
139 (!memcmp(&(t), &pt_zero_tid, sizeof(pthread_t)))
140#define _PT_PTHREAD_COPY_THR_HANDLE(st, dt) (dt) = (st)
141#elif defined(IRIX) || defined(OSF1) || defined(AIX) || defined(SOLARIS) \
142 || defined(HPUX) || defined(LINUX) || defined(FREEBSD) \
143 || defined(NETBSD) || defined(OPENBSD) || defined(BSDI) \
144 || defined(VMS) || defined(NTO) || defined(DARWIN) \
145 || defined(UNIXWARE)
146#define _PT_PTHREAD_INVALIDATE_THR_HANDLE(t) (t) = 0
147#define _PT_PTHREAD_THR_HANDLE_IS_INVALID(t) (t) == 0
148#define _PT_PTHREAD_COPY_THR_HANDLE(st, dt) (dt) = (st)
149#else
150#error "pthreads is not supported for this architecture"
151#endif
152
153#if defined(_PR_DCETHREADS)
154#define _PT_PTHREAD_ATTR_INIT pthread_attr_create
155#define _PT_PTHREAD_ATTR_DESTROY pthread_attr_delete
156#define _PT_PTHREAD_CREATE(t, a, f, r) pthread_create(t, a, f, r)
157#define _PT_PTHREAD_KEY_CREATE pthread_keycreate
158#define _PT_PTHREAD_ATTR_SETSCHEDPOLICY pthread_attr_setsched
159#define _PT_PTHREAD_ATTR_GETSTACKSIZE(a, s) \
160 (*(s) = pthread_attr_getstacksize(*(a)), 0)
161#define _PT_PTHREAD_GETSPECIFIC(k, r) \
162 pthread_getspecific((k), (pthread_addr_t *) &(r))
163#elif defined(_PR_PTHREADS)
164#define _PT_PTHREAD_ATTR_INIT pthread_attr_init
165#define _PT_PTHREAD_ATTR_DESTROY pthread_attr_destroy
166#define _PT_PTHREAD_CREATE(t, a, f, r) pthread_create(t, &a, f, r)
167#define _PT_PTHREAD_KEY_CREATE pthread_key_create
168#define _PT_PTHREAD_ATTR_SETSCHEDPOLICY pthread_attr_setschedpolicy
169#define _PT_PTHREAD_ATTR_GETSTACKSIZE(a, s) pthread_attr_getstacksize(a, s)
170#define _PT_PTHREAD_GETSPECIFIC(k, r) (r) = pthread_getspecific(k)
171#else
172#error "Cannot determine pthread strategy"
173#endif
174
175#if defined(_PR_DCETHREADS)
176#define _PT_PTHREAD_EXPLICIT_SCHED _PT_PTHREAD_DEFAULT_SCHED
177#endif
178
179/*
180 * pthread_mutex_trylock returns different values in DCE threads and
181 * pthreads.
182 */
183#if defined(_PR_DCETHREADS)
184#define PT_TRYLOCK_SUCCESS 1
185#define PT_TRYLOCK_BUSY 0
186#else
187#define PT_TRYLOCK_SUCCESS 0
188#define PT_TRYLOCK_BUSY EBUSY
189#endif
190
191/*
192 * These platforms don't have sigtimedwait()
193 */
194#if (defined(AIX) && !defined(AIX4_3_PLUS)) || defined(LINUX) \
195 || defined(FREEBSD) || defined(NETBSD) || defined(OPENBSD) \
196 || defined(BSDI) || defined(VMS) || defined(UNIXWARE) \
197 || defined(DARWIN)
198#define PT_NO_SIGTIMEDWAIT
199#endif
200
201/*
202 * These platforms don't have pthread_kill()
203 */
204#if defined(DARWIN)
205#define pthread_kill(thread, sig) ENOSYS
206#endif
207
208#if defined(OSF1) || defined(VMS)
209#define PT_PRIO_MIN PRI_OTHER_MIN
210#define PT_PRIO_MAX PRI_OTHER_MAX
211#elif defined(IRIX)
212#include <sys/sched.h>
213#define PT_PRIO_MIN PX_PRIO_MIN
214#define PT_PRIO_MAX PX_PRIO_MAX
215#elif defined(AIX)
216#include <sys/priv.h>
217#include <sys/sched.h>
218#ifndef PTHREAD_CREATE_JOINABLE
219#define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED
220#endif
221#define PT_PRIO_MIN DEFAULT_PRIO
222#define PT_PRIO_MAX DEFAULT_PRIO
223#elif defined(HPUX)
224
225#if defined(_PR_DCETHREADS)
226#define PT_PRIO_MIN PRI_OTHER_MIN
227#define PT_PRIO_MAX PRI_OTHER_MAX
228#else /* defined(_PR_DCETHREADS) */
229#include <sys/sched.h>
230#define PT_PRIO_MIN sched_get_priority_min(SCHED_OTHER)
231#define PT_PRIO_MAX sched_get_priority_max(SCHED_OTHER)
232#endif /* defined(_PR_DCETHREADS) */
233
234#elif defined(LINUX) || defined(FREEBSD)
235#define PT_PRIO_MIN sched_get_priority_min(SCHED_OTHER)
236#define PT_PRIO_MAX sched_get_priority_max(SCHED_OTHER)
237#elif defined(NTO)
238/*
239 * Neutrino has functions that return the priority range but
240 * they return invalid numbers, so I just hard coded these here
241 * for now. [email protected]
242 */
243#define PT_PRIO_MIN 0
244#define PT_PRIO_MAX 30
245#elif defined(SOLARIS)
246/*
247 * Solaris doesn't seem to have macros for the min/max priorities.
248 * The range of 0-127 is mentioned in the pthread_setschedparam(3T)
249 * man pages, and pthread_setschedparam indeed allows 0-127. However,
250 * pthread_attr_setschedparam does not allow 0; it allows 1-127.
251 */
252#define PT_PRIO_MIN 1
253#define PT_PRIO_MAX 127
254#elif defined(OPENBSD)
255#define PT_PRIO_MIN 0
256#define PT_PRIO_MAX 31
257#elif defined(NETBSD) \
258 || defined(BSDI) || defined(DARWIN) || defined(UNIXWARE) /* XXX */
259#define PT_PRIO_MIN 0
260#define PT_PRIO_MAX 126
261#else
262#error "pthreads is not supported for this architecture"
263#endif
264
265/*
266 * The _PT_PTHREAD_YIELD function is called from a signal handler.
267 * Needed for garbage collection -- Look at PR_Suspend/PR_Resume
268 * implementation.
269 */
270#if defined(_PR_DCETHREADS)
271#define _PT_PTHREAD_YIELD() pthread_yield()
272#elif defined(OSF1) || defined(VMS)
273/*
274 * sched_yield can't be called from a signal handler. Must use
275 * the _np version.
276 */
277#define _PT_PTHREAD_YIELD() pthread_yield_np()
278#elif defined(AIX)
279extern int (*_PT_aix_yield_fcn)();
280#define _PT_PTHREAD_YIELD() (*_PT_aix_yield_fcn)()
281#elif defined(IRIX)
282#include <time.h>
283#define _PT_PTHREAD_YIELD() \
284 PR_BEGIN_MACRO \
285 struct timespec onemillisec = {0}; \
286 onemillisec.tv_nsec = 1000000L; \
287 nanosleep(&onemillisec,NULL); \
288 PR_END_MACRO
289#elif defined(HPUX) || defined(LINUX) || defined(SOLARIS) \
290 || defined(FREEBSD) || defined(NETBSD) || defined(OPENBSD) \
291 || defined(BSDI) || defined(NTO) || defined(DARWIN) \
292 || defined(UNIXWARE)
293#define _PT_PTHREAD_YIELD() sched_yield()
294#else
295#error "Need to define _PT_PTHREAD_YIELD for this platform"
296#endif
297
298#endif /* nspr_pth_defs_h_ */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette