VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/linux/thread2-r0drv-linux.c@ 36378

Last change on this file since 36378 was 36378, checked in by vboxsync, 14 years ago

thread2-r0drv-linux.c: Missing break in the RTTHREADTYPE_TIMER case. Style cleanups.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.9 KB
Line 
1/* $Id: thread2-r0drv-linux.c 36378 2011-03-23 17:48:42Z vboxsync $ */
2/** @file
3 * IPRT - Threads (Part 2), Ring-0 Driver, Linux.
4 */
5
6/*
7 * Copyright (C) 2006-2011 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-linux-kernel.h"
32#include "internal/iprt.h"
33
34#include <iprt/assert.h>
35#include <iprt/thread.h>
36#include <iprt/err.h>
37#include "internal/thread.h"
38
39
40RTDECL(RTTHREAD) RTThreadSelf(void)
41{
42 return rtThreadGetByNative((RTNATIVETHREAD)current);
43}
44
45
46int rtThreadNativeInit(void)
47{
48 return VINF_SUCCESS;
49}
50
51
52int rtThreadNativeSetPriority(PRTTHREADINT pThread, RTTHREADTYPE enmType)
53{
54 /* See comment near MAX_RT_PRIO in linux/sched.h for details on
55 sched_priority. */
56 int iSchedClass = SCHED_NORMAL;
57 struct sched_param Param = { .sched_priority = MAX_PRIO - 1 };
58 switch (enmType)
59 {
60 case RTTHREADTYPE_INFREQUENT_POLLER:
61 Param.sched_priority = MAX_RT_PRIO + 5;
62 break;
63
64 case RTTHREADTYPE_EMULATION:
65 Param.sched_priority = MAX_RT_PRIO + 4;
66 break;
67
68 case RTTHREADTYPE_DEFAULT:
69 Param.sched_priority = MAX_RT_PRIO + 3;
70 break;
71
72 case RTTHREADTYPE_MSG_PUMP:
73 Param.sched_priority = MAX_RT_PRIO + 2;
74 break;
75
76 case RTTHREADTYPE_IO:
77 iSchedClass = SCHED_FIFO;
78 Param.sched_priority = MAX_RT_PRIO - 1;
79 break;
80
81 case RTTHREADTYPE_TIMER:
82 iSchedClass = SCHED_FIFO;
83 Param.sched_priority = 1; /* not 0 just in case */
84 break;
85
86 default:
87 AssertMsgFailed(("enmType=%d\n", enmType));
88 return VERR_INVALID_PARAMETER;
89 }
90
91#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11)
92 sched_setscheduler(current, iSchedClass, &Param);
93#endif
94
95 return VINF_SUCCESS;
96}
97
98
99int rtThreadNativeAdopt(PRTTHREADINT pThread)
100{
101 return VERR_NOT_IMPLEMENTED;
102}
103
104
105void rtThreadNativeDestroy(PRTTHREADINT pThread)
106{
107 NOREF(pThread);
108}
109
110
111#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 4)
112/**
113 * Native kernel thread wrapper function.
114 *
115 * This will forward to rtThreadMain and do termination upon return.
116 *
117 * @param pvArg Pointer to the argument package.
118 */
119static int rtThreadNativeMain(void *pvArg)
120{
121 PRTTHREADINT pThread = (PRTTHREADINT)pvArg;
122
123 rtThreadMain(pThread, (RTNATIVETHREAD)current, &pThread->szName[0]);
124 return 0;
125}
126#endif
127
128
129int rtThreadNativeCreate(PRTTHREADINT pThreadInt, PRTNATIVETHREAD pNativeThread)
130{
131#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 4)
132 struct task_struct *NativeThread;
133
134 RT_ASSERT_PREEMPTIBLE();
135
136 NativeThread = kthread_run(rtThreadNativeMain, pThreadInt, "vbox-%s", pThreadInt->szName);
137
138 if (IS_ERR(NativeThread))
139 return VERR_GENERAL_FAILURE;
140
141 *pNativeThread = (RTNATIVETHREAD)NativeThread;
142 return VINF_SUCCESS;
143#else
144 return VERR_NOT_IMPLEMENTED;
145#endif
146}
147
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