VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/netbsd/thread-r0drv-netbsd.c@ 63191

最後變更 在這個檔案從63191是 63191,由 vboxsync 提交於 9 年 前

r0drv/netbsd: initial r0drv support for NetBSD.
From Haomai Wang GSoC project with additional changes by Arto Huusko.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 4.4 KB
 
1/* $Id: thread-r0drv-netbsd.c 63191 2016-08-09 03:01:52Z vboxsync $ */
2/** @file
3 * IPRT - Threads (Part 1), Ring-0 Driver, NetBSD.
4 */
5
6/*
7 * Copyright (C) 2007-2011 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.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-netbsd-kernel.h"
31#include "internal/iprt.h"
32#include <iprt/thread.h>
33
34#include <iprt/asm.h>
35#include <iprt/asm-amd64-x86.h>
36#include <iprt/assert.h>
37#include <iprt/err.h>
38#include <iprt/mp.h>
39#include "internal/thread.h"
40
41
42RTDECL(RTNATIVETHREAD) RTThreadNativeSelf(void)
43{
44 return (RTNATIVETHREAD)curlwp;
45}
46
47
48static int rtR0ThreadNbsdSleepCommon(RTMSINTERVAL cMillies)
49{
50 int rc;
51 int cTicks;
52
53 /*
54 * 0 ms sleep -> yield.
55 */
56 if (!cMillies)
57 {
58 RTThreadYield();
59 return VINF_SUCCESS;
60 }
61
62 /*
63 * Translate milliseconds into ticks and go to sleep.
64 */
65 if (cMillies != RT_INDEFINITE_WAIT)
66 {
67 if (hz == 1000)
68 cTicks = cMillies;
69 else if (hz == 100)
70 cTicks = cMillies / 10;
71 else
72 {
73 int64_t cTicks64 = ((uint64_t)cMillies * hz) / 1000;
74 cTicks = (int)cTicks64;
75 if (cTicks != cTicks64)
76 cTicks = INT_MAX;
77 }
78 }
79 else
80 cTicks = 0; /* requires giant lock! */
81
82 rc = tsleep((void *)RTThreadSleep,
83 PZERO | PCATCH,
84 "iprtsl", /* max 6 chars */
85 cTicks);
86 switch (rc)
87 {
88 case 0:
89 return VINF_SUCCESS;
90 case EWOULDBLOCK:
91 return VERR_TIMEOUT;
92 case EINTR:
93 case ERESTART:
94 return VERR_INTERRUPTED;
95 default:
96 AssertMsgFailed(("%d\n", rc));
97 return VERR_NO_TRANSLATION;
98 }
99}
100
101
102RTDECL(int) RTThreadSleep(RTMSINTERVAL cMillies)
103{
104 return rtR0ThreadNbsdSleepCommon(cMillies);
105}
106
107
108RTDECL(int) RTThreadSleepNoLog(RTMSINTERVAL cMillies)
109{
110 return rtR0ThreadNbsdSleepCommon(cMillies);
111}
112
113
114RTDECL(bool) RTThreadYield(void)
115{
116 yield();
117 return true;
118}
119
120
121RTDECL(bool) RTThreadPreemptIsEnabled(RTTHREAD hThread)
122{
123 Assert(hThread == NIL_RTTHREAD);
124
125 return curlwp->l_dopreempt == 0
126 && ASMIntAreEnabled(); /** @todo is there a native netbsd function/macro for this? */
127}
128
129
130RTDECL(bool) RTThreadPreemptIsPending(RTTHREAD hThread)
131{
132 Assert(hThread == NIL_RTTHREAD);
133
134 return curlwp->l_dopreempt;
135}
136
137
138RTDECL(bool) RTThreadPreemptIsPendingTrusty(void)
139{
140 /* yes, RTThreadPreemptIsPending is reliable. */
141 return true;
142}
143
144
145RTDECL(bool) RTThreadPreemptIsPossible(void)
146{
147 /* yes, kernel preemption is possible. */
148 return true;
149}
150
151RTDECL(void) RTThreadPreemptDisable(PRTTHREADPREEMPTSTATE pState)
152{
153 AssertPtr(pState);
154
155 curlwp->l_nopreempt++;
156 __insn_barrier();
157}
158
159
160RTDECL(void) RTThreadPreemptRestore(PRTTHREADPREEMPTSTATE pState)
161{
162
163 AssertPtr(pState);
164 __insn_barrier();
165 if (--curlwp->l_nopreempt != 0)
166 return;
167 __insn_barrier();
168 if (__predict_false(curlwp->l_dopreempt))
169 kpreempt(0);
170 __insn_barrier();
171}
172
173RTDECL(bool) RTThreadIsInInterrupt(RTTHREAD hThread)
174{
175 Assert(hThread == NIL_RTTHREAD); NOREF(hThread);
176 /** @todo NetBSD: Implement RTThreadIsInInterrupt. Required for guest
177 * additions! */
178 return !ASMIntAreEnabled();
179}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette