VirtualBox

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

Last change on this file since 43974 was 42784, checked in by vboxsync, 12 years ago

Linux 3.6-rc1 compile fix, spaces

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.0 KB
Line 
1/* $Id: thread2-r0drv-linux.c 42784 2012-08-12 20:31:36Z 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
46DECLHIDDEN(int) rtThreadNativeInit(void)
47{
48 return VINF_SUCCESS;
49}
50
51
52DECLHIDDEN(int) rtThreadNativeSetPriority(PRTTHREADINT pThread, RTTHREADTYPE enmType)
53{
54#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
55 /* See comment near MAX_RT_PRIO in linux/sched.h for details on
56 sched_priority. */
57 int iSchedClass = SCHED_NORMAL;
58 struct sched_param Param = { .sched_priority = MAX_PRIO - 1 };
59 switch (enmType)
60 {
61 case RTTHREADTYPE_INFREQUENT_POLLER:
62 Param.sched_priority = MAX_RT_PRIO + 5;
63 break;
64
65 case RTTHREADTYPE_EMULATION:
66 Param.sched_priority = MAX_RT_PRIO + 4;
67 break;
68
69 case RTTHREADTYPE_DEFAULT:
70 Param.sched_priority = MAX_RT_PRIO + 3;
71 break;
72
73 case RTTHREADTYPE_MSG_PUMP:
74 Param.sched_priority = MAX_RT_PRIO + 2;
75 break;
76
77 case RTTHREADTYPE_IO:
78 iSchedClass = SCHED_FIFO;
79 Param.sched_priority = MAX_RT_PRIO - 1;
80 break;
81
82 case RTTHREADTYPE_TIMER:
83 iSchedClass = SCHED_FIFO;
84 Param.sched_priority = 1; /* not 0 just in case */
85 break;
86
87 default:
88 AssertMsgFailed(("enmType=%d\n", enmType));
89 return VERR_INVALID_PARAMETER;
90 }
91
92 sched_setscheduler(current, iSchedClass, &Param);
93#endif
94
95 return VINF_SUCCESS;
96}
97
98
99DECLHIDDEN(int) rtThreadNativeAdopt(PRTTHREADINT pThread)
100{
101 return VERR_NOT_IMPLEMENTED;
102}
103
104
105DECLHIDDEN(void) 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
129DECLHIDDEN(int) 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, "iprt-%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