VirtualBox

Changeset 33166 in vbox


Ignore:
Timestamp:
Oct 15, 2010 6:09:39 PM (14 years ago)
Author:
vboxsync
Message:

semeventwait-r0drv-solaris.h: addressed a potential timeout race.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r0drv/solaris/semeventwait-r0drv-solaris.h

    r33152 r33166  
    7272    /** Cylic timer ID (used by the timeout callback). */
    7373    cyclic_id_t     idCy;
     74    /** The mutex associated with the condition variable wait. */
     75    void volatile  *pvMtx;
    7476} RTR0SEMSOLWAIT;
    7577/** Pointer to a solaris semaphore wait structure.  */
     
    160162    pWait->fInterruptible   = !!(fFlags & RTSEMWAIT_FLAGS_INTERRUPTIBLE);
    161163    pWait->pThread          = curthread;
     164    pWait->pvMtx            = NULL;
    162165    pWait->idCy             = CYCLIC_NONE;
    163166
     
    176179    PRTR0SEMSOLWAIT pWait   = (PRTR0SEMSOLWAIT)pvUser;
    177180    kthread_t      *pThread = pWait->pThread;
    178     if (VALID_PTR(pThread)) /* paranoia */
    179     {
    180         /* Note: Trying to take the cpu_lock here doesn't work. */
     181    kmutex_t       *pMtx    = (kmutex_t *)ASMAtomicReadPtr(&pWait->pvMtx);
     182    if (VALID_PTR(pMtx))
     183    {
     184        /* Enter the mutex here to make sure the thread has gone to sleep
     185           before we wake it up.
     186           Note: Trying to take the cpu_lock here doesn't work. */
     187        mutex_enter(pMtx);
    181188        if (mutex_owner(&cpu_lock) == curthread)
    182189        {
     
    185192        }
    186193        ASMAtomicWriteBool(&pWait->fTimedOut, true);
     194        mutex_exit(pMtx);
    187195        setrun(pThread);
    188196    }
     
    200208    PRTR0SEMSOLWAIT pWait   = (PRTR0SEMSOLWAIT)pvUser;
    201209    kthread_t      *pThread = pWait->pThread;
    202     if (VALID_PTR(pThread)) /* paranoia */
    203     {
     210    kmutex_t       *pMtx    = (kmutex_t *)ASMAtomicReadPtr(&pWait->pvMtx);
     211    if (VALID_PTR(pMtx))
     212    {
     213        /* Enter the mutex here to make sure the thread has gone to sleep
     214           before we wake it up. */
     215        mutex_enter(pMtx);
    204216        ASMAtomicWriteBool(&pWait->fTimedOut, true);
     217        mutex_exit(pMtx);
    205218        setrun(pThread);
    206219    }
     
    230243    if (fHasTimeout)
    231244    {
     245        ASMAtomicWritePtr(&pWait->pvMtx, pMtx); /* atomic is paranoia */
     246
    232247        if (pWait->fHighRes)
    233248        {
     
    294309    /*
    295310     * Remove the timeout callback.  Drop the lock while we're doing that
    296      * to reduce lock contention - we don't need it yet anyway.  (Too bad we
    297      * are stuck with the cv_* API here, it's doing a little bit too much.)
     311     * to reduce lock contention / deadlocks.  (Too bad we are stuck with the
     312     * cv_* API here, it's doing a little bit too much.)
    298313     */
    299314    if (fHasTimeout)
    300315    {
     316        ASMAtomicWritePtr(&pWait->pvMtx, NULL);
    301317        mutex_exit(pMtx);
    302318
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