VirtualBox

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/linux/thread-r0drv-linux.c

    r21337 r21536  
    3737
    3838#include <iprt/thread.h>
     39#include <iprt/asm.h>
     40#include <iprt/assert.h>
    3941#include <iprt/err.h>
    40 #include <iprt/assert.h>
     42
     43
     44/*******************************************************************************
     45*   Global Variables                                                           *
     46*******************************************************************************/
     47#ifndef CONFIG_PREEMPT
     48/** Per-cpu preemption counters. */
     49static int32_t volatile g_acPreemptDisabled[NR_CPUS];
     50#endif
    4151
    4252
     
    7686RTDECL(bool) RTThreadPreemptIsEnabled(RTTHREAD hThread)
    7787{
     88#ifdef CONFIG_PREEMPT
    7889    Assert(hThread == NIL_RTTHREAD);
    79 #ifdef CONFIG_PREEMPT
    8090# ifdef preemptible
    8191    return preemptible();
     
    8494# endif
    8595#else
    86     return false;
     96    int32_t c;
     97
     98    Assert(hThread == NIL_RTTHREAD);
     99    c = g_acPreemptDisabled[smp_processor_id()];
     100    AssertMsg(c >= 0 && c < 32, ("%d\n", c));
     101    return c == 0 && !in_atomic() && !irqs_disabled();
    87102#endif
    88103}
     
    117132
    118133
     134RTDECL(bool) RTThreadPreemptIsPossible(void)
     135{
     136#ifdef CONFIG_PREEMPT
     137    return true;    /* yes, kernel preemption is possible. */
     138#else
     139    return false;   /* no kernel preemption */
     140#endif
     141}
     142RT_EXPORT_SYMBOL(RTThreadPreemptIsPossible);
     143
     144
    119145RTDECL(void) RTThreadPreemptDisable(PRTTHREADPREEMPTSTATE pState)
    120146{
     147#ifdef CONFIG_PREEMPT
    121148    AssertPtr(pState);
    122149    Assert(pState->uchDummy != 42);
    123150    pState->uchDummy = 42;
     151    preempt_disable();
    124152
    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();
     153#else /* !CONFIG_PREEMPT */
     154    int32_t c;
     155    AssertPtr(pState);
     156
     157    /* Do our own accounting. */
     158    c = ASMAtomicIncS32(&g_acPreemptDisabled[smp_processor_id()]);
     159    AssertMsg(c > 0 && c < 32, ("%d\n", c));
     160    pState->uchDummy = (unsigned char )c;
     161#endif
    131162}
    132163RT_EXPORT_SYMBOL(RTThreadPreemptDisable);
     
    135166RTDECL(void) RTThreadPreemptRestore(PRTTHREADPREEMPTSTATE pState)
    136167{
     168#ifdef CONFIG_PREEMPT
    137169    AssertPtr(pState);
    138170    Assert(pState->uchDummy == 42);
    139171    pState->uchDummy = 0;
     172    preempt_enable();
    140173
    141     preempt_enable();
     174#else
     175    int32_t volatile *pc;
     176    AssertPtr(pState);
     177    AssertMsg(pState->uchDummy > 0 && pState->uchDummy < 32, ("%d\n", pState->uchDummy));
     178
     179    /* Do our own accounting. */
     180    pc = &g_acPreemptDisabled[smp_processor_id()];
     181    AssertMsg(pState->uchDummy == (uint32_t)*pc, ("uchDummy=%d *pc=%d \n", pState->uchDummy, *pc));
     182    ASMAtomicUoWriteS32(pc, pState->uchDummy - 1);
     183#endif
    142184}
    143185RT_EXPORT_SYMBOL(RTThreadPreemptRestore);
    144186
     187
     188RTDECL(bool) RTThreadIsInInterrupt(RTTHREAD hThread)
     189{
     190    Assert(hThread == NIL_RTTHREAD); NOREF(hThread);
     191
     192    return in_interrupt() != 0;
     193}
     194RT_EXPORT_SYMBOL(RTThreadIsInInterrupt);
     195
Note: See TracChangeset for help on using the changeset viewer.

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