VirtualBox

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

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

IPRT: Some old OS/2 build fixes.

  • 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 33393 2010-10-24 16:17:00Z 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/asm-amd64-x86.h>
40#include <iprt/assert.h>
41#include <iprt/err.h>
42#include <iprt/mp.h>
43#include "internal/thread.h"
44
45
46/*******************************************************************************
47* Global Variables *
48*******************************************************************************/
49/** Per-cpu preemption counters. */
50static int32_t volatile g_acPreemptDisabled[256];
51
52
53
54RTDECL(RTNATIVETHREAD) RTThreadNativeSelf(void)
55{
56 PLINFOSEG pLIS = (PLINFOSEG)RTR0Os2Virt2Flat(g_fpLIS);
57 AssertReturn(pLIS, NIL_RTNATIVETHREAD);
58 return pLIS->tidCurrent | (pLIS->pidCurrent << 16);
59}
60
61
62RTDECL(int) RTThreadSleep(RTMSINTERVAL cMillies)
63{
64 int rc = KernBlock((ULONG)RTThreadSleep,
65 cMillies == RT_INDEFINITE_WAIT ? SEM_INDEFINITE_WAIT : cMillies,
66 0, NULL, NULL);
67 switch (rc)
68 {
69 case NO_ERROR:
70 return VINF_SUCCESS;
71 case ERROR_TIMEOUT:
72 return VERR_TIMEOUT;
73 case ERROR_INTERRUPT:
74 return VERR_INTERRUPTED;
75 default:
76 AssertMsgFailed(("%d\n", rc));
77 return VERR_NO_TRANSLATION;
78 }
79}
80
81
82RTDECL(bool) RTThreadYield(void)
83{
84 /** @todo implement me (requires a devhelp) */
85 return false;
86}
87
88
89RTDECL(bool) RTThreadPreemptIsEnabled(RTTHREAD hThread)
90{
91 Assert(hThread == NIL_RTTHREAD);
92 int32_t c = g_acPreemptDisabled[ASMGetApicId()];
93 AssertMsg(c >= 0 && c < 32, ("%d\n", c));
94 return c == 0
95 && ASMIntAreEnabled();
96}
97
98
99RTDECL(bool) RTThreadPreemptIsPending(RTTHREAD hThread)
100{
101 Assert(hThread == NIL_RTTHREAD);
102
103 union
104 {
105 RTFAR16 fp;
106 uint8_t fResched;
107 } u;
108 int rc = RTR0Os2DHQueryDOSVar(DHGETDOSV_YIELDFLAG, 0, &u.fp);
109 AssertReturn(rc == 0, false);
110 if (u.fResched)
111 return true;
112
113 /** @todo Check if DHGETDOSV_YIELDFLAG includes TCYIELDFLAG. */
114 rc = RTR0Os2DHQueryDOSVar(DHGETDOSV_TCYIELDFLAG, 0, &u.fp);
115 AssertReturn(rc == 0, false);
116 if (u.fResched)
117 return true;
118 return false;
119}
120
121
122RTDECL(bool) RTThreadPreemptIsPendingTrusty(void)
123{
124 /* yes, RTThreadPreemptIsPending is reliable. */
125 return true;
126}
127
128
129RTDECL(bool) RTThreadPreemptIsPossible(void)
130{
131 /* no kernel preemption on OS/2. */
132 return false;
133}
134
135
136RTDECL(void) RTThreadPreemptDisable(PRTTHREADPREEMPTSTATE pState)
137{
138 AssertPtr(pState);
139 Assert(pState->u32Reserved == 0);
140
141 /* No preemption on OS/2, so do our own accounting. */
142 int32_t c = ASMAtomicIncS32(&g_acPreemptDisabled[ASMGetApicId()]);
143 AssertMsg(c > 0 && c < 32, ("%d\n", c));
144 pState->u32Reserved = c;
145 RT_ASSERT_PREEMPT_CPUID_DISABLE(pState);
146}
147
148
149RTDECL(void) RTThreadPreemptRestore(PRTTHREADPREEMPTSTATE pState)
150{
151 AssertPtr(pState);
152 AssertMsg(pState->u32Reserved > 0 && pState->u32Reserved < 32, ("%d\n", pState->u32Reserved));
153 RT_ASSERT_PREEMPT_CPUID_RESTORE(pState);
154
155 /* No preemption on OS/2, so do our own accounting. */
156 int32_t volatile *pc = &g_acPreemptDisabled[ASMGetApicId()];
157 AssertMsg(pState->u32Reserved == (uint32_t)*pc, ("uchDummy=%d *pc=%d \n", pState->u32Reserved, *pc));
158 ASMAtomicUoWriteS32(pc, pState->u32Reserved - 1);
159 pState->u32Reserved = 0;
160}
161
162
163RTDECL(bool) RTThreadIsInInterrupt(RTTHREAD hThread)
164{
165 Assert(hThread == NIL_RTTHREAD); NOREF(hThread);
166
167 union
168 {
169 RTFAR16 fp;
170 uint8_t cInterruptLevel;
171 } u;
172 /** @todo OS/2: verify the usage of DHGETDOSV_INTERRUPTLEV. */
173 int rc = RTR0Os2DHQueryDOSVar(DHGETDOSV_INTERRUPTLEV, 0, &u.fp);
174 AssertReturn(rc == 0, true);
175
176 return u.cInterruptLevel > 0;
177}
178
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