1 | /* $Id: thread2-r0drv-solaris.c 54362 2015-02-23 01:33:02Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Threads (Part 2), Ring-0 Driver, Solaris.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2014 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-solaris-kernel.h"
|
---|
32 | #include "internal/iprt.h"
|
---|
33 | #include <iprt/thread.h>
|
---|
34 | #include <iprt/process.h>
|
---|
35 |
|
---|
36 | #include <iprt/assert.h>
|
---|
37 | #include <iprt/err.h>
|
---|
38 | #include "internal/thread.h"
|
---|
39 |
|
---|
40 |
|
---|
41 |
|
---|
42 | DECLHIDDEN(int) rtThreadNativeInit(void)
|
---|
43 | {
|
---|
44 | return VINF_SUCCESS;
|
---|
45 | }
|
---|
46 |
|
---|
47 |
|
---|
48 | RTDECL(RTTHREAD) RTThreadSelf(void)
|
---|
49 | {
|
---|
50 | return rtThreadGetByNative(RTThreadNativeSelf());
|
---|
51 | }
|
---|
52 |
|
---|
53 |
|
---|
54 | DECLHIDDEN(int) rtThreadNativeSetPriority(PRTTHREADINT pThread, RTTHREADTYPE enmType)
|
---|
55 | {
|
---|
56 | int iPriority;
|
---|
57 | switch (enmType)
|
---|
58 | {
|
---|
59 | case RTTHREADTYPE_INFREQUENT_POLLER: iPriority = 60; break;
|
---|
60 | case RTTHREADTYPE_EMULATION: iPriority = 66; break;
|
---|
61 | case RTTHREADTYPE_DEFAULT: iPriority = 72; break;
|
---|
62 | case RTTHREADTYPE_MSG_PUMP: iPriority = 78; break;
|
---|
63 | case RTTHREADTYPE_IO: iPriority = 84; break;
|
---|
64 | case RTTHREADTYPE_TIMER: iPriority = 99; break;
|
---|
65 | default:
|
---|
66 | AssertMsgFailed(("enmType=%d\n", enmType));
|
---|
67 | return VERR_INVALID_PARAMETER;
|
---|
68 | }
|
---|
69 |
|
---|
70 | kthread_t *pCurThread = curthread;
|
---|
71 | Assert(pCurThread);
|
---|
72 | thread_lock(pCurThread);
|
---|
73 | thread_change_pri(pCurThread, iPriority, 0);
|
---|
74 | thread_unlock(pCurThread);
|
---|
75 | return VINF_SUCCESS;
|
---|
76 | }
|
---|
77 |
|
---|
78 |
|
---|
79 | DECLHIDDEN(int) rtThreadNativeAdopt(PRTTHREADINT pThread)
|
---|
80 | {
|
---|
81 | NOREF(pThread);
|
---|
82 | /* There is nothing special that needs doing here, but the
|
---|
83 | user really better know what he's cooking. */
|
---|
84 | return VINF_SUCCESS;
|
---|
85 | }
|
---|
86 |
|
---|
87 |
|
---|
88 | DECLHIDDEN(void) rtThreadNativeWaitKludge(PRTTHREADINT pThread)
|
---|
89 | {
|
---|
90 | thread_join(pThread->tid);
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 | DECLHIDDEN(void) rtThreadNativeDestroy(PRTTHREADINT pThread)
|
---|
95 | {
|
---|
96 | NOREF(pThread);
|
---|
97 | }
|
---|
98 |
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * Native thread main function.
|
---|
102 | *
|
---|
103 | * @param pvThreadInt The thread structure.
|
---|
104 | */
|
---|
105 | static void rtThreadNativeMain(void *pvThreadInt)
|
---|
106 | {
|
---|
107 | PRTTHREADINT pThreadInt = (PRTTHREADINT)pvThreadInt;
|
---|
108 |
|
---|
109 | /* thread_join takes the t_did value. There seems to be no interface for
|
---|
110 | retrieving t_did, so we have to gamble on the Solaris guys not messing
|
---|
111 | up its position in the _kthread struct. We access t_intr which is
|
---|
112 | 16 bytes earlier in the struct from semeventwait-r0drv-solaris.h, so
|
---|
113 | maybe we're lucky. Maybe, but experience indicates that the odds
|
---|
114 | are against us... */
|
---|
115 | pThreadInt->tid = curthread->t_did;
|
---|
116 |
|
---|
117 | rtThreadMain(pThreadInt, RTThreadNativeSelf(), &pThreadInt->szName[0]);
|
---|
118 | thread_exit();
|
---|
119 | }
|
---|
120 |
|
---|
121 |
|
---|
122 | DECLHIDDEN(int) rtThreadNativeCreate(PRTTHREADINT pThreadInt, PRTNATIVETHREAD pNativeThread)
|
---|
123 | {
|
---|
124 | kthread_t *pThread;
|
---|
125 | RT_ASSERT_PREEMPTIBLE();
|
---|
126 |
|
---|
127 | pThreadInt->tid = UINT64_MAX;
|
---|
128 |
|
---|
129 | pThread = thread_create(NULL, /* Stack, use base */
|
---|
130 | 0, /* Stack size */
|
---|
131 | rtThreadNativeMain, /* Thread function */
|
---|
132 | pThreadInt, /* Function data */
|
---|
133 | 0, /* Data size */
|
---|
134 | (proc_t *)RTR0ProcHandleSelf(), /* Process handle */
|
---|
135 | TS_RUN, /* Ready to run */
|
---|
136 | minclsyspri /* Priority */
|
---|
137 | );
|
---|
138 | if (RT_LIKELY(pThread))
|
---|
139 | {
|
---|
140 | *pNativeThread = (RTNATIVETHREAD)pThread;
|
---|
141 | return VINF_SUCCESS;
|
---|
142 | }
|
---|
143 |
|
---|
144 | return VERR_OUT_OF_RESOURCES;
|
---|
145 | }
|
---|
146 |
|
---|