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