1 | /* $Id: thread-r0drv-solaris.c 22566 2009-08-28 18:25:32Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Threads, Ring-0 Driver, Solaris.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2009 Sun Microsystems, Inc.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.alldomusa.eu.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | *
|
---|
26 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
27 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
28 | * additional information or have any questions.
|
---|
29 | */
|
---|
30 |
|
---|
31 |
|
---|
32 | /*******************************************************************************
|
---|
33 | * Header Files *
|
---|
34 | *******************************************************************************/
|
---|
35 | #include "the-solaris-kernel.h"
|
---|
36 | #include "internal/iprt.h"
|
---|
37 | #include <iprt/thread.h>
|
---|
38 |
|
---|
39 | #include <iprt/asm.h>
|
---|
40 | #include <iprt/assert.h>
|
---|
41 | #include <iprt/err.h>
|
---|
42 | #include <iprt/mp.h>
|
---|
43 |
|
---|
44 |
|
---|
45 |
|
---|
46 | RTDECL(RTNATIVETHREAD) RTThreadNativeSelf(void)
|
---|
47 | {
|
---|
48 | return (RTNATIVETHREAD)curthread;
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
52 | RTDECL(int) RTThreadSleep(unsigned cMillies)
|
---|
53 | {
|
---|
54 | clock_t cTicks;
|
---|
55 | unsigned long timeout;
|
---|
56 | RT_ASSERT_PREEMPTIBLE();
|
---|
57 |
|
---|
58 | if (!cMillies)
|
---|
59 | {
|
---|
60 | RTThreadYield();
|
---|
61 | return VINF_SUCCESS;
|
---|
62 | }
|
---|
63 |
|
---|
64 | if (cMillies != RT_INDEFINITE_WAIT)
|
---|
65 | cTicks = drv_usectohz((clock_t)(cMillies * 1000L));
|
---|
66 | else
|
---|
67 | cTicks = 0;
|
---|
68 |
|
---|
69 | #if 0
|
---|
70 | timeout = ddi_get_lbolt();
|
---|
71 | timeout += cTicks;
|
---|
72 |
|
---|
73 | kcondvar_t cnd;
|
---|
74 | kmutex_t mtx;
|
---|
75 | mutex_init(&mtx, "IPRT Sleep Mutex", MUTEX_DRIVER, NULL);
|
---|
76 | cv_init(&cnd, "IPRT Sleep CV", CV_DRIVER, NULL);
|
---|
77 | mutex_enter(&mtx);
|
---|
78 | cv_timedwait (&cnd, &mtx, timeout);
|
---|
79 | mutex_exit(&mtx);
|
---|
80 | cv_destroy(&cnd);
|
---|
81 | mutex_destroy(&mtx);
|
---|
82 | #endif
|
---|
83 |
|
---|
84 | #if 1
|
---|
85 | delay(cTicks);
|
---|
86 | #endif
|
---|
87 |
|
---|
88 | #if 0
|
---|
89 | /* Hmm, no same effect as using delay() */
|
---|
90 | struct timespec t;
|
---|
91 | t.tv_sec = 0;
|
---|
92 | t.tv_nsec = cMillies * 1000000L;
|
---|
93 | nanosleep (&t, NULL);
|
---|
94 | #endif
|
---|
95 |
|
---|
96 | return VINF_SUCCESS;
|
---|
97 | }
|
---|
98 |
|
---|
99 |
|
---|
100 | RTDECL(bool) RTThreadYield(void)
|
---|
101 | {
|
---|
102 | RT_ASSERT_PREEMPTIBLE();
|
---|
103 | schedctl_set_yield(curthread, 0); /** @todo this is incomplete/wrong. */
|
---|
104 | return true;
|
---|
105 | }
|
---|
106 |
|
---|
107 |
|
---|
108 | RTDECL(bool) RTThreadPreemptIsEnabled(RTTHREAD hThread)
|
---|
109 | {
|
---|
110 | Assert(hThread == NIL_RTTHREAD);
|
---|
111 | if (curthread->t_preempt != 0)
|
---|
112 | return false;
|
---|
113 | if (!ASMIntAreEnabled())
|
---|
114 | return false;
|
---|
115 | if (getpil() >= DISP_LEVEL)
|
---|
116 | return false;
|
---|
117 | return true;
|
---|
118 | }
|
---|
119 |
|
---|
120 |
|
---|
121 | RTDECL(bool) RTThreadPreemptIsPending(RTTHREAD hThread)
|
---|
122 | {
|
---|
123 | Assert(hThread == NIL_RTTHREAD);
|
---|
124 | return CPU->cpu_runrun != 0
|
---|
125 | || CPU->cpu_kprunrun != 0;
|
---|
126 | }
|
---|
127 |
|
---|
128 |
|
---|
129 | RTDECL(bool) RTThreadPreemptIsPendingTrusty(void)
|
---|
130 | {
|
---|
131 | /* yes, RTThreadPreemptIsPending is reliable. */
|
---|
132 | return true;
|
---|
133 | }
|
---|
134 |
|
---|
135 |
|
---|
136 | RTDECL(bool) RTThreadPreemptIsPossible(void)
|
---|
137 | {
|
---|
138 | /* yes, kernel preemption is possible. */
|
---|
139 | return true;
|
---|
140 | }
|
---|
141 |
|
---|
142 |
|
---|
143 | RTDECL(void) RTThreadPreemptDisable(PRTTHREADPREEMPTSTATE pState)
|
---|
144 | {
|
---|
145 | AssertPtr(pState);
|
---|
146 | Assert(pState->u32Reserved == 0);
|
---|
147 | pState->u32Reserved = 42;
|
---|
148 |
|
---|
149 | kpreempt_disable();
|
---|
150 | RT_ASSERT_PREEMPT_CPUID_DISABLE(pState);
|
---|
151 | }
|
---|
152 |
|
---|
153 |
|
---|
154 | RTDECL(void) RTThreadPreemptRestore(PRTTHREADPREEMPTSTATE pState)
|
---|
155 | {
|
---|
156 | AssertPtr(pState);
|
---|
157 | Assert(pState->u32Reserved == 42);
|
---|
158 | pState->u32Reserved = 0;
|
---|
159 | RT_ASSERT_PREEMPT_CPUID_RESTORE(pState);
|
---|
160 |
|
---|
161 | kpreempt_enable();
|
---|
162 | }
|
---|
163 |
|
---|
164 |
|
---|
165 | RTDECL(bool) RTThreadIsInInterrupt(RTTHREAD hThread)
|
---|
166 | {
|
---|
167 | Assert(hThread == NIL_RTTHREAD);
|
---|
168 | return servicing_interrupt() ? true : false;
|
---|
169 | }
|
---|
170 |
|
---|