VirtualBox

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

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

Copyright year updates by scm.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 5.5 KB
 
1/* $Id: thread-r0drv-netbsd.c 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * IPRT - Threads (Part 1), Ring-0 Driver, NetBSD.
4 */
5
6/*
7 * Contributed by knut st. osmundsen.
8 *
9 * Copyright (C) 2007-2020 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.alldomusa.eu.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 *
19 * The contents of this file may alternatively be used under the terms
20 * of the Common Development and Distribution License Version 1.0
21 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
22 * VirtualBox OSE distribution, in which case the provisions of the
23 * CDDL are applicable instead of those of the GPL.
24 *
25 * You may elect to license modified versions of this file under the
26 * terms and conditions of either the GPL or the CDDL or both.
27 * --------------------------------------------------------------------
28 *
29 * Copyright (C) 2007-2019 Oracle Corporation
30 *
31 * This file is part of VirtualBox Open Source Edition (OSE), as
32 * available from http://www.alldomusa.eu.org. This file is free software;
33 * you can redistribute it and/or modify it under the terms of the GNU
34 * General Public License (GPL) as published by the Free Software
35 * Foundation, in version 2 as it comes in the "COPYING" file of the
36 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
37 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
38 *
39 * The contents of this file may alternatively be used under the terms
40 * of the Common Development and Distribution License Version 1.0
41 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
42 * VirtualBox OSE distribution, in which case the provisions of the
43 * CDDL are applicable instead of those of the GPL.
44 *
45 * You may elect to license modified versions of this file under the
46 * terms and conditions of either the GPL or the CDDL or both.
47 */
48
49
50/*********************************************************************************************************************************
51* Header Files *
52*********************************************************************************************************************************/
53#include "the-netbsd-kernel.h"
54#include "internal/iprt.h"
55#include <iprt/thread.h>
56
57#include <iprt/asm.h>
58#include <iprt/asm-amd64-x86.h>
59#include <iprt/assert.h>
60#include <iprt/err.h>
61#include <iprt/mp.h>
62#include "internal/thread.h"
63
64
65RTDECL(RTNATIVETHREAD) RTThreadNativeSelf(void)
66{
67 return (RTNATIVETHREAD)curlwp;
68}
69
70
71static int rtR0ThreadNbsdSleepCommon(RTMSINTERVAL cMillies)
72{
73 int rc;
74 int cTicks;
75
76 /*
77 * 0 ms sleep -> yield.
78 */
79 if (!cMillies)
80 {
81 RTThreadYield();
82 return VINF_SUCCESS;
83 }
84
85 /*
86 * Translate milliseconds into ticks and go to sleep.
87 */
88 if (cMillies != RT_INDEFINITE_WAIT)
89 {
90 if (hz == 1000)
91 cTicks = cMillies;
92 else if (hz == 100)
93 cTicks = cMillies / 10;
94 else
95 {
96 int64_t cTicks64 = ((uint64_t)cMillies * hz) / 1000;
97 cTicks = (int)cTicks64;
98 if (cTicks != cTicks64)
99 cTicks = INT_MAX;
100 }
101 }
102 else
103 cTicks = 0; /* requires giant lock! */
104
105 rc = tsleep((void *)RTThreadSleep,
106 PZERO | PCATCH,
107 "iprtsl", /* max 6 chars */
108 cTicks);
109 switch (rc)
110 {
111 case 0:
112 return VINF_SUCCESS;
113 case EWOULDBLOCK:
114 return VERR_TIMEOUT;
115 case EINTR:
116 case ERESTART:
117 return VERR_INTERRUPTED;
118 default:
119 AssertMsgFailed(("%d\n", rc));
120 return VERR_NO_TRANSLATION;
121 }
122}
123
124
125RTDECL(int) RTThreadSleep(RTMSINTERVAL cMillies)
126{
127 return rtR0ThreadNbsdSleepCommon(cMillies);
128}
129
130
131RTDECL(int) RTThreadSleepNoLog(RTMSINTERVAL cMillies)
132{
133 return rtR0ThreadNbsdSleepCommon(cMillies);
134}
135
136
137RTDECL(bool) RTThreadYield(void)
138{
139 yield();
140 return true;
141}
142
143
144RTDECL(bool) RTThreadPreemptIsEnabled(RTTHREAD hThread)
145{
146 Assert(hThread == NIL_RTTHREAD);
147
148 return curlwp->l_dopreempt == 0
149 && ASMIntAreEnabled(); /** @todo is there a native netbsd function/macro for this? */
150}
151
152
153RTDECL(bool) RTThreadPreemptIsPending(RTTHREAD hThread)
154{
155 Assert(hThread == NIL_RTTHREAD);
156
157 return curlwp->l_dopreempt;
158}
159
160
161RTDECL(bool) RTThreadPreemptIsPendingTrusty(void)
162{
163 /* yes, RTThreadPreemptIsPending is reliable. */
164 return true;
165}
166
167
168RTDECL(bool) RTThreadPreemptIsPossible(void)
169{
170 /* yes, kernel preemption is possible. */
171 return true;
172}
173
174
175RTDECL(void) RTThreadPreemptDisable(PRTTHREADPREEMPTSTATE pState)
176{
177 AssertPtr(pState);
178
179 curlwp->l_nopreempt++;
180 __insn_barrier();
181}
182
183
184RTDECL(void) RTThreadPreemptRestore(PRTTHREADPREEMPTSTATE pState)
185{
186 AssertPtr(pState);
187 __insn_barrier();
188 if (--curlwp->l_nopreempt != 0)
189 return;
190 __insn_barrier();
191 if (__predict_false(curlwp->l_dopreempt))
192 kpreempt(0);
193 __insn_barrier();
194}
195
196
197RTDECL(bool) RTThreadIsInInterrupt(RTTHREAD hThread)
198{
199 Assert(hThread == NIL_RTTHREAD); NOREF(hThread);
200 /** @todo NetBSD: Implement RTThreadIsInInterrupt. Required for guest
201 * additions! */
202 return !ASMIntAreEnabled();
203}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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