VirtualBox

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

Last change on this file since 22150 was 22150, checked in by vboxsync, 15 years ago

IPRT,SUPDrv: Changed RTTHREADPREEMPTSTATE breaking binary compatibility - increased the major SUPDrv version.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 KB
Line 
1/* $Id: thread-r0drv-solaris.c 22150 2009-08-11 09:41:58Z vboxsync $ */
2/** @file
3 * IPRT - Threads, Ring-0 Driver, Solaris.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * 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
43
44
45RTDECL(RTNATIVETHREAD) RTThreadNativeSelf(void)
46{
47 return (RTNATIVETHREAD)curthread;
48}
49
50
51RTDECL(int) RTThreadSleep(unsigned cMillies)
52{
53 clock_t cTicks;
54 unsigned long timeout;
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#if 0
69 timeout = ddi_get_lbolt();
70 timeout += cTicks;
71
72 kcondvar_t cnd;
73 kmutex_t mtx;
74 mutex_init(&mtx, "IPRT Sleep Mutex", MUTEX_DRIVER, NULL);
75 cv_init(&cnd, "IPRT Sleep CV", CV_DRIVER, NULL);
76 mutex_enter(&mtx);
77 cv_timedwait (&cnd, &mtx, timeout);
78 mutex_exit(&mtx);
79 cv_destroy(&cnd);
80 mutex_destroy(&mtx);
81#endif
82
83#if 1
84 delay(cTicks);
85#endif
86
87#if 0
88 /* Hmm, no same effect as using delay() */
89 struct timespec t;
90 t.tv_sec = 0;
91 t.tv_nsec = cMillies * 1000000L;
92 nanosleep (&t, NULL);
93#endif
94
95 return VINF_SUCCESS;
96}
97
98
99RTDECL(bool) RTThreadYield(void)
100{
101 RT_ASSERT_PREEMPTIBLE();
102 schedctl_set_yield(curthread, 0); /** @todo this is incomplete/wrong. */
103 return true;
104}
105
106
107RTDECL(bool) RTThreadPreemptIsEnabled(RTTHREAD hThread)
108{
109 Assert(hThread == NIL_RTTHREAD);
110 if (curthread->t_preempt != 0)
111 return false;
112 if (!ASMIntAreEnabled())
113 return false;
114 return true;
115}
116
117
118RTDECL(bool) RTThreadPreemptIsPending(RTTHREAD hThread)
119{
120 Assert(hThread == NIL_RTTHREAD);
121 /** @todo Review this! */
122 return CPU->cpu_runrun != 0
123 || CPU->cpu_kprunrun != 0;
124}
125
126
127RTDECL(bool) RTThreadPreemptIsPendingTrusty(void)
128{
129 /* yes, RTThreadPreemptIsPending is reliable. */
130 return true;
131}
132
133
134RTDECL(bool) RTThreadPreemptIsPossible(void)
135{
136 /* yes, kernel preemption is possible. */
137 return true;
138}
139
140
141RTDECL(void) RTThreadPreemptDisable(PRTTHREADPREEMPTSTATE pState)
142{
143 AssertPtr(pState);
144 Assert(pState->u32Reserved == 0);
145 pState->u32Reserved = 42;
146
147 kpreempt_disable();
148 RT_ASSERT_PREEMPT_CPUID_DISABLE(pState);
149}
150
151
152RTDECL(void) RTThreadPreemptRestore(PRTTHREADPREEMPTSTATE pState)
153{
154 AssertPtr(pState);
155 Assert(pState->u32Reserved == 42);
156 pState->u32Reserved = 0;
157 RT_ASSERT_PREEMPT_CPUID_RESTORE(pState);
158
159 kpreempt_enable();
160}
161
162
163RTDECL(bool) RTThreadIsInInterrupt(RTTHREAD hThread)
164{
165 /* This is the best we currently can do here. :-( */
166 return !RTThreadPreemptIsEnabled(hThread)
167 && getpil() > 0;
168}
169
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