VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/freebsd/thread-r0drv-freebsd.c@ 25720

Last change on this file since 25720 was 22151, checked in by vboxsync, 16 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.3 KB
Line 
1/* $Id: thread-r0drv-freebsd.c 22151 2009-08-11 09:46:23Z vboxsync $ */
2/** @file
3 * IPRT - Threads (Part 1), Ring-0 Driver, FreeBSD.
4 */
5
6/*
7 * Copyright (C) 2007-2009 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* Header Files *
33*******************************************************************************/
34#include "the-freebsd-kernel.h"
35#include "internal/iprt.h"
36#include <iprt/thread.h>
37
38#include <iprt/asm.h>
39#include <iprt/assert.h>
40#include <iprt/err.h>
41#include <iprt/mp.h>
42#include "internal/thread.h"
43
44
45RTDECL(RTNATIVETHREAD) RTThreadNativeSelf(void)
46{
47 return (RTNATIVETHREAD)curthread;
48}
49
50
51RTDECL(int) RTThreadSleep(unsigned cMillies)
52{
53 int rc;
54 int cTicks;
55
56 /*
57 * 0 ms sleep -> yield.
58 */
59 if (!cMillies)
60 {
61 RTThreadYield();
62 return VINF_SUCCESS;
63 }
64
65 /*
66 * Translate milliseconds into ticks and go to sleep.
67 */
68 if (cMillies != RT_INDEFINITE_WAIT)
69 {
70 if (hz == 1000)
71 cTicks = cMillies;
72 else if (hz == 100)
73 cTicks = cMillies / 10;
74 else
75 {
76 int64_t cTicks64 = ((uint64_t)cMillies * hz) / 1000;
77 cTicks = (int)cTicks64;
78 if (cTicks != cTicks64)
79 cTicks = INT_MAX;
80 }
81 }
82 else
83 cTicks = 0; /* requires giant lock! */
84
85 rc = tsleep((void *)RTThreadSleep,
86 PZERO | PCATCH,
87 "iprtsl", /* max 6 chars */
88 cTicks);
89 switch (rc)
90 {
91 case 0:
92 return VINF_SUCCESS;
93 case EWOULDBLOCK:
94 return VERR_TIMEOUT;
95 case EINTR:
96 case ERESTART:
97 return VERR_INTERRUPTED;
98 default:
99 AssertMsgFailed(("%d\n", rc));
100 return VERR_NO_TRANSLATION;
101 }
102}
103
104
105RTDECL(bool) RTThreadYield(void)
106{
107 uio_yield();
108 return false; /** @todo figure this one ... */
109}
110
111
112RTDECL(bool) RTThreadPreemptIsEnabled(RTTHREAD hThread)
113{
114 Assert(hThread == NIL_RTTHREAD);
115
116 return curthread->td_critnest == 0
117 && ASMIntAreEnabled(); /** @todo is there a native freebsd function/macro for this? */
118}
119
120
121RTDECL(bool) RTThreadPreemptIsPending(RTTHREAD hThread)
122{
123 Assert(hThread == NIL_RTTHREAD);
124
125 return curthread->td_owepreempt == 1;
126}
127
128
129RTDECL(bool) RTThreadPreemptIsPendingTrusty(void)
130{
131 /* yes, RTThreadPreemptIsPending is reliable. */
132 return true;
133}
134
135
136RTDECL(bool) RTThreadPreemptIsPossible(void)
137{
138 /* yes, kernel preemption is possible. */
139 return true;
140}
141
142
143RTDECL(void) RTThreadPreemptDisable(PRTTHREADPREEMPTSTATE pState)
144{
145 AssertPtr(pState);
146 Assert(pState->u32Reserved == 0);
147 pState->u32Reserved = 42;
148
149 critical_enter();
150 RT_ASSERT_PREEMPT_CPUID_DISABLE(pState);
151}
152
153
154RTDECL(void) RTThreadPreemptRestore(PRTTHREADPREEMPTSTATE pState)
155{
156 AssertPtr(pState);
157 Assert(pState->u32Reserved == 42);
158 pState->u32Reserved = 0;
159
160 RT_ASSERT_PREEMPT_CPUID_RESTORE(pState);
161 critical_exit();
162}
163
164
165RTDECL(bool) RTThreadIsInInterrupt(RTTHREAD hThread)
166{
167 Assert(hThread == NIL_RTTHREAD); NOREF(hThread);
168 /** @todo FreeBSD: Implement RTThreadIsInInterrupt. Required for guest
169 * additions! */
170 return !ASMIntAreEnabled();
171}
172
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