VirtualBox

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

最後變更 在這個檔案從102215是 102215,由 vboxsync 提交於 16 月 前

libs/xpcom: Bury the NSPR thread code finally, there is no user left, bugref:10545

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 7.1 KB
 
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#define _PT_PTHREAD_MUTEXATTR_INIT pthread_mutexattr_init
50#define _PT_PTHREAD_MUTEXATTR_DESTROY pthread_mutexattr_destroy
51#define _PT_PTHREAD_MUTEX_INIT(m, a) pthread_mutex_init(&(m), &(a))
52#define _PT_PTHREAD_MUTEX_IS_LOCKED(m) (EBUSY == pthread_mutex_trylock(&(m)))
53#if defined(DARWIN)
54#define _PT_PTHREAD_CONDATTR_INIT(x) 0
55#else
56#define _PT_PTHREAD_CONDATTR_INIT pthread_condattr_init
57#endif
58#define _PT_PTHREAD_CONDATTR_DESTROY pthread_condattr_destroy
59#define _PT_PTHREAD_COND_INIT(m, a) pthread_cond_init(&(m), &(a))
60
61/* The pthreads standard does not specify an invalid value for the
62 * pthread_t handle. (0 is usually an invalid pthread identifier
63 * but there are exceptions, for example, DG/UX.) These macros
64 * define a way to set the handle to or compare the handle with an
65 * invalid identifier. These macros are not portable and may be
66 * more of a problem as we adapt to more pthreads implementations.
67 * They are only used in the PRMonitor functions. Do not use them
68 * in new code.
69 *
70 * Unfortunately some of our clients depend on certain properties
71 * of our PRMonitor implementation, preventing us from replacing
72 * it by a portable implementation.
73 * - High-performance servers like the fact that PR_EnterMonitor
74 * only calls PR_Lock and PR_ExitMonitor only calls PR_Unlock.
75 * (A portable implementation would use a PRLock and a PRCondVar
76 * to implement the recursive lock in a monitor and call both
77 * PR_Lock and PR_Unlock in PR_EnterMonitor and PR_ExitMonitor.)
78 * Unfortunately this forces us to read the monitor owner field
79 * without holding a lock.
80 * - One way to make it safe to read the monitor owner field
81 * without holding a lock is to make that field a PRThread*
82 * (one should be able to read a pointer with a single machine
83 * instruction). However, PR_GetCurrentThread calls calloc if
84 * it is called by a thread that was not created by NSPR. The
85 * malloc tracing tools in the Mozilla client use PRMonitor for
86 * locking in their malloc, calloc, and free functions. If
87 * PR_EnterMonitor calls any of these functions, infinite
88 * recursion ensues.
89 */
90#if defined(IRIX) || defined(OSF1) || defined(AIX) || defined(SOLARIS) \
91 || defined(HPUX) || defined(LINUX) || defined(FREEBSD) \
92 || defined(NETBSD) || defined(OPENBSD) || defined(BSDI) \
93 || defined(VMS) || defined(NTO) || defined(DARWIN) \
94 || defined(UNIXWARE)
95#define _PT_PTHREAD_INVALIDATE_THR_HANDLE(t) (t) = 0
96#define _PT_PTHREAD_THR_HANDLE_IS_INVALID(t) (t) == 0
97#define _PT_PTHREAD_COPY_THR_HANDLE(st, dt) (dt) = (st)
98#else
99#error "pthreads is not supported for this architecture"
100#endif
101
102#if defined(_PR_PTHREADS)
103#define _PT_PTHREAD_ATTR_INIT pthread_attr_init
104#define _PT_PTHREAD_ATTR_DESTROY pthread_attr_destroy
105#define _PT_PTHREAD_CREATE(t, a, f, r) pthread_create(t, &a, f, r)
106#define _PT_PTHREAD_KEY_CREATE pthread_key_create
107#define _PT_PTHREAD_ATTR_SETSCHEDPOLICY pthread_attr_setschedpolicy
108#define _PT_PTHREAD_ATTR_GETSTACKSIZE(a, s) pthread_attr_getstacksize(a, s)
109#define _PT_PTHREAD_GETSPECIFIC(k, r) (r) = pthread_getspecific(k)
110#else
111#error "Cannot determine pthread strategy"
112#endif
113
114#define PT_TRYLOCK_SUCCESS 0
115#define PT_TRYLOCK_BUSY EBUSY
116
117/*
118 * These platforms don't have sigtimedwait()
119 */
120#if (defined(AIX) && !defined(AIX4_3_PLUS)) || defined(LINUX) \
121 || defined(FREEBSD) || defined(NETBSD) || defined(OPENBSD) \
122 || defined(BSDI) || defined(VMS) || defined(UNIXWARE) \
123 || defined(DARWIN)
124#define PT_NO_SIGTIMEDWAIT
125#endif
126
127/*
128 * These platforms don't have pthread_kill()
129 */
130#if defined(DARWIN) && !defined(_DARWIN_FEATURE_UNIX_CONFORMANCE)
131#define pthread_kill(thread, sig) ENOSYS
132#endif
133
134#if defined(LINUX) || defined(FREEBSD)
135#define PT_PRIO_MIN sched_get_priority_min(SCHED_OTHER)
136#define PT_PRIO_MAX sched_get_priority_max(SCHED_OTHER)
137#elif defined(SOLARIS)
138/*
139 * Solaris doesn't seem to have macros for the min/max priorities.
140 * The range of 0-127 is mentioned in the pthread_setschedparam(3T)
141 * man pages, and pthread_setschedparam indeed allows 0-127. However,
142 * pthread_attr_setschedparam does not allow 0; it allows 1-127.
143 */
144#define PT_PRIO_MIN 1
145#define PT_PRIO_MAX 127
146#elif defined(OPENBSD)
147#define PT_PRIO_MIN 0
148#define PT_PRIO_MAX 31
149#elif defined(NETBSD) \
150 || defined(BSDI) || defined(DARWIN) || defined(UNIXWARE) /* XXX */
151#define PT_PRIO_MIN 0
152#define PT_PRIO_MAX 126
153#else
154#error "pthreads is not supported for this architecture"
155#endif
156
157/*
158 * The _PT_PTHREAD_YIELD function is called from a signal handler.
159 * Needed for garbage collection -- Look at PR_Suspend/PR_Resume
160 * implementation.
161 */
162#if defined(HPUX) || defined(LINUX) || defined(SOLARIS) \
163 || defined(FREEBSD) || defined(NETBSD) || defined(OPENBSD) \
164 || defined(BSDI) || defined(NTO) || defined(DARWIN) \
165 || defined(UNIXWARE)
166#define _PT_PTHREAD_YIELD() sched_yield()
167#else
168#error "Need to define _PT_PTHREAD_YIELD for this platform"
169#endif
170
171#endif /* nspr_pth_defs_h_ */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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