VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/os2/thread-r0drv-os2.cpp@ 25240

Last change on this file since 25240 was 24287, checked in by vboxsync, 15 years ago

Made the common parts of the OS/2 additions build again.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.1 KB
Line 
1/* $Id: thread-r0drv-os2.cpp 24287 2009-11-03 12:34:11Z vboxsync $ */
2/** @file
3 * IPRT - Threads (Part 1), Ring-0 Driver, OS/2.
4 */
5
6/*
7 * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
8 *
9 * Permission is hereby granted, free of charge, to any person
10 * obtaining a copy of this software and associated documentation
11 * files (the "Software"), to deal in the Software without
12 * restriction, including without limitation the rights to use,
13 * copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following
16 * conditions:
17 *
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 * OTHER DEALINGS IN THE SOFTWARE.
29 */
30
31/*******************************************************************************
32* Header Files *
33*******************************************************************************/
34#include "the-os2-kernel.h"
35#include "internal/iprt.h"
36#include <iprt/thread.h>
37
38#include <iprt/asm.h>
39#include <iprt/assert.h>
40#include <iprt/err.h>
41#include <iprt/mp.h>
42#include "internal/thread.h"
43
44
45/*******************************************************************************
46* Global Variables *
47*******************************************************************************/
48/** Per-cpu preemption counters. */
49static int32_t volatile g_acPreemptDisabled[256];
50
51
52
53RTDECL(RTNATIVETHREAD) RTThreadNativeSelf(void)
54{
55 PLINFOSEG pLIS = (PLINFOSEG)RTR0Os2Virt2Flat(g_fpLIS);
56 AssertReturn(pLIS, NIL_RTNATIVETHREAD);
57 return pLIS->tidCurrent | (pLIS->pidCurrent << 16);
58}
59
60
61RTDECL(int) RTThreadSleep(unsigned cMillies)
62{
63 int rc = KernBlock((ULONG)RTThreadSleep,
64 cMillies == RT_INDEFINITE_WAIT ? SEM_INDEFINITE_WAIT : cMillies,
65 0, NULL, NULL);
66 switch (rc)
67 {
68 case NO_ERROR:
69 return VINF_SUCCESS;
70 case ERROR_TIMEOUT:
71 return VERR_TIMEOUT;
72 case ERROR_INTERRUPT:
73 return VERR_INTERRUPTED;
74 default:
75 AssertMsgFailed(("%d\n", rc));
76 return VERR_NO_TRANSLATION;
77 }
78}
79
80
81RTDECL(bool) RTThreadYield(void)
82{
83 /** @todo implement me (requires a devhelp) */
84 return false;
85}
86
87
88RTDECL(bool) RTThreadPreemptIsEnabled(RTTHREAD hThread)
89{
90 Assert(hThread == NIL_RTTHREAD);
91 int32_t c = g_acPreemptDisabled[ASMGetApicId()];
92 AssertMsg(c >= 0 && c < 32, ("%d\n", c));
93 return c == 0
94 && ASMIntAreEnabled();
95}
96
97
98RTDECL(bool) RTThreadPreemptIsPending(RTTHREAD hThread)
99{
100 Assert(hThread == NIL_RTTHREAD);
101
102 union
103 {
104 RTFAR16 fp;
105 uint8_t fResched;
106 } u;
107 int rc = RTR0Os2DHQueryDOSVar(DHGETDOSV_YIELDFLAG, 0, &u.fp);
108 AssertReturn(rc == 0, false);
109 if (u.fResched)
110 return true;
111
112 /** @todo Check if DHGETDOSV_YIELDFLAG includes TCYIELDFLAG. */
113 rc = RTR0Os2DHQueryDOSVar(DHGETDOSV_TCYIELDFLAG, 0, &u.fp);
114 AssertReturn(rc == 0, false);
115 if (u.fResched)
116 return true;
117 return false;
118}
119
120
121RTDECL(bool) RTThreadPreemptIsPendingTrusty(void)
122{
123 /* yes, RTThreadPreemptIsPending is reliable. */
124 return true;
125}
126
127
128RTDECL(bool) RTThreadPreemptIsPossible(void)
129{
130 /* no kernel preemption on OS/2. */
131 return false;
132}
133
134
135RTDECL(void) RTThreadPreemptDisable(PRTTHREADPREEMPTSTATE pState)
136{
137 AssertPtr(pState);
138 Assert(pState->u32Reserved == 0);
139
140 /* No preemption on OS/2, so do our own accounting. */
141 int32_t c = ASMAtomicIncS32(&g_acPreemptDisabled[ASMGetApicId()]);
142 AssertMsg(c > 0 && c < 32, ("%d\n", c));
143 pState->u32Reserved = c;
144 RT_ASSERT_PREEMPT_CPUID_DISABLE(pState);
145}
146
147
148RTDECL(void) RTThreadPreemptRestore(PRTTHREADPREEMPTSTATE pState)
149{
150 AssertPtr(pState);
151 AssertMsg(pState->u32Reserved > 0 && pState->u32Reserved < 32, ("%d\n", pState->u32Reserved));
152 RT_ASSERT_PREEMPT_CPUID_RESTORE(pState);
153
154 /* No preemption on OS/2, so do our own accounting. */
155 int32_t volatile *pc = &g_acPreemptDisabled[ASMGetApicId()];
156 AssertMsg(pState->u32Reserved == (uint32_t)*pc, ("uchDummy=%d *pc=%d \n", pState->u32Reserved, *pc));
157 ASMAtomicUoWriteS32(pc, pState->u32Reserved - 1);
158 pState->u32Reserved = 0;
159}
160
161
162RTDECL(bool) RTThreadIsInInterrupt(RTTHREAD hThread)
163{
164 Assert(hThread == NIL_RTTHREAD); NOREF(hThread);
165
166 union
167 {
168 RTFAR16 fp;
169 uint8_t cInterruptLevel;
170 } u;
171 /** @todo OS/2: verify the usage of DHGETDOSV_INTERRUPTLEV. */
172 int rc = RTR0Os2DHQueryDOSVar(DHGETDOSV_INTERRUPTLEV, 0, &u.fp);
173 AssertReturn(rc == 0, true);
174
175 return u.cInterruptLevel > 0;
176}
177
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