VirtualBox

Changeset 21536 in vbox for trunk/src/VBox/Runtime/r0drv/os2


Ignore:
Timestamp:
Jul 13, 2009 2:49:39 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
50009
Message:

iprt/thread.h: Redefined RTThreadPreemptIsEnabled for systems without preemption (we keep count ourselves). Added RTThreadPreemptIsPossible and RTThreadIsInInterrupt. Fixed RTThreadPreemptIsEnabled on FreeBSD and Solaris/vbi.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/os2/thread-r0drv-os2.cpp

    r20124 r21536  
    3535
    3636#include <iprt/thread.h>
     37#include <iprt/asm.h>
     38#include <iprt/assert.h>
    3739#include <iprt/err.h>
    38 #include <iprt/assert.h>
    3940#include "internal/thread.h"
     41
     42
     43/*******************************************************************************
     44*   Global Variables                                                           *
     45*******************************************************************************/
     46/** Per-cpu preemption counters. */
     47static int32_t volatile g_acPreemptDisabled[256];
     48
    4049
    4150
     
    7887{
    7988    Assert(hThread == NIL_RTTHREAD);
    80     return false;
    81 }
    82 
    83 
    84 RTDECL(bool) RTThreadPreemptIsPendingTrusty(void)
    85 {
    86     /* yes, RTThreadPreemptIsPending is reliable. */
    87     return true;
     89    int32_t c = g_acPreemptDisabled[ASMGetApicId()];
     90    AssertMsg(c >= 0 && c < 32, ("%d\n", c));
     91    return c == 0
     92        && ASMIntAreEnabled();
    8893}
    8994
     
    112117
    113118
     119RTDECL(bool) RTThreadPreemptIsPendingTrusty(void)
     120{
     121    /* yes, RTThreadPreemptIsPending is reliable. */
     122    return true;
     123}
     124
     125
     126RTDECL(bool) RTThreadPreemptIsPossible(void)
     127{
     128    /* no kernel preemption on OS/2. */
     129    return false;
     130}
     131
     132
    114133RTDECL(void) RTThreadPreemptDisable(PRTTHREADPREEMPTSTATE pState)
    115134{
    116135    AssertPtr(pState);
    117     Assert(pState->uchDummy != 42);
    118     pState->uchDummy = 42;
    119     /* Nothing to do here as OS/2 doesn't preempt kernel threads. */
     136
     137    /* No preemption on OS/2, so do our own accounting. */
     138    int32_t c = ASMAtomicIncS32(&g_acPreemptDisabled[ASMGetApicId()]);
     139    AssertMsg(c > 0 && c < 32, ("%d\n", c));
     140    pState->uchDummy = (unsigned char)c;
    120141}
    121142
     
    124145{
    125146    AssertPtr(pState);
    126     Assert(pState->uchDummy == 42);
     147    AssertMsg(pState->uchDummy > 0 && pState->uchDummy < 32, ("%d\n", pState->uchDummy));
     148
     149    /* No preemption on OS/2, so do our own accounting. */
     150    int32_t volatile *pc = &g_acPreemptDisabled[ASMGetApicId()];
     151    AssertMsg(pState->uchDummy == (uint32_t)*pc, ("uchDummy=%d *pc=%d \n", pState->uchDummy, *pc));
     152    ASMAtomicUoWriteS32(pc, pState->uchDummy - 1);
    127153    pState->uchDummy = 0;
    128154}
    129155
     156
     157RTDECL(bool) RTThreadIsInInterrupt(RTTHREAD hThread)
     158{
     159    Assert(hThread == NIL_RTTHREAD); NOREF(hThread);
     160
     161    union
     162    {
     163        RTFAR16 fp;
     164        uint8_t cInterruptLevel;
     165    } u;
     166    /** @todo OS/2: verify the usage of DHGETDOSV_INTERRUPTLEV. */
     167    int rc = RTR0Os2DHQueryDOSVar(DHGETDOSV_INTERRUPTLEV, 0, &u.fp);
     168    AssertReturn(rc == 0, true);
     169
     170    return cInterruptLevel > 0;
     171}
     172
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette