VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/netbsd/thread2-r0drv-netbsd.c@ 96407

Last change on this file since 96407 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1/* $Id: thread2-r0drv-netbsd.c 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 * IPRT - Threads (Part 2), Ring-0 Driver, NetBSD.
4 */
5
6/*
7 * Contributed by knut st. osmundsen.
8 *
9 * Copyright (C) 2007-2022 Oracle and/or its affiliates.
10 *
11 * This file is part of VirtualBox base platform packages, as
12 * available from https://www.virtualbox.org.
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation, in version 3 of the
17 * License.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see <https://www.gnu.org/licenses>.
26 *
27 * The contents of this file may alternatively be used under the terms
28 * of the Common Development and Distribution License Version 1.0
29 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
30 * in the VirtualBox distribution, in which case the provisions of the
31 * CDDL are applicable instead of those of the GPL.
32 *
33 * You may elect to license modified versions of this file under the
34 * terms and conditions of either the GPL or the CDDL or both.
35 *
36 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
37 * --------------------------------------------------------------------
38 *
39 * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
40 *
41 * Permission is hereby granted, free of charge, to any person
42 * obtaining a copy of this software and associated documentation
43 * files (the "Software"), to deal in the Software without
44 * restriction, including without limitation the rights to use,
45 * copy, modify, merge, publish, distribute, sublicense, and/or sell
46 * copies of the Software, and to permit persons to whom the
47 * Software is furnished to do so, subject to the following
48 * conditions:
49 *
50 * The above copyright notice and this permission notice shall be
51 * included in all copies or substantial portions of the Software.
52 *
53 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
54 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
55 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
56 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
57 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
58 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
59 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
60 * OTHER DEALINGS IN THE SOFTWARE.
61 */
62
63
64/*********************************************************************************************************************************
65* Header Files *
66*********************************************************************************************************************************/
67#include "the-netbsd-kernel.h"
68
69#include <iprt/thread.h>
70#include <iprt/errcore.h>
71#include <iprt/assert.h>
72
73#include "internal/thread.h"
74
75
76DECLHIDDEN(int) rtThreadNativeInit(void)
77{
78 return VINF_SUCCESS;
79}
80
81
82RTDECL(RTTHREAD) RTThreadSelf(void)
83{
84 return rtThreadGetByNative(RTThreadNativeSelf());
85}
86
87
88DECLHIDDEN(int) rtThreadNativeSetPriority(PRTTHREADINT pThread, RTTHREADTYPE enmType)
89{
90 int iPriority;
91
92 switch (enmType)
93 {
94 case RTTHREADTYPE_INFREQUENT_POLLER: iPriority = PZERO + 8; break;
95 case RTTHREADTYPE_EMULATION: iPriority = PZERO + 4; break;
96 case RTTHREADTYPE_DEFAULT: iPriority = PZERO; break;
97 case RTTHREADTYPE_MSG_PUMP: iPriority = PZERO - 4; break;
98 case RTTHREADTYPE_IO: iPriority = PRIBIO; break;
99 case RTTHREADTYPE_TIMER: iPriority = PSWP; break;
100 default:
101 AssertMsgFailed(("enmType=%d\n", enmType));
102 return VERR_INVALID_PARAMETER;
103 }
104
105 lwp_lock(curlwp);
106 lwp_changepri(curlwp, iPriority);
107 lwp_unlock(curlwp);
108
109 return VINF_SUCCESS;
110}
111
112
113DECLHIDDEN(int) rtThreadNativeAdopt(PRTTHREADINT pThread)
114{
115 NOREF(pThread);
116 /* There is nothing special that needs doing here, but the
117 user really better know what he's cooking. */
118 return VINF_SUCCESS;
119}
120
121
122DECLHIDDEN(void) rtThreadNativeWaitKludge(PRTTHREADINT pThread)
123{
124 /** @todo fix RTThreadWait/RTR0Term race on netbsd. */
125 RTThreadSleep(1);
126}
127
128
129DECLHIDDEN(void) rtThreadNativeDestroy(PRTTHREADINT pThread)
130{
131 NOREF(pThread);
132}
133
134
135/**
136 * Native thread main function.
137 *
138 * @param pvThreadInt The thread structure.
139 */
140static void rtThreadNativeMain(void *pvThreadInt)
141{
142 const struct lwp *Self = curlwp;
143 PRTTHREADINT pThreadInt = (PRTTHREADINT)pvThreadInt;
144 int rc;
145
146 rc = rtThreadMain(pThreadInt, (RTNATIVETHREAD)Self, &pThreadInt->szName[0]);
147
148 kthread_exit(rc);
149}
150
151
152DECLHIDDEN(int) rtThreadNativeCreate(PRTTHREADINT pThreadInt, PRTNATIVETHREAD pNativeThread)
153{
154 int rc;
155 struct lwp *l;
156
157 rc = kthread_create(PRI_NONE, 0, NULL, rtThreadNativeMain, (void *)pThreadInt, &l, "%s", pThreadInt->szName);
158
159 if (!rc)
160 {
161 *pNativeThread = (RTNATIVETHREAD)l;
162 rc = VINF_SUCCESS;
163 }
164 else
165 rc = RTErrConvertFromErrno(rc);
166 return rc;
167}
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