VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/haiku/thread2-r0drv-haiku.c

Last change on this file was 98103, checked in by vboxsync, 17 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1/* $Id: thread2-r0drv-haiku.c 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * IPRT - Threads (Part 2), Ring-0 Driver, Haiku.
4 */
5
6/*
7 * Copyright (C) 2012-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include "the-haiku-kernel.h"
42#include "internal/iprt.h"
43#include <iprt/thread.h>
44
45#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
46#include <iprt/asm-amd64-x86.h>
47#endif
48#include <iprt/assert.h>
49#include <iprt/errcore.h>
50#include "internal/thread.h"
51
52
53DECLHIDDEN(int) rtThreadNativeInit(void)
54{
55 /* No TLS in Ring-0. :-/ */
56 return VINF_SUCCESS;
57}
58
59
60RTDECL(RTTHREAD) RTThreadSelf(void)
61{
62 return rtThreadGetByNative((RTNATIVETHREAD)find_thread(NULL));
63}
64
65
66DECLHIDDEN(int) rtThreadNativeSetPriority(PRTTHREADINT pThread, RTTHREADTYPE enmType)
67{
68 int32 iPriority;
69 status_t status;
70
71 /*
72 * Convert the priority type to native priorities.
73 * (This is quite naive but should be ok.)
74 */
75 switch (enmType)
76 {
77 case RTTHREADTYPE_INFREQUENT_POLLER: iPriority = B_LOWEST_ACTIVE_PRIORITY; break;
78 case RTTHREADTYPE_EMULATION: iPriority = B_LOW_PRIORITY; break;
79 case RTTHREADTYPE_DEFAULT: iPriority = B_NORMAL_PRIORITY; break;
80 case RTTHREADTYPE_MSG_PUMP: iPriority = B_DISPLAY_PRIORITY; break;
81 case RTTHREADTYPE_IO: iPriority = B_URGENT_DISPLAY_PRIORITY; break;
82 case RTTHREADTYPE_TIMER: iPriority = B_REAL_TIME_DISPLAY_PRIORITY; break;
83 default:
84 AssertMsgFailed(("enmType=%d\n", enmType));
85 return VERR_INVALID_PARAMETER;
86 }
87
88 status = set_thread_priority((thread_id)pThread->Core.Key, iPriority);
89
90 return RTErrConvertFromHaikuKernReturn(status);
91}
92
93
94DECLHIDDEN(int) rtThreadNativeAdopt(PRTTHREADINT pThread)
95{
96 return VERR_NOT_IMPLEMENTED;
97}
98
99
100DECLHIDDEN(void) rtThreadNativeWaitKludge(PRTTHREADINT pThread)
101{
102 /** @todo fix RTThreadWait/RTR0Term race on freebsd. */
103 RTThreadSleep(1);
104}
105
106
107DECLHIDDEN(void) rtThreadNativeDestroy(PRTTHREADINT pThread)
108{
109 NOREF(pThread);
110}
111
112
113/**
114 * Native kernel thread wrapper function.
115 *
116 * This will forward to rtThreadMain and do termination upon return.
117 *
118 * @param pvArg Pointer to the argument package.
119 * @param Ignored Wait result, which we ignore.
120 */
121static status_t rtThreadNativeMain(void *pvArg)
122{
123 const thread_id Self = find_thread(NULL);
124 PRTTHREADINT pThread = (PRTTHREADINT)pvArg;
125
126 int rc = rtThreadMain(pThread, (RTNATIVETHREAD)Self, &pThread->szName[0]);
127
128 if (rc < 0)
129 return RTErrConvertFromHaikuKernReturn(rc);
130 return rc;
131}
132
133
134DECLHIDDEN(int) rtThreadNativeCreate(PRTTHREADINT pThreadInt, PRTNATIVETHREAD pNativeThread)
135{
136 thread_id NativeThread;
137 RT_ASSERT_PREEMPTIBLE();
138
139 NativeThread = spawn_kernel_thread(rtThreadNativeMain, pThreadInt->szName, B_NORMAL_PRIORITY, pThreadInt);
140 if (NativeThread >= B_OK)
141 {
142 resume_thread(NativeThread);
143 *pNativeThread = (RTNATIVETHREAD)NativeThread;
144 return VINF_SUCCESS;
145 }
146 return RTErrConvertFromHaikuKernReturn(NativeThread);
147}
148
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use