michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "primpl.h" michael@0: michael@0: michael@0: extern PRBool suspendAllOn; michael@0: extern PRThread *suspendAllThread; michael@0: michael@0: extern void _MD_SET_PRIORITY(_MDThread *md, PRThreadPriority newPri); michael@0: michael@0: PRIntervalTime _MD_Solaris_TicksPerSecond(void) michael@0: { michael@0: /* michael@0: * Ticks have a 10-microsecond resolution. So there are michael@0: * 100000 ticks per second. michael@0: */ michael@0: return 100000UL; michael@0: } michael@0: michael@0: /* Interval timers, implemented using gethrtime() */ michael@0: michael@0: PRIntervalTime _MD_Solaris_GetInterval(void) michael@0: { michael@0: union { michael@0: hrtime_t hrt; /* hrtime_t is a 64-bit (long long) integer */ michael@0: PRInt64 pr64; michael@0: } time; michael@0: PRInt64 resolution; michael@0: PRIntervalTime ticks; michael@0: michael@0: time.hrt = gethrtime(); /* in nanoseconds */ michael@0: /* michael@0: * Convert from nanoseconds to ticks. A tick's resolution is michael@0: * 10 microseconds, or 10000 nanoseconds. michael@0: */ michael@0: LL_I2L(resolution, 10000); michael@0: LL_DIV(time.pr64, time.pr64, resolution); michael@0: LL_L2UI(ticks, time.pr64); michael@0: return ticks; michael@0: } michael@0: michael@0: #ifdef _PR_PTHREADS michael@0: void _MD_EarlyInit(void) michael@0: { michael@0: } michael@0: michael@0: PRWord *_MD_HomeGCRegisters(PRThread *t, PRIntn isCurrent, PRIntn *np) michael@0: { michael@0: *np = 0; michael@0: return NULL; michael@0: } michael@0: #endif /* _PR_PTHREADS */ michael@0: michael@0: #if defined(_PR_LOCAL_THREADS_ONLY) michael@0: michael@0: void _MD_EarlyInit(void) michael@0: { michael@0: } michael@0: michael@0: void _MD_SolarisInit() michael@0: { michael@0: _PR_UnixInit(); michael@0: } michael@0: michael@0: void michael@0: _MD_SET_PRIORITY(_MDThread *thread, PRThreadPriority newPri) michael@0: { michael@0: return; michael@0: } michael@0: michael@0: PRStatus michael@0: _MD_InitializeThread(PRThread *thread) michael@0: { michael@0: return PR_SUCCESS; michael@0: } michael@0: michael@0: PRStatus michael@0: _MD_WAIT(PRThread *thread, PRIntervalTime ticks) michael@0: { michael@0: PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE)); michael@0: _PR_MD_SWITCH_CONTEXT(thread); michael@0: return PR_SUCCESS; michael@0: } michael@0: michael@0: PRStatus michael@0: _MD_WAKEUP_WAITER(PRThread *thread) michael@0: { michael@0: PR_ASSERT((thread == NULL) || (!(thread->flags & _PR_GLOBAL_SCOPE))); michael@0: return PR_SUCCESS; michael@0: } michael@0: michael@0: /* These functions should not be called for Solaris */ michael@0: void michael@0: _MD_YIELD(void) michael@0: { michael@0: PR_NOT_REACHED("_MD_YIELD should not be called for Solaris"); michael@0: } michael@0: michael@0: PRStatus michael@0: _MD_CREATE_THREAD( michael@0: PRThread *thread, michael@0: void (*start) (void *), michael@0: PRThreadPriority priority, michael@0: PRThreadScope scope, michael@0: PRThreadState state, michael@0: PRUint32 stackSize) michael@0: { michael@0: PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for Solaris"); michael@0: return(PR_FAILURE); michael@0: } michael@0: michael@0: #ifdef USE_SETJMP michael@0: PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) michael@0: { michael@0: if (isCurrent) { michael@0: (void) setjmp(CONTEXT(t)); michael@0: } michael@0: *np = sizeof(CONTEXT(t)) / sizeof(PRWord); michael@0: return (PRWord *) CONTEXT(t); michael@0: } michael@0: #else michael@0: PRWord *_MD_HomeGCRegisters(PRThread *t, PRIntn isCurrent, PRIntn *np) michael@0: { michael@0: if (isCurrent) { michael@0: (void) getcontext(CONTEXT(t)); michael@0: } michael@0: *np = NGREG; michael@0: return (PRWord*) &t->md.context.uc_mcontext.gregs[0]; michael@0: } michael@0: #endif /* USE_SETJMP */ michael@0: michael@0: #endif /* _PR_LOCAL_THREADS_ONLY */ michael@0: michael@0: #ifndef _PR_PTHREADS michael@0: #if defined(i386) && defined(SOLARIS2_4) michael@0: /* michael@0: * Because clock_gettime() on Solaris/x86 2.4 always generates a michael@0: * segmentation fault, we use an emulated version _pr_solx86_clock_gettime(), michael@0: * which is implemented using gettimeofday(). michael@0: */ michael@0: michael@0: int michael@0: _pr_solx86_clock_gettime(clockid_t clock_id, struct timespec *tp) michael@0: { michael@0: struct timeval tv; michael@0: michael@0: if (clock_id != CLOCK_REALTIME) { michael@0: errno = EINVAL; michael@0: return -1; michael@0: } michael@0: michael@0: gettimeofday(&tv, NULL); michael@0: tp->tv_sec = tv.tv_sec; michael@0: tp->tv_nsec = tv.tv_usec * 1000; michael@0: return 0; michael@0: } michael@0: #endif /* i386 && SOLARIS2_4 */ michael@0: #endif /* _PR_PTHREADS */