VirtualBox

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

Last change on this file since 81106 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 KB
Line 
1/* $Id: thread-r0drv-solaris.c 76553 2019-01-01 01:45:53Z vboxsync $ */
2/** @file
3 * IPRT - Threads, Ring-0 Driver, Solaris.
4 */
5
6/*
7 * Copyright (C) 2006-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.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
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include "the-solaris-kernel.h"
32#include "internal/iprt.h"
33#include <iprt/thread.h>
34
35#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
36# include <iprt/asm-amd64-x86.h>
37#endif
38#include <iprt/assert.h>
39#include <iprt/errcore.h>
40#include <iprt/mp.h>
41
42#define SOL_THREAD_PREEMPT (*((char *)curthread + g_offrtSolThreadPreempt))
43#define SOL_CPU_RUNRUN (*((char *)CPU + g_offrtSolCpuPreempt))
44#define SOL_CPU_KPRUNRUN (*((char *)CPU + g_offrtSolCpuForceKernelPreempt))
45
46RTDECL(RTNATIVETHREAD) RTThreadNativeSelf(void)
47{
48 return (RTNATIVETHREAD)curthread;
49}
50
51
52static int rtR0ThreadSolSleepCommon(RTMSINTERVAL cMillies)
53{
54 clock_t cTicks;
55 RT_ASSERT_PREEMPTIBLE();
56
57 if (!cMillies)
58 {
59 RTThreadYield();
60 return VINF_SUCCESS;
61 }
62
63 if (cMillies != RT_INDEFINITE_WAIT)
64 cTicks = drv_usectohz((clock_t)(cMillies * 1000L));
65 else
66 cTicks = 0;
67
68 delay(cTicks);
69 return VINF_SUCCESS;
70}
71
72
73RTDECL(int) RTThreadSleep(RTMSINTERVAL cMillies)
74{
75 return rtR0ThreadSolSleepCommon(cMillies);
76}
77
78
79RTDECL(int) RTThreadSleepNoLog(RTMSINTERVAL cMillies)
80{
81 return rtR0ThreadSolSleepCommon(cMillies);
82}
83
84
85RTDECL(bool) RTThreadYield(void)
86{
87 RT_ASSERT_PREEMPTIBLE();
88
89 RTTHREADPREEMPTSTATE PreemptState = RTTHREADPREEMPTSTATE_INITIALIZER;
90 RTThreadPreemptDisable(&PreemptState);
91
92 char const bThreadPreempt = SOL_THREAD_PREEMPT;
93 char const bForcePreempt = SOL_CPU_KPRUNRUN;
94 bool fWillYield = false;
95 Assert(bThreadPreempt >= 1);
96
97 /*
98 * If we are the last preemption enabler for this thread and if force
99 * preemption is set on the CPU, only then we are guaranteed to be preempted.
100 */
101 if (bThreadPreempt == 1 && bForcePreempt != 0)
102 fWillYield = true;
103
104 RTThreadPreemptRestore(&PreemptState);
105 return fWillYield;
106}
107
108
109RTDECL(bool) RTThreadPreemptIsEnabled(RTTHREAD hThread)
110{
111 Assert(hThread == NIL_RTTHREAD);
112 if (RT_UNLIKELY(g_frtSolInitDone == false))
113 {
114 cmn_err(CE_CONT, "!RTThreadPreemptIsEnabled called before RTR0Init!\n");
115 return true;
116 }
117
118 bool fThreadPreempt = false;
119 if (SOL_THREAD_PREEMPT == 0)
120 fThreadPreempt = true;
121
122 if (!fThreadPreempt)
123 return false;
124#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
125 if (!ASMIntAreEnabled())
126 return false;
127#endif
128 if (getpil() >= DISP_LEVEL)
129 return false;
130 return true;
131}
132
133
134RTDECL(bool) RTThreadPreemptIsPending(RTTHREAD hThread)
135{
136 Assert(hThread == NIL_RTTHREAD);
137
138 char const bPreempt = SOL_CPU_RUNRUN;
139 char const bForcePreempt = SOL_CPU_KPRUNRUN;
140 return (bPreempt != 0 || bForcePreempt != 0);
141}
142
143
144RTDECL(bool) RTThreadPreemptIsPendingTrusty(void)
145{
146 /* yes, RTThreadPreemptIsPending is reliable. */
147 return true;
148}
149
150
151RTDECL(bool) RTThreadPreemptIsPossible(void)
152{
153 /* yes, kernel preemption is possible. */
154 return true;
155}
156
157
158RTDECL(void) RTThreadPreemptDisable(PRTTHREADPREEMPTSTATE pState)
159{
160 AssertPtr(pState);
161
162 SOL_THREAD_PREEMPT++;
163 Assert(SOL_THREAD_PREEMPT >= 1);
164
165 RT_ASSERT_PREEMPT_CPUID_DISABLE(pState);
166}
167
168
169RTDECL(void) RTThreadPreemptRestore(PRTTHREADPREEMPTSTATE pState)
170{
171 AssertPtr(pState);
172 RT_ASSERT_PREEMPT_CPUID_RESTORE(pState);
173
174 Assert(SOL_THREAD_PREEMPT >= 1);
175 if (--SOL_THREAD_PREEMPT == 0 && SOL_CPU_RUNRUN != 0)
176 kpreempt(KPREEMPT_SYNC);
177}
178
179
180RTDECL(bool) RTThreadIsInInterrupt(RTTHREAD hThread)
181{
182 Assert(hThread == NIL_RTTHREAD);
183 return servicing_interrupt() ? true : false;
184}
185
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette