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