VirtualBox

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

Last change on this file since 21536 was 21536, checked in by vboxsync, 16 years ago

iprt/thread.h: Redefined RTThreadPreemptIsEnabled for systems without preemption (we keep count ourselves). Added RTThreadPreemptIsPossible and RTThreadIsInInterrupt. Fixed RTThreadPreemptIsEnabled on FreeBSD and Solaris/vbi.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1/* $Id: thread-r0drv-solaris.c 21536 2009-07-13 14:49:39Z 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
37#include <iprt/thread.h>
38#include <iprt/asm.h>
39#include <iprt/assert.h>
40#include <iprt/err.h>
41
42
43RTDECL(RTNATIVETHREAD) RTThreadNativeSelf(void)
44{
45 return (RTNATIVETHREAD)vbi_curthread();
46}
47
48
49RTDECL(int) RTThreadSleep(unsigned cMillies)
50{
51 clock_t cTicks;
52 unsigned long timeout;
53
54 if (!cMillies)
55 {
56 RTThreadYield();
57 return VINF_SUCCESS;
58 }
59
60 if (cMillies != RT_INDEFINITE_WAIT)
61 cTicks = drv_usectohz((clock_t)(cMillies * 1000L));
62 else
63 cTicks = 0;
64
65#if 0
66 timeout = ddi_get_lbolt();
67 timeout += cTicks;
68
69 kcondvar_t cnd;
70 kmutex_t mtx;
71 mutex_init(&mtx, "IPRT Sleep Mutex", MUTEX_DRIVER, NULL);
72 cv_init(&cnd, "IPRT Sleep CV", CV_DRIVER, NULL);
73 mutex_enter(&mtx);
74 cv_timedwait (&cnd, &mtx, timeout);
75 mutex_exit(&mtx);
76 cv_destroy(&cnd);
77 mutex_destroy(&mtx);
78#endif
79
80#if 1
81 delay(cTicks);
82#endif
83
84#if 0
85 /* Hmm, no same effect as using delay() */
86 struct timespec t;
87 t.tv_sec = 0;
88 t.tv_nsec = cMillies * 1000000L;
89 nanosleep (&t, NULL);
90#endif
91
92 return VINF_SUCCESS;
93}
94
95
96RTDECL(bool) RTThreadYield(void)
97{
98 return vbi_yield();
99}
100
101
102RTDECL(bool) RTThreadPreemptIsEnabled(RTTHREAD hThread)
103{
104 Assert(hThread == NIL_RTTHREAD);
105 if ( vbi_is_preempt_enabled()
106 && ASMIntAreEnabled())
107 return true;
108 return false;
109}
110
111
112RTDECL(bool) RTThreadPreemptIsPending(RTTHREAD hThread)
113{
114 Assert(hThread == NIL_RTTHREAD);
115 return !!vbi_is_preempt_pending();
116}
117
118
119RTDECL(bool) RTThreadPreemptIsPendingTrusty(void)
120{
121 /* yes, RTThreadPreemptIsPending is reliable. */
122 return true;
123}
124
125
126RTDECL(bool) RTThreadPreemptIsPossible(void)
127{
128 /* yes, kernel preemption is possible. */
129 return true;
130}
131
132
133RTDECL(void) RTThreadPreemptDisable(PRTTHREADPREEMPTSTATE pState)
134{
135 AssertPtr(pState);
136 Assert(pState->uchDummy != 42);
137 pState->uchDummy = 42;
138 vbi_preempt_disable();
139}
140
141
142RTDECL(void) RTThreadPreemptRestore(PRTTHREADPREEMPTSTATE pState)
143{
144 AssertPtr(pState);
145 Assert(pState->uchDummy == 42);
146 pState->uchDummy = 0;
147 vbi_preempt_enable();
148}
149
150
151RTDECL(bool) RTThreadIsInInterrupt(RTTHREAD hThread)
152{
153 Assert(hThread == NIL_RTTHREAD); NOREF(hThread);
154 /** @todo Solaris: Implement RTThreadIsInInterrupt. Required for guest
155 * additions! */
156 return !ASMIntAreEnabled();
157}
158
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