1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/vm/PosixNSPR.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,143 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99: 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef vm_PosixNSPR_h 1.11 +#define vm_PosixNSPR_h 1.12 + 1.13 +#ifdef JS_POSIX_NSPR 1.14 + 1.15 +#ifndef JS_THREADSAFE 1.16 +#error "This file must not be included in non-threadsafe mode" 1.17 +#endif 1.18 + 1.19 +#include <pthread.h> 1.20 +#include <stdint.h> 1.21 + 1.22 +namespace nspr { 1.23 +class Thread; 1.24 +class Lock; 1.25 +class CondVar; 1.26 +}; 1.27 + 1.28 +typedef nspr::Thread PRThread; 1.29 +typedef nspr::Lock PRLock; 1.30 +typedef nspr::CondVar PRCondVar; 1.31 + 1.32 +enum PRThreadType { 1.33 + PR_USER_THREAD, 1.34 + PR_SYSTEM_THREAD 1.35 +}; 1.36 + 1.37 +enum PRThreadPriority 1.38 +{ 1.39 + PR_PRIORITY_FIRST = 0, 1.40 + PR_PRIORITY_LOW = 0, 1.41 + PR_PRIORITY_NORMAL = 1, 1.42 + PR_PRIORITY_HIGH = 2, 1.43 + PR_PRIORITY_URGENT = 3, 1.44 + PR_PRIORITY_LAST = 3 1.45 +}; 1.46 + 1.47 +enum PRThreadScope { 1.48 + PR_LOCAL_THREAD, 1.49 + PR_GLOBAL_THREAD, 1.50 + PR_GLOBAL_BOUND_THREAD 1.51 +}; 1.52 + 1.53 +enum PRThreadState { 1.54 + PR_JOINABLE_THREAD, 1.55 + PR_UNJOINABLE_THREAD 1.56 +}; 1.57 + 1.58 +PRThread * 1.59 +PR_CreateThread(PRThreadType type, 1.60 + void (*start)(void *arg), 1.61 + void *arg, 1.62 + PRThreadPriority priority, 1.63 + PRThreadScope scope, 1.64 + PRThreadState state, 1.65 + uint32_t stackSize); 1.66 + 1.67 +typedef enum { PR_FAILURE = -1, PR_SUCCESS = 0 } PRStatus; 1.68 + 1.69 +PRStatus 1.70 +PR_JoinThread(PRThread *thread); 1.71 + 1.72 +PRThread * 1.73 +PR_GetCurrentThread(); 1.74 + 1.75 +PRStatus 1.76 +PR_SetCurrentThreadName(const char *name); 1.77 + 1.78 +typedef void (*PRThreadPrivateDTOR)(void *priv); 1.79 + 1.80 +PRStatus 1.81 +PR_NewThreadPrivateIndex(unsigned *newIndex, PRThreadPrivateDTOR destructor); 1.82 + 1.83 +PRStatus 1.84 +PR_SetThreadPrivate(unsigned index, void *priv); 1.85 + 1.86 +void * 1.87 +PR_GetThreadPrivate(unsigned index); 1.88 + 1.89 +struct PRCallOnceType { 1.90 + int initialized; 1.91 + int32_t inProgress; 1.92 + PRStatus status; 1.93 +}; 1.94 + 1.95 +typedef PRStatus (*PRCallOnceFN)(); 1.96 + 1.97 +PRStatus 1.98 +PR_CallOnce(PRCallOnceType *once, PRCallOnceFN func); 1.99 + 1.100 +typedef PRStatus (*PRCallOnceWithArgFN)(void *); 1.101 + 1.102 +PRStatus 1.103 +PR_CallOnceWithArg(PRCallOnceType *once, PRCallOnceWithArgFN func, void *arg); 1.104 + 1.105 +PRLock * 1.106 +PR_NewLock(); 1.107 + 1.108 +void 1.109 +PR_DestroyLock(PRLock *lock); 1.110 + 1.111 +void 1.112 +PR_Lock(PRLock *lock); 1.113 + 1.114 +PRStatus 1.115 +PR_Unlock(PRLock *lock); 1.116 + 1.117 +PRCondVar * 1.118 +PR_NewCondVar(PRLock *lock); 1.119 + 1.120 +void 1.121 +PR_DestroyCondVar(PRCondVar *cvar); 1.122 + 1.123 +PRStatus 1.124 +PR_NotifyCondVar(PRCondVar *cvar); 1.125 + 1.126 +PRStatus 1.127 +PR_NotifyAllCondVar(PRCondVar *cvar); 1.128 + 1.129 +#define PR_INTERVAL_MIN 1000UL 1.130 +#define PR_INTERVAL_MAX 100000UL 1.131 + 1.132 +#define PR_INTERVAL_NO_WAIT 0UL 1.133 +#define PR_INTERVAL_NO_TIMEOUT 0xffffffffUL 1.134 + 1.135 +uint32_t 1.136 +PR_MillisecondsToInterval(uint32_t milli); 1.137 + 1.138 +uint32_t 1.139 +PR_TicksPerSecond(); 1.140 + 1.141 +PRStatus 1.142 +PR_WaitCondVar(PRCondVar *cvar, uint32_t timeout); 1.143 + 1.144 +#endif /* JS_POSIX_NSPR */ 1.145 + 1.146 +#endif /* vm_PosixNSPR_h */