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: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "primpl.h" |
michael@0 | 7 | |
michael@0 | 8 | |
michael@0 | 9 | extern PRBool suspendAllOn; |
michael@0 | 10 | extern PRThread *suspendAllThread; |
michael@0 | 11 | |
michael@0 | 12 | extern void _MD_SET_PRIORITY(_MDThread *md, PRThreadPriority newPri); |
michael@0 | 13 | |
michael@0 | 14 | PRIntervalTime _MD_Solaris_TicksPerSecond(void) |
michael@0 | 15 | { |
michael@0 | 16 | /* |
michael@0 | 17 | * Ticks have a 10-microsecond resolution. So there are |
michael@0 | 18 | * 100000 ticks per second. |
michael@0 | 19 | */ |
michael@0 | 20 | return 100000UL; |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | /* Interval timers, implemented using gethrtime() */ |
michael@0 | 24 | |
michael@0 | 25 | PRIntervalTime _MD_Solaris_GetInterval(void) |
michael@0 | 26 | { |
michael@0 | 27 | union { |
michael@0 | 28 | hrtime_t hrt; /* hrtime_t is a 64-bit (long long) integer */ |
michael@0 | 29 | PRInt64 pr64; |
michael@0 | 30 | } time; |
michael@0 | 31 | PRInt64 resolution; |
michael@0 | 32 | PRIntervalTime ticks; |
michael@0 | 33 | |
michael@0 | 34 | time.hrt = gethrtime(); /* in nanoseconds */ |
michael@0 | 35 | /* |
michael@0 | 36 | * Convert from nanoseconds to ticks. A tick's resolution is |
michael@0 | 37 | * 10 microseconds, or 10000 nanoseconds. |
michael@0 | 38 | */ |
michael@0 | 39 | LL_I2L(resolution, 10000); |
michael@0 | 40 | LL_DIV(time.pr64, time.pr64, resolution); |
michael@0 | 41 | LL_L2UI(ticks, time.pr64); |
michael@0 | 42 | return ticks; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | #ifdef _PR_PTHREADS |
michael@0 | 46 | void _MD_EarlyInit(void) |
michael@0 | 47 | { |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | PRWord *_MD_HomeGCRegisters(PRThread *t, PRIntn isCurrent, PRIntn *np) |
michael@0 | 51 | { |
michael@0 | 52 | *np = 0; |
michael@0 | 53 | return NULL; |
michael@0 | 54 | } |
michael@0 | 55 | #endif /* _PR_PTHREADS */ |
michael@0 | 56 | |
michael@0 | 57 | #if defined(_PR_LOCAL_THREADS_ONLY) |
michael@0 | 58 | |
michael@0 | 59 | void _MD_EarlyInit(void) |
michael@0 | 60 | { |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | void _MD_SolarisInit() |
michael@0 | 64 | { |
michael@0 | 65 | _PR_UnixInit(); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | void |
michael@0 | 69 | _MD_SET_PRIORITY(_MDThread *thread, PRThreadPriority newPri) |
michael@0 | 70 | { |
michael@0 | 71 | return; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | PRStatus |
michael@0 | 75 | _MD_InitializeThread(PRThread *thread) |
michael@0 | 76 | { |
michael@0 | 77 | return PR_SUCCESS; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | PRStatus |
michael@0 | 81 | _MD_WAIT(PRThread *thread, PRIntervalTime ticks) |
michael@0 | 82 | { |
michael@0 | 83 | PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); |
michael@0 | 84 | _PR_MD_SWITCH_CONTEXT(thread); |
michael@0 | 85 | return PR_SUCCESS; |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | PRStatus |
michael@0 | 89 | _MD_WAKEUP_WAITER(PRThread *thread) |
michael@0 | 90 | { |
michael@0 | 91 | PR_ASSERT((thread == NULL) || (!(thread->flags & _PR_GLOBAL_SCOPE))); |
michael@0 | 92 | return PR_SUCCESS; |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | /* These functions should not be called for Solaris */ |
michael@0 | 96 | void |
michael@0 | 97 | _MD_YIELD(void) |
michael@0 | 98 | { |
michael@0 | 99 | PR_NOT_REACHED("_MD_YIELD should not be called for Solaris"); |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | PRStatus |
michael@0 | 103 | _MD_CREATE_THREAD( |
michael@0 | 104 | PRThread *thread, |
michael@0 | 105 | void (*start) (void *), |
michael@0 | 106 | PRThreadPriority priority, |
michael@0 | 107 | PRThreadScope scope, |
michael@0 | 108 | PRThreadState state, |
michael@0 | 109 | PRUint32 stackSize) |
michael@0 | 110 | { |
michael@0 | 111 | PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for Solaris"); |
michael@0 | 112 | return(PR_FAILURE); |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | #ifdef USE_SETJMP |
michael@0 | 116 | PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) |
michael@0 | 117 | { |
michael@0 | 118 | if (isCurrent) { |
michael@0 | 119 | (void) setjmp(CONTEXT(t)); |
michael@0 | 120 | } |
michael@0 | 121 | *np = sizeof(CONTEXT(t)) / sizeof(PRWord); |
michael@0 | 122 | return (PRWord *) CONTEXT(t); |
michael@0 | 123 | } |
michael@0 | 124 | #else |
michael@0 | 125 | PRWord *_MD_HomeGCRegisters(PRThread *t, PRIntn isCurrent, PRIntn *np) |
michael@0 | 126 | { |
michael@0 | 127 | if (isCurrent) { |
michael@0 | 128 | (void) getcontext(CONTEXT(t)); |
michael@0 | 129 | } |
michael@0 | 130 | *np = NGREG; |
michael@0 | 131 | return (PRWord*) &t->md.context.uc_mcontext.gregs[0]; |
michael@0 | 132 | } |
michael@0 | 133 | #endif /* USE_SETJMP */ |
michael@0 | 134 | |
michael@0 | 135 | #endif /* _PR_LOCAL_THREADS_ONLY */ |
michael@0 | 136 | |
michael@0 | 137 | #ifndef _PR_PTHREADS |
michael@0 | 138 | #if defined(i386) && defined(SOLARIS2_4) |
michael@0 | 139 | /* |
michael@0 | 140 | * Because clock_gettime() on Solaris/x86 2.4 always generates a |
michael@0 | 141 | * segmentation fault, we use an emulated version _pr_solx86_clock_gettime(), |
michael@0 | 142 | * which is implemented using gettimeofday(). |
michael@0 | 143 | */ |
michael@0 | 144 | |
michael@0 | 145 | int |
michael@0 | 146 | _pr_solx86_clock_gettime(clockid_t clock_id, struct timespec *tp) |
michael@0 | 147 | { |
michael@0 | 148 | struct timeval tv; |
michael@0 | 149 | |
michael@0 | 150 | if (clock_id != CLOCK_REALTIME) { |
michael@0 | 151 | errno = EINVAL; |
michael@0 | 152 | return -1; |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | gettimeofday(&tv, NULL); |
michael@0 | 156 | tp->tv_sec = tv.tv_sec; |
michael@0 | 157 | tp->tv_nsec = tv.tv_usec * 1000; |
michael@0 | 158 | return 0; |
michael@0 | 159 | } |
michael@0 | 160 | #endif /* i386 && SOLARIS2_4 */ |
michael@0 | 161 | #endif /* _PR_PTHREADS */ |