VirtualBox

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

Last change on this file since 49221 was 43403, checked in by vboxsync, 12 years ago

r0drv/haiku: cleanup.

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