VirtualBox

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

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

iprt/r0drv/solaris: context assertions (RT_MORE_STRICT).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 KB
Line 
1/* $Id: thread-r0drv-solaris.c 22073 2009-08-07 15:26:56Z 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)vbi_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 return vbi_yield();
103}
104
105
106RTDECL(bool) RTThreadPreemptIsEnabled(RTTHREAD hThread)
107{
108 Assert(hThread == NIL_RTTHREAD);
109 if ( vbi_is_preempt_enabled()
110 && ASMIntAreEnabled())
111 return true;
112 return false;
113}
114
115
116RTDECL(bool) RTThreadPreemptIsPending(RTTHREAD hThread)
117{
118 Assert(hThread == NIL_RTTHREAD);
119 return !!vbi_is_preempt_pending();
120}
121
122
123RTDECL(bool) RTThreadPreemptIsPendingTrusty(void)
124{
125 /* yes, RTThreadPreemptIsPending is reliable. */
126 return true;
127}
128
129
130RTDECL(bool) RTThreadPreemptIsPossible(void)
131{
132 /* yes, kernel preemption is possible. */
133 return true;
134}
135
136
137RTDECL(void) RTThreadPreemptDisable(PRTTHREADPREEMPTSTATE pState)
138{
139 AssertPtr(pState);
140 Assert(pState->uchDummy != 42);
141 pState->uchDummy = 42;
142 vbi_preempt_disable();
143}
144
145
146RTDECL(void) RTThreadPreemptRestore(PRTTHREADPREEMPTSTATE pState)
147{
148 AssertPtr(pState);
149 Assert(pState->uchDummy == 42);
150 pState->uchDummy = 0;
151 vbi_preempt_enable();
152}
153
154
155RTDECL(bool) RTThreadIsInInterrupt(RTTHREAD hThread)
156{
157 /* This is the best we currently can do here. :-( */
158 return !RTThreadPreemptIsEnabled(hThread)
159 && getpil() > 0;
160}
161
162
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