VirtualBox

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

Last change on this file since 86669 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
Line 
1/* $Id: thread2-r0drv-netbsd.c 82968 2020-02-04 10:35:17Z 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-2020 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.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 knut st. osmundsen <[email protected]>
30 *
31 * Permission is hereby granted, free of charge, to any person
32 * obtaining a copy of this software and associated documentation
33 * files (the "Software"), to deal in the Software without
34 * restriction, including without limitation the rights to use,
35 * copy, modify, merge, publish, distribute, sublicense, and/or sell
36 * copies of the Software, and to permit persons to whom the
37 * Software is furnished to do so, subject to the following
38 * conditions:
39 *
40 * The above copyright notice and this permission notice shall be
41 * included in all copies or substantial portions of the Software.
42 *
43 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
44 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
45 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
46 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
47 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
48 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
49 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
50 * OTHER DEALINGS IN THE SOFTWARE.
51 */
52
53
54/*********************************************************************************************************************************
55* Header Files *
56*********************************************************************************************************************************/
57#include "the-netbsd-kernel.h"
58
59#include <iprt/thread.h>
60#include <iprt/errcore.h>
61#include <iprt/assert.h>
62
63#include "internal/thread.h"
64
65
66DECLHIDDEN(int) rtThreadNativeInit(void)
67{
68 return VINF_SUCCESS;
69}
70
71
72RTDECL(RTTHREAD) RTThreadSelf(void)
73{
74 return rtThreadGetByNative(RTThreadNativeSelf());
75}
76
77
78DECLHIDDEN(int) rtThreadNativeSetPriority(PRTTHREADINT pThread, RTTHREADTYPE enmType)
79{
80 int iPriority;
81
82 switch (enmType)
83 {
84 case RTTHREADTYPE_INFREQUENT_POLLER: iPriority = PZERO + 8; break;
85 case RTTHREADTYPE_EMULATION: iPriority = PZERO + 4; break;
86 case RTTHREADTYPE_DEFAULT: iPriority = PZERO; break;
87 case RTTHREADTYPE_MSG_PUMP: iPriority = PZERO - 4; break;
88 case RTTHREADTYPE_IO: iPriority = PRIBIO; break;
89 case RTTHREADTYPE_TIMER: iPriority = PSWP; break;
90 default:
91 AssertMsgFailed(("enmType=%d\n", enmType));
92 return VERR_INVALID_PARAMETER;
93 }
94
95 lwp_lock(curlwp);
96 lwp_changepri(curlwp, iPriority);
97 lwp_unlock(curlwp);
98
99 return VINF_SUCCESS;
100}
101
102
103DECLHIDDEN(int) rtThreadNativeAdopt(PRTTHREADINT pThread)
104{
105 NOREF(pThread);
106 /* There is nothing special that needs doing here, but the
107 user really better know what he's cooking. */
108 return VINF_SUCCESS;
109}
110
111
112DECLHIDDEN(void) rtThreadNativeWaitKludge(PRTTHREADINT pThread)
113{
114 /** @todo fix RTThreadWait/RTR0Term race on netbsd. */
115 RTThreadSleep(1);
116}
117
118
119DECLHIDDEN(void) rtThreadNativeDestroy(PRTTHREADINT pThread)
120{
121 NOREF(pThread);
122}
123
124
125/**
126 * Native thread main function.
127 *
128 * @param pvThreadInt The thread structure.
129 */
130static void rtThreadNativeMain(void *pvThreadInt)
131{
132 const struct lwp *Self = curlwp;
133 PRTTHREADINT pThreadInt = (PRTTHREADINT)pvThreadInt;
134 int rc;
135
136 rc = rtThreadMain(pThreadInt, (RTNATIVETHREAD)Self, &pThreadInt->szName[0]);
137
138 kthread_exit(rc);
139}
140
141
142DECLHIDDEN(int) rtThreadNativeCreate(PRTTHREADINT pThreadInt, PRTNATIVETHREAD pNativeThread)
143{
144 int rc;
145 struct lwp *l;
146
147 rc = kthread_create(PRI_NONE, 0, NULL, rtThreadNativeMain, (void *)pThreadInt, &l, "%s", pThreadInt->szName);
148
149 if (!rc)
150 {
151 *pNativeThread = (RTNATIVETHREAD)l;
152 rc = VINF_SUCCESS;
153 }
154 else
155 rc = RTErrConvertFromErrno(rc);
156 return rc;
157}
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