|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * vim: set ts=8 sts=4 et sw=4 tw=99: |
|
3 * This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef vm_PosixNSPR_h |
|
8 #define vm_PosixNSPR_h |
|
9 |
|
10 #ifdef JS_POSIX_NSPR |
|
11 |
|
12 #ifndef JS_THREADSAFE |
|
13 #error "This file must not be included in non-threadsafe mode" |
|
14 #endif |
|
15 |
|
16 #include <pthread.h> |
|
17 #include <stdint.h> |
|
18 |
|
19 namespace nspr { |
|
20 class Thread; |
|
21 class Lock; |
|
22 class CondVar; |
|
23 }; |
|
24 |
|
25 typedef nspr::Thread PRThread; |
|
26 typedef nspr::Lock PRLock; |
|
27 typedef nspr::CondVar PRCondVar; |
|
28 |
|
29 enum PRThreadType { |
|
30 PR_USER_THREAD, |
|
31 PR_SYSTEM_THREAD |
|
32 }; |
|
33 |
|
34 enum PRThreadPriority |
|
35 { |
|
36 PR_PRIORITY_FIRST = 0, |
|
37 PR_PRIORITY_LOW = 0, |
|
38 PR_PRIORITY_NORMAL = 1, |
|
39 PR_PRIORITY_HIGH = 2, |
|
40 PR_PRIORITY_URGENT = 3, |
|
41 PR_PRIORITY_LAST = 3 |
|
42 }; |
|
43 |
|
44 enum PRThreadScope { |
|
45 PR_LOCAL_THREAD, |
|
46 PR_GLOBAL_THREAD, |
|
47 PR_GLOBAL_BOUND_THREAD |
|
48 }; |
|
49 |
|
50 enum PRThreadState { |
|
51 PR_JOINABLE_THREAD, |
|
52 PR_UNJOINABLE_THREAD |
|
53 }; |
|
54 |
|
55 PRThread * |
|
56 PR_CreateThread(PRThreadType type, |
|
57 void (*start)(void *arg), |
|
58 void *arg, |
|
59 PRThreadPriority priority, |
|
60 PRThreadScope scope, |
|
61 PRThreadState state, |
|
62 uint32_t stackSize); |
|
63 |
|
64 typedef enum { PR_FAILURE = -1, PR_SUCCESS = 0 } PRStatus; |
|
65 |
|
66 PRStatus |
|
67 PR_JoinThread(PRThread *thread); |
|
68 |
|
69 PRThread * |
|
70 PR_GetCurrentThread(); |
|
71 |
|
72 PRStatus |
|
73 PR_SetCurrentThreadName(const char *name); |
|
74 |
|
75 typedef void (*PRThreadPrivateDTOR)(void *priv); |
|
76 |
|
77 PRStatus |
|
78 PR_NewThreadPrivateIndex(unsigned *newIndex, PRThreadPrivateDTOR destructor); |
|
79 |
|
80 PRStatus |
|
81 PR_SetThreadPrivate(unsigned index, void *priv); |
|
82 |
|
83 void * |
|
84 PR_GetThreadPrivate(unsigned index); |
|
85 |
|
86 struct PRCallOnceType { |
|
87 int initialized; |
|
88 int32_t inProgress; |
|
89 PRStatus status; |
|
90 }; |
|
91 |
|
92 typedef PRStatus (*PRCallOnceFN)(); |
|
93 |
|
94 PRStatus |
|
95 PR_CallOnce(PRCallOnceType *once, PRCallOnceFN func); |
|
96 |
|
97 typedef PRStatus (*PRCallOnceWithArgFN)(void *); |
|
98 |
|
99 PRStatus |
|
100 PR_CallOnceWithArg(PRCallOnceType *once, PRCallOnceWithArgFN func, void *arg); |
|
101 |
|
102 PRLock * |
|
103 PR_NewLock(); |
|
104 |
|
105 void |
|
106 PR_DestroyLock(PRLock *lock); |
|
107 |
|
108 void |
|
109 PR_Lock(PRLock *lock); |
|
110 |
|
111 PRStatus |
|
112 PR_Unlock(PRLock *lock); |
|
113 |
|
114 PRCondVar * |
|
115 PR_NewCondVar(PRLock *lock); |
|
116 |
|
117 void |
|
118 PR_DestroyCondVar(PRCondVar *cvar); |
|
119 |
|
120 PRStatus |
|
121 PR_NotifyCondVar(PRCondVar *cvar); |
|
122 |
|
123 PRStatus |
|
124 PR_NotifyAllCondVar(PRCondVar *cvar); |
|
125 |
|
126 #define PR_INTERVAL_MIN 1000UL |
|
127 #define PR_INTERVAL_MAX 100000UL |
|
128 |
|
129 #define PR_INTERVAL_NO_WAIT 0UL |
|
130 #define PR_INTERVAL_NO_TIMEOUT 0xffffffffUL |
|
131 |
|
132 uint32_t |
|
133 PR_MillisecondsToInterval(uint32_t milli); |
|
134 |
|
135 uint32_t |
|
136 PR_TicksPerSecond(); |
|
137 |
|
138 PRStatus |
|
139 PR_WaitCondVar(PRCondVar *cvar, uint32_t timeout); |
|
140 |
|
141 #endif /* JS_POSIX_NSPR */ |
|
142 |
|
143 #endif /* vm_PosixNSPR_h */ |