VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/linux/thread-r0drv-linux.c@ 21337

Last change on this file since 21337 was 21337, checked in by vboxsync, 16 years ago

IPRT,HostDrv,AddDrv: Export public IPRT symbols for the linux kernel (pain).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.9 KB
Line 
1/* $Id: thread-r0drv-linux.c 21337 2009-07-07 14:58:27Z vboxsync $ */
2/** @file
3 * IPRT - Threads, Ring-0 Driver, Linux.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#include "the-linux-kernel.h"
36#include "internal/iprt.h"
37
38#include <iprt/thread.h>
39#include <iprt/err.h>
40#include <iprt/assert.h>
41
42
43RTDECL(RTNATIVETHREAD) RTThreadNativeSelf(void)
44{
45 return (RTNATIVETHREAD)current;
46}
47RT_EXPORT_SYMBOL(RTThreadNativeSelf);
48
49
50RTDECL(int) RTThreadSleep(unsigned cMillies)
51{
52 long cJiffies = msecs_to_jiffies(cMillies);
53 set_current_state(TASK_INTERRUPTIBLE);
54 cJiffies = schedule_timeout(cJiffies);
55 if (!cJiffies)
56 return VINF_SUCCESS;
57 return VERR_INTERRUPTED;
58}
59RT_EXPORT_SYMBOL(RTThreadSleep);
60
61
62RTDECL(bool) RTThreadYield(void)
63{
64#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 20)
65 yield();
66#else
67 set_current_state(TASK_RUNNING);
68 sys_sched_yield();
69 schedule();
70#endif
71 return true;
72}
73RT_EXPORT_SYMBOL(RTThreadYield);
74
75
76RTDECL(bool) RTThreadPreemptIsEnabled(RTTHREAD hThread)
77{
78 Assert(hThread == NIL_RTTHREAD);
79#ifdef CONFIG_PREEMPT
80# ifdef preemptible
81 return preemptible();
82# else
83 return preempt_count() == 0 && !in_atomic() && !irqs_disabled();
84# endif
85#else
86 return false;
87#endif
88}
89RT_EXPORT_SYMBOL(RTThreadPreemptIsEnabled);
90
91
92RTDECL(bool) RTThreadPreemptIsPending(RTTHREAD hThread)
93{
94 Assert(hThread == NIL_RTTHREAD);
95#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 4)
96 return test_tsk_thread_flag(current, TIF_NEED_RESCHED);
97
98#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 20)
99 return need_resched();
100
101#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 1, 110)
102 return current->need_resched != 0;
103
104#else
105 return need_resched != 0;
106#endif
107}
108RT_EXPORT_SYMBOL(RTThreadPreemptIsPending);
109
110
111RTDECL(bool) RTThreadPreemptIsPendingTrusty(void)
112{
113 /* yes, RTThreadPreemptIsPending is reliable. */
114 return true;
115}
116RT_EXPORT_SYMBOL(RTThreadPreemptIsPendingTrusty);
117
118
119RTDECL(void) RTThreadPreemptDisable(PRTTHREADPREEMPTSTATE pState)
120{
121 AssertPtr(pState);
122 Assert(pState->uchDummy != 42);
123 pState->uchDummy = 42;
124
125 /*
126 * Note: This call is a NOP if CONFIG_PREEMPT is not enabled in the Linux kernel
127 * configuration. In that case, schedule() is only called need_resched() is set
128 * which is tested just before we return to R3 (not when returning from R0 to R0).
129 */
130 preempt_disable();
131}
132RT_EXPORT_SYMBOL(RTThreadPreemptDisable);
133
134
135RTDECL(void) RTThreadPreemptRestore(PRTTHREADPREEMPTSTATE pState)
136{
137 AssertPtr(pState);
138 Assert(pState->uchDummy == 42);
139 pState->uchDummy = 0;
140
141 preempt_enable();
142}
143RT_EXPORT_SYMBOL(RTThreadPreemptRestore);
144
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