Bug 449533. Set the mFixedPitch flag within SetFixedPitch. r+sr=vlad
[wine-gecko.git] / nsprpub / pr / include / md / _nspr_pthread.h
blobb7a0481ee524da113b734d223924b393a306fccf
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
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/
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.
15 * The Original Code is the Netscape Portable Runtime (NSPR).
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.
22 * Contributor(s):
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.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nspr_pthread_defs_h___
39 #define nspr_pthread_defs_h___
41 #include <pthread.h>
42 #include "prthread.h"
44 #if defined(PTHREADS_USER)
46 ** Thread Local Storage
48 extern pthread_key_t current_thread_key;
49 extern pthread_key_t current_cpu_key;
50 extern pthread_key_t last_thread_key;
51 extern pthread_key_t intsoff_key;
53 #define _MD_CURRENT_THREAD() \
54 ((struct PRThread *) pthread_getspecific(current_thread_key))
55 #define _MD_CURRENT_CPU() \
56 ((struct _PRCPU *) pthread_getspecific(current_cpu_key))
57 #define _MD_LAST_THREAD() \
58 ((struct PRThread *) pthread_getspecific(last_thread_key))
60 #define _MD_SET_CURRENT_THREAD(newval) \
61 pthread_setspecific(current_thread_key, (void *)newval)
63 #define _MD_SET_CURRENT_CPU(newval) \
64 pthread_setspecific(current_cpu_key, (void *)newval)
66 #define _MD_SET_LAST_THREAD(newval) \
67 pthread_setspecific(last_thread_key, (void *)newval)
69 #define _MD_SET_INTSOFF(_val)
70 #define _MD_GET_INTSOFF() 1
73 ** Initialize the thread context preparing it to execute _main.
75 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
76 PR_BEGIN_MACRO \
77 *status = PR_TRUE; \
78 if (SAVE_CONTEXT(_thread)) { \
79 (*_main)(); \
80 } \
81 _MD_SET_THR_SP(_thread, _sp); \
82 _thread->no_sched = 0; \
83 PR_END_MACRO
85 #define _MD_SWITCH_CONTEXT(_thread) \
86 PR_BEGIN_MACRO \
87 PR_ASSERT(_thread->no_sched); \
88 if (!SAVE_CONTEXT(_thread)) { \
89 (_thread)->md.errcode = errno; \
90 _MD_SET_LAST_THREAD(_thread); \
91 _PR_Schedule(); \
92 } else { \
93 (_MD_LAST_THREAD())->no_sched = 0; \
94 } \
95 PR_END_MACRO
98 ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
100 #define _MD_RESTORE_CONTEXT(_thread) \
101 PR_BEGIN_MACRO \
102 errno = (_thread)->md.errcode; \
103 _MD_SET_CURRENT_THREAD(_thread); \
104 _thread->no_sched = 1; \
105 GOTO_CONTEXT(_thread); \
106 PR_END_MACRO
109 /* Machine-dependent (MD) data structures */
111 struct _MDThread {
112 jmp_buf jb;
113 int id;
114 int errcode;
115 pthread_t pthread;
116 pthread_mutex_t pthread_mutex;
117 pthread_cond_t pthread_cond;
118 int wait;
121 struct _MDThreadStack {
122 PRInt8 notused;
125 struct _MDLock {
126 pthread_mutex_t mutex;
129 struct _MDSemaphore {
130 PRInt8 notused;
133 struct _MDCVar {
134 pthread_mutex_t mutex;
137 struct _MDSegment {
138 PRInt8 notused;
142 * md-specific cpu structure field
144 #define _PR_MD_MAX_OSFD FD_SETSIZE
146 struct _MDCPU_Unix {
147 PRCList ioQ;
148 PRUint32 ioq_timeout;
149 PRInt32 ioq_max_osfd;
150 PRInt32 ioq_osfd_cnt;
151 #ifndef _PR_USE_POLL
152 fd_set fd_read_set, fd_write_set, fd_exception_set;
153 PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
154 fd_exception_cnt[_PR_MD_MAX_OSFD];
155 #else
156 struct pollfd *ioq_pollfds;
157 int ioq_pollfds_size;
158 #endif /* _PR_USE_POLL */
161 #define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
162 #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
163 #define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
164 #define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
165 #define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
166 #define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
167 #define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
168 #define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
169 #define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
170 #define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
171 #define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
172 #define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
173 #define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
175 #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
177 struct _MDCPU {
178 jmp_buf jb;
179 pthread_t pthread;
180 struct _MDCPU_Unix md_unix;
184 #define _MD_NEW_LOCK(lock) PR_SUCCESS
185 #define _MD_FREE_LOCK(lock)
186 #define _MD_LOCK(lock)
187 #define _MD_UNLOCK(lock)
190 extern pthread_mutex_t _pr_heapLock;
192 #define _PR_LOCK(lock) pthread_mutex_lock(lock)
194 #define _PR_UNLOCK(lock) pthread_mutex_unlock(lock)
197 #define _PR_LOCK_HEAP() { \
198 if (_pr_primordialCPU) { \
199 _PR_LOCK(_pr_heapLock); \
202 #define _PR_UNLOCK_HEAP() if (_pr_primordialCPU) { \
203 _PR_UNLOCK(_pr_heapLock); \
207 NSPR_API(PRStatus) _MD_NEW_LOCK(struct _MDLock *md);
208 NSPR_API(void) _MD_FREE_LOCK(struct _MDLock *lockp);
210 #define _MD_LOCK(_lockp) _PR_LOCK(&(_lockp)->mutex)
211 #define _MD_UNLOCK(_lockp) _PR_UNLOCK(&(_lockp)->mutex)
213 #define _MD_INIT_IO()
214 #define _MD_IOQ_LOCK()
215 #define _MD_IOQ_UNLOCK()
216 #define _MD_CHECK_FOR_EXIT()
218 NSPR_API(PRStatus) _MD_InitThread(struct PRThread *thread);
219 #define _MD_INIT_THREAD _MD_InitThread
220 #define _MD_INIT_ATTACHED_THREAD _MD_InitThread
222 NSPR_API(void) _MD_ExitThread(struct PRThread *thread);
223 #define _MD_EXIT_THREAD _MD_ExitThread
225 NSPR_API(void) _MD_SuspendThread(struct PRThread *thread);
226 #define _MD_SUSPEND_THREAD _MD_SuspendThread
228 NSPR_API(void) _MD_ResumeThread(struct PRThread *thread);
229 #define _MD_RESUME_THREAD _MD_ResumeThread
231 NSPR_API(void) _MD_SuspendCPU(struct _PRCPU *thread);
232 #define _MD_SUSPEND_CPU _MD_SuspendCPU
234 NSPR_API(void) _MD_ResumeCPU(struct _PRCPU *thread);
235 #define _MD_RESUME_CPU _MD_ResumeCPU
237 #define _MD_BEGIN_SUSPEND_ALL()
238 #define _MD_END_SUSPEND_ALL()
239 #define _MD_BEGIN_RESUME_ALL()
240 #define _MD_END_RESUME_ALL()
242 NSPR_API(void) _MD_EarlyInit(void);
243 #define _MD_EARLY_INIT _MD_EarlyInit
245 #define _MD_FINAL_INIT _PR_UnixInit
247 NSPR_API(void) _MD_InitLocks(void);
248 #define _MD_INIT_LOCKS _MD_InitLocks
250 NSPR_API(void) _MD_CleanThread(struct PRThread *thread);
251 #define _MD_CLEAN_THREAD _MD_CleanThread
253 NSPR_API(PRStatus) _MD_CreateThread(
254 struct PRThread *thread,
255 void (*start) (void *),
256 PRThreadPriority priority,
257 PRThreadScope scope,
258 PRThreadState state,
259 PRUint32 stackSize);
260 #define _MD_CREATE_THREAD _MD_CreateThread
262 extern void _MD_CleanupBeforeExit(void);
263 #define _MD_CLEANUP_BEFORE_EXIT _MD_CleanupBeforeExit
265 NSPR_API(void) _MD_InitRunningCPU(struct _PRCPU *cpu);
266 #define _MD_INIT_RUNNING_CPU _MD_InitRunningCPU
268 /* The _PR_MD_WAIT_LOCK and _PR_MD_WAKEUP_WAITER functions put to sleep and
269 * awaken a thread which is waiting on a lock or cvar.
271 NSPR_API(PRStatus) _MD_wait(struct PRThread *, PRIntervalTime timeout);
272 #define _MD_WAIT _MD_wait
274 NSPR_API(PRStatus) _MD_WakeupWaiter(struct PRThread *);
275 #define _MD_WAKEUP_WAITER _MD_WakeupWaiter
277 NSPR_API(void) _MD_SetPriority(struct _MDThread *thread,
278 PRThreadPriority newPri);
279 #define _MD_SET_PRIORITY _MD_SetPriority
281 #endif /* PTHREADS_USER */
283 #endif /* nspr_pthread_defs_h___ */