VirtualBox

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

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

Automated rebranding to Oracle copyright/license strings via filemuncher

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