VirtualBox

Changeset 52413 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Aug 19, 2014 12:48:42 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
95585
Message:

VBoxSVC: resolve undesirable freeze on shutdown.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-all/EventImpl.cpp

    r50545 r52413  
    579579
    580580    RTSEMEVENT                    mQEvent;
     581    int32_t volatile              mWaitCnt;
    581582    RTCRITSECT                    mcsQLock;
    582583    PassiveQueue                  mQueue;
     
    725726                               BOOL aActive,
    726727                               EventSource *aOwner) :
    727     mActive(aActive), mOwner(aOwner), mRefCnt(0)
     728    mActive(aActive), mOwner(aOwner), mWaitCnt(0), mRefCnt(0)
    728729{
    729730    mListener = aListener;
     
    882883        // release lock while waiting, listener will not go away due to above holder
    883884        aAlock.release();
     885
     886        // In order to safely shutdown, count all waiting threads here.
     887        ASMAtomicIncS32(&mWaitCnt);
    884888        ::RTSemEventWait(mQEvent, aTimeout);
     889        ASMAtomicDecS32(&mWaitCnt);
     890
    885891        // reacquire lock
    886892        aAlock.acquire();
     
    918924        RTSEMEVENT tmp = mQEvent;
    919925        mQEvent = NIL_RTSEMEVENT;
     926
     927        /* On Darwin it is known that RTSemEventDestroy() returns 0 while
     928         * corresponding thread remains to be blocked after that. In order to prevent
     929         * undesireble freeze on shutdown, this workaround is used. */
     930        Log(("Wait for %d waiters to release.\n", ASMAtomicReadS32(&mWaitCnt)));
     931        while (ASMAtomicReadS32(&mWaitCnt) > 0)
     932        {
     933            ::RTSemEventSignal(tmp);
     934
     935            /* Are we already done? */
     936            if (ASMAtomicReadS32(&mWaitCnt) == 0)
     937                break;
     938
     939            RTThreadSleep(10);
     940        }
     941        Log(("All waiters just released the lock.\n"));
     942
    920943        ::RTSemEventDestroy(tmp);
    921944    }
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