VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/freebsd/thread2-r0drv-freebsd.c@ 94293

Last change on this file since 94293 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1/* $Id: thread2-r0drv-freebsd.c 93115 2022-01-01 11:31:46Z vboxsync $ */
2/** @file
3 * IPRT - Threads (Part 2), Ring-0 Driver, FreeBSD.
4 */
5
6/*
7 * Contributed by knut st. osmundsen.
8 *
9 * Copyright (C) 2007-2022 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 * This code is based on:
30 *
31 * Copyright (c) 2007 knut st. osmundsen <[email protected]>
32 *
33 * Permission is hereby granted, free of charge, to any person
34 * obtaining a copy of this software and associated documentation
35 * files (the "Software"), to deal in the Software without
36 * restriction, including without limitation the rights to use,
37 * copy, modify, merge, publish, distribute, sublicense, and/or sell
38 * copies of the Software, and to permit persons to whom the
39 * Software is furnished to do so, subject to the following
40 * conditions:
41 *
42 * The above copyright notice and this permission notice shall be
43 * included in all copies or substantial portions of the Software.
44 *
45 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
46 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
47 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
48 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
49 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
50 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
51 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
52 * OTHER DEALINGS IN THE SOFTWARE.
53 */
54
55
56/*********************************************************************************************************************************
57* Header Files *
58*********************************************************************************************************************************/
59#include "the-freebsd-kernel.h"
60
61#include <iprt/thread.h>
62#include <iprt/errcore.h>
63#include <iprt/assert.h>
64
65#include "internal/thread.h"
66
67
68DECLHIDDEN(int) rtThreadNativeInit(void)
69{
70 return VINF_SUCCESS;
71}
72
73
74RTDECL(RTTHREAD) RTThreadSelf(void)
75{
76 return rtThreadGetByNative(RTThreadNativeSelf());
77}
78
79
80DECLHIDDEN(int) rtThreadNativeSetPriority(PRTTHREADINT pThread, RTTHREADTYPE enmType)
81{
82 int iPriority;
83
84 switch (enmType)
85 {
86 case RTTHREADTYPE_INFREQUENT_POLLER: iPriority = PZERO + 8; break;
87 case RTTHREADTYPE_EMULATION: iPriority = PZERO + 4; break;
88 case RTTHREADTYPE_DEFAULT: iPriority = PZERO; break;
89 case RTTHREADTYPE_MSG_PUMP: iPriority = PZERO - 4; break;
90 case RTTHREADTYPE_IO: iPriority = PRIBIO; break;
91 case RTTHREADTYPE_TIMER: iPriority = PRI_MIN_KERN; break;
92 default:
93 AssertMsgFailed(("enmType=%d\n", enmType));
94 return VERR_INVALID_PARAMETER;
95 }
96
97#if __FreeBSD_version < 700000
98 /* Do like they're doing in subr_ntoskrnl.c... */
99 mtx_lock_spin(&sched_lock);
100#else
101 thread_lock(curthread);
102#endif
103 sched_prio(curthread, iPriority);
104#if __FreeBSD_version < 600000
105 curthread->td_base_pri = iPriority;
106#endif
107#if __FreeBSD_version < 700000
108 mtx_unlock_spin(&sched_lock);
109#else
110 thread_unlock(curthread);
111#endif
112
113 return VINF_SUCCESS;
114}
115
116
117DECLHIDDEN(int) rtThreadNativeAdopt(PRTTHREADINT pThread)
118{
119 NOREF(pThread);
120 /* There is nothing special that needs doing here, but the
121 user really better know what he's cooking. */
122 return VINF_SUCCESS;
123}
124
125
126DECLHIDDEN(void) rtThreadNativeWaitKludge(PRTTHREADINT pThread)
127{
128 /** @todo fix RTThreadWait/RTR0Term race on freebsd. */
129 RTThreadSleep(1);
130}
131
132
133DECLHIDDEN(void) rtThreadNativeDestroy(PRTTHREADINT pThread)
134{
135 NOREF(pThread);
136}
137
138
139/**
140 * Native thread main function.
141 *
142 * @param pvThreadInt The thread structure.
143 */
144static void rtThreadNativeMain(void *pvThreadInt)
145{
146 const struct thread *Self = curthread;
147 PRTTHREADINT pThreadInt = (PRTTHREADINT)pvThreadInt;
148 int rc;
149
150 rc = rtThreadMain(pThreadInt, (RTNATIVETHREAD)Self, &pThreadInt->szName[0]);
151
152#if __FreeBSD_version >= 800002
153 kproc_exit(rc);
154#else
155 kthread_exit(rc);
156#endif
157}
158
159
160DECLHIDDEN(int) rtThreadNativeCreate(PRTTHREADINT pThreadInt, PRTNATIVETHREAD pNativeThread)
161{
162 int rc;
163 struct proc *pProc;
164
165#if __FreeBSD_version >= 800002
166 rc = kproc_create(rtThreadNativeMain, pThreadInt, &pProc, RFHIGHPID, 0, "%s", pThreadInt->szName);
167#else
168 rc = kthread_create(rtThreadNativeMain, pThreadInt, &pProc, RFHIGHPID, 0, "%s", pThreadInt->szName);
169#endif
170 if (!rc)
171 {
172 *pNativeThread = (RTNATIVETHREAD)FIRST_THREAD_IN_PROC(pProc);
173 rc = VINF_SUCCESS;
174 }
175 else
176 rc = RTErrConvertFromErrno(rc);
177 return rc;
178}
179
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