VirtualBox

Ignore:
Timestamp:
Mar 5, 2014 11:55:54 AM (11 years ago)
Author:
vboxsync
Message:

Darwin Additions: intoduced a dedicated workloop in VBoxGuest.kext in order to handle DevVMM interrupts.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-darwin.cpp

    r50699 r50701  
    124124    bool isVmmDev(IOPCIDevice *pIOPCIDevice);
    125125
     126protected:
     127    IOWorkLoop                *m_pWorkLoop;
     128
    126129public:
    127130    virtual bool start(IOService *pProvider);
    128131    virtual void stop(IOService *pProvider);
    129132    virtual bool terminate(IOOptionBits fOptions);
     133    IOWorkLoop * getWorkLoop();
    130134};
    131135
     
    223227static IONotifier          *g_pSleepNotifier    = NULL;
    224228
     229/* States of atimic variable aimed to protect dynamic object allocation in SMP environment. */
     230#define VBOXGUEST_OBJECT_UNINITIALIZED  (0)
     231#define VBOXGUEST_OBJECT_INITIALIZING   (1)
     232#define VBOXGUEST_OBJECT_INITIALIZED    (2)
     233#define VBOXGUEST_OBJECT_INVALID        (3)
     234/** Atomic variable used to protect work loop allocation when multiple threads attempt to obtain it. */
     235static uint8_t volatile     g_fWorkLoopCreated  = VBOXGUEST_OBJECT_UNINITIALIZED;
    225236
    226237
     
    660671 */
    661672
     673
     674IOWorkLoop *
     675org_virtualbox_VBoxGuest::getWorkLoop()
     676{
     677    /* Handle the case when work loop was not created yet */
     678    if(ASMAtomicCmpXchgU8(&g_fWorkLoopCreated, VBOXGUEST_OBJECT_INITIALIZING, VBOXGUEST_OBJECT_UNINITIALIZED))
     679    {
     680        m_pWorkLoop = IOWorkLoop::workLoop();
     681        if (m_pWorkLoop)
     682        {
     683            /* Notify the rest of threads about the fact that work
     684             * loop was successully allocated and can be safely used */
     685            PDEBUG("created new work loop\n");
     686            ASMAtomicWriteU8(&g_fWorkLoopCreated, VBOXGUEST_OBJECT_INITIALIZED);
     687        }
     688        else
     689        {
     690            /* Notify the rest of threads about the fact that there was
     691             * an error during allocation of a work loop */
     692            PDEBUG("unable new work loop\n");
     693            ASMAtomicWriteU8(&g_fWorkLoopCreated, VBOXGUEST_OBJECT_UNINITIALIZED);
     694        }
     695    }
     696    else
     697    {
     698        /* Handle the case when work loop is currently being
     699         * created or it was previously failed to create */
     700        uint8_t fWorkLoopCreated = VBOXGUEST_OBJECT_INVALID;
     701        while (fWorkLoopCreated != VBOXGUEST_OBJECT_INITIALIZED
     702            && fWorkLoopCreated != VBOXGUEST_OBJECT_UNINITIALIZED)
     703        {
     704            fWorkLoopCreated = ASMAtomicReadU8(&g_fWorkLoopCreated);
     705            thread_block(0);
     706        }
     707        if (fWorkLoopCreated == VBOXGUEST_OBJECT_INITIALIZED)
     708            PDEBUG("returned existing work loop");
     709        else
     710            PDEBUG("work loop was not allocated correctly");
     711    }
     712
     713    return m_pWorkLoop;
     714}
     715
     716
    662717/**
    663718 * Perform pending wake ups in work loop context.
     
    690745org_virtualbox_VBoxGuest::setupVmmDevInterrupts(IOService *pProvider)
    691746{
    692     IOWorkLoop *pWorkLoop = (IOWorkLoop *)getWorkLoop();
     747    IOWorkLoop *pWorkLoop = getWorkLoop();
    693748
    694749    if (!pWorkLoop)
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