VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/solaris/thread-r0drv-solaris.c

Last change on this file was 98103, checked in by vboxsync, 17 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 KB
Line 
1/* $Id: thread-r0drv-solaris.c 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * IPRT - Threads, Ring-0 Driver, Solaris.
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include "the-solaris-kernel.h"
42#include "internal/iprt.h"
43#include <iprt/thread.h>
44
45#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
46# include <iprt/asm-amd64-x86.h>
47#endif
48#include <iprt/assert.h>
49#include <iprt/errcore.h>
50#include <iprt/mp.h>
51
52#define SOL_THREAD_PREEMPT (*((char *)curthread + g_offrtSolThreadPreempt))
53#define SOL_CPU_RUNRUN (*((char *)CPU + g_offrtSolCpuPreempt))
54#define SOL_CPU_KPRUNRUN (*((char *)CPU + g_offrtSolCpuForceKernelPreempt))
55
56RTDECL(RTNATIVETHREAD) RTThreadNativeSelf(void)
57{
58 return (RTNATIVETHREAD)curthread;
59}
60
61
62static int rtR0ThreadSolSleepCommon(RTMSINTERVAL cMillies)
63{
64 clock_t cTicks;
65 RT_ASSERT_PREEMPTIBLE();
66
67 if (!cMillies)
68 {
69 RTThreadYield();
70 return VINF_SUCCESS;
71 }
72
73 if (cMillies != RT_INDEFINITE_WAIT)
74 cTicks = drv_usectohz((clock_t)(cMillies * 1000L));
75 else
76 cTicks = 0;
77
78 delay(cTicks);
79 return VINF_SUCCESS;
80}
81
82
83RTDECL(int) RTThreadSleep(RTMSINTERVAL cMillies)
84{
85 return rtR0ThreadSolSleepCommon(cMillies);
86}
87
88
89RTDECL(int) RTThreadSleepNoLog(RTMSINTERVAL cMillies)
90{
91 return rtR0ThreadSolSleepCommon(cMillies);
92}
93
94
95RTDECL(bool) RTThreadYield(void)
96{
97 RT_ASSERT_PREEMPTIBLE();
98
99 RTTHREADPREEMPTSTATE PreemptState = RTTHREADPREEMPTSTATE_INITIALIZER;
100 RTThreadPreemptDisable(&PreemptState);
101
102 char const bThreadPreempt = SOL_THREAD_PREEMPT;
103 char const bForcePreempt = SOL_CPU_KPRUNRUN;
104 bool fWillYield = false;
105 Assert(bThreadPreempt >= 1);
106
107 /*
108 * If we are the last preemption enabler for this thread and if force
109 * preemption is set on the CPU, only then we are guaranteed to be preempted.
110 */
111 if (bThreadPreempt == 1 && bForcePreempt != 0)
112 fWillYield = true;
113
114 RTThreadPreemptRestore(&PreemptState);
115 return fWillYield;
116}
117
118
119RTDECL(bool) RTThreadPreemptIsEnabled(RTTHREAD hThread)
120{
121 Assert(hThread == NIL_RTTHREAD);
122 if (RT_UNLIKELY(g_frtSolInitDone == false))
123 {
124 cmn_err(CE_CONT, "!RTThreadPreemptIsEnabled called before RTR0Init!\n");
125 return true;
126 }
127
128 bool fThreadPreempt = false;
129 if (SOL_THREAD_PREEMPT == 0)
130 fThreadPreempt = true;
131
132 if (!fThreadPreempt)
133 return false;
134#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
135 if (!ASMIntAreEnabled())
136 return false;
137#endif
138 if (getpil() >= DISP_LEVEL)
139 return false;
140 return true;
141}
142
143
144RTDECL(bool) RTThreadPreemptIsPending(RTTHREAD hThread)
145{
146 Assert(hThread == NIL_RTTHREAD);
147
148 char const bPreempt = SOL_CPU_RUNRUN;
149 char const bForcePreempt = SOL_CPU_KPRUNRUN;
150 return (bPreempt != 0 || bForcePreempt != 0);
151}
152
153
154RTDECL(bool) RTThreadPreemptIsPendingTrusty(void)
155{
156 /* yes, RTThreadPreemptIsPending is reliable. */
157 return true;
158}
159
160
161RTDECL(bool) RTThreadPreemptIsPossible(void)
162{
163 /* yes, kernel preemption is possible. */
164 return true;
165}
166
167
168RTDECL(void) RTThreadPreemptDisable(PRTTHREADPREEMPTSTATE pState)
169{
170 AssertPtr(pState);
171
172 SOL_THREAD_PREEMPT++;
173 Assert(SOL_THREAD_PREEMPT >= 1);
174
175 RT_ASSERT_PREEMPT_CPUID_DISABLE(pState);
176}
177
178
179RTDECL(void) RTThreadPreemptRestore(PRTTHREADPREEMPTSTATE pState)
180{
181 AssertPtr(pState);
182 RT_ASSERT_PREEMPT_CPUID_RESTORE(pState);
183
184 Assert(SOL_THREAD_PREEMPT >= 1);
185 if (--SOL_THREAD_PREEMPT == 0 && SOL_CPU_RUNRUN != 0)
186 kpreempt(KPREEMPT_SYNC);
187}
188
189
190RTDECL(bool) RTThreadIsInInterrupt(RTTHREAD hThread)
191{
192 Assert(hThread == NIL_RTTHREAD);
193 return servicing_interrupt() ? true : false;
194}
195
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use