nsprpub/pr/src/md/unix/solaris.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/src/md/unix/solaris.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,161 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "primpl.h"
    1.10 +
    1.11 +
    1.12 +extern PRBool suspendAllOn;
    1.13 +extern PRThread *suspendAllThread;
    1.14 +
    1.15 +extern void _MD_SET_PRIORITY(_MDThread *md, PRThreadPriority newPri);
    1.16 +
    1.17 +PRIntervalTime _MD_Solaris_TicksPerSecond(void)
    1.18 +{
    1.19 +    /*
    1.20 +     * Ticks have a 10-microsecond resolution.  So there are
    1.21 +     * 100000 ticks per second.
    1.22 +     */
    1.23 +    return 100000UL;
    1.24 +}
    1.25 +
    1.26 +/* Interval timers, implemented using gethrtime() */
    1.27 +
    1.28 +PRIntervalTime _MD_Solaris_GetInterval(void)
    1.29 +{
    1.30 +    union {
    1.31 +	hrtime_t hrt;  /* hrtime_t is a 64-bit (long long) integer */
    1.32 +	PRInt64 pr64;
    1.33 +    } time;
    1.34 +    PRInt64 resolution;
    1.35 +    PRIntervalTime ticks;
    1.36 +
    1.37 +    time.hrt = gethrtime();  /* in nanoseconds */
    1.38 +    /*
    1.39 +     * Convert from nanoseconds to ticks.  A tick's resolution is
    1.40 +     * 10 microseconds, or 10000 nanoseconds.
    1.41 +     */
    1.42 +    LL_I2L(resolution, 10000);
    1.43 +    LL_DIV(time.pr64, time.pr64, resolution);
    1.44 +    LL_L2UI(ticks, time.pr64);
    1.45 +    return ticks;
    1.46 +}
    1.47 +
    1.48 +#ifdef _PR_PTHREADS
    1.49 +void _MD_EarlyInit(void)
    1.50 +{
    1.51 +}
    1.52 +
    1.53 +PRWord *_MD_HomeGCRegisters(PRThread *t, PRIntn isCurrent, PRIntn *np)
    1.54 +{
    1.55 +	*np = 0;
    1.56 +	return NULL;
    1.57 +}
    1.58 +#endif /* _PR_PTHREADS */
    1.59 +
    1.60 +#if defined(_PR_LOCAL_THREADS_ONLY)
    1.61 +
    1.62 +void _MD_EarlyInit(void)
    1.63 +{
    1.64 +}
    1.65 +
    1.66 +void _MD_SolarisInit()
    1.67 +{
    1.68 +    _PR_UnixInit();
    1.69 +}
    1.70 +
    1.71 +void
    1.72 +_MD_SET_PRIORITY(_MDThread *thread, PRThreadPriority newPri)
    1.73 +{
    1.74 +    return;
    1.75 +}
    1.76 +
    1.77 +PRStatus
    1.78 +_MD_InitializeThread(PRThread *thread)
    1.79 +{
    1.80 +	return PR_SUCCESS;
    1.81 +}
    1.82 +
    1.83 +PRStatus
    1.84 +_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
    1.85 +{
    1.86 +    PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
    1.87 +    _PR_MD_SWITCH_CONTEXT(thread);
    1.88 +    return PR_SUCCESS;
    1.89 +}
    1.90 +
    1.91 +PRStatus
    1.92 +_MD_WAKEUP_WAITER(PRThread *thread)
    1.93 +{
    1.94 +	PR_ASSERT((thread == NULL) || (!(thread->flags & _PR_GLOBAL_SCOPE)));
    1.95 +    return PR_SUCCESS;
    1.96 +}
    1.97 +
    1.98 +/* These functions should not be called for Solaris */
    1.99 +void
   1.100 +_MD_YIELD(void)
   1.101 +{
   1.102 +    PR_NOT_REACHED("_MD_YIELD should not be called for Solaris");
   1.103 +}
   1.104 +
   1.105 +PRStatus
   1.106 +_MD_CREATE_THREAD(
   1.107 +    PRThread *thread,
   1.108 +    void (*start) (void *),
   1.109 +    PRThreadPriority priority,
   1.110 +    PRThreadScope scope,
   1.111 +    PRThreadState state,
   1.112 +    PRUint32 stackSize)
   1.113 +{
   1.114 +    PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for Solaris");
   1.115 +	return(PR_FAILURE);
   1.116 +}
   1.117 +
   1.118 +#ifdef USE_SETJMP
   1.119 +PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
   1.120 +{
   1.121 +    if (isCurrent) {
   1.122 +		(void) setjmp(CONTEXT(t));
   1.123 +    }
   1.124 +    *np = sizeof(CONTEXT(t)) / sizeof(PRWord);
   1.125 +    return (PRWord *) CONTEXT(t);
   1.126 +}
   1.127 +#else
   1.128 +PRWord *_MD_HomeGCRegisters(PRThread *t, PRIntn isCurrent, PRIntn *np)
   1.129 +{
   1.130 +    if (isCurrent) {
   1.131 +		(void) getcontext(CONTEXT(t));
   1.132 +    }
   1.133 +    *np = NGREG;
   1.134 +    return (PRWord*) &t->md.context.uc_mcontext.gregs[0];
   1.135 +}
   1.136 +#endif  /* USE_SETJMP */
   1.137 +
   1.138 +#endif  /* _PR_LOCAL_THREADS_ONLY */
   1.139 +
   1.140 +#ifndef _PR_PTHREADS
   1.141 +#if defined(i386) && defined(SOLARIS2_4)
   1.142 +/* 
   1.143 + * Because clock_gettime() on Solaris/x86 2.4 always generates a
   1.144 + * segmentation fault, we use an emulated version _pr_solx86_clock_gettime(),
   1.145 + * which is implemented using gettimeofday().
   1.146 + */
   1.147 +
   1.148 +int
   1.149 +_pr_solx86_clock_gettime(clockid_t clock_id, struct timespec *tp)
   1.150 +{
   1.151 +    struct timeval tv;
   1.152 +
   1.153 +    if (clock_id != CLOCK_REALTIME) {
   1.154 +	errno = EINVAL;
   1.155 +	return -1;
   1.156 +    }
   1.157 +
   1.158 +    gettimeofday(&tv, NULL);
   1.159 +    tp->tv_sec = tv.tv_sec;
   1.160 +    tp->tv_nsec = tv.tv_usec * 1000;
   1.161 +    return 0;
   1.162 +}
   1.163 +#endif  /* i386 && SOLARIS2_4 */
   1.164 +#endif  /* _PR_PTHREADS */

mercurial