VirtualBox

Changeset 6731 in vbox


Ignore:
Timestamp:
Feb 1, 2008 7:34:27 PM (17 years ago)
Author:
vboxsync
Message:

Fix bug in mutex semaphore reimplementation without pthreads. The releasing of the semaphore was incorrectly using non-atomic operations. Also removed the unneeded setting of the mutex state on timeout, and told the compiler about how to optimize the control flow. Still disabled, as there is no testcase.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/linux/sems-linux.cpp

    r6727 r6731  
    866866    int32_t iOld;
    867867    ASMAtomicCmpXchgExS32(&pIntMutexSem->iState, 1, 0, &iOld);
    868     if (iOld != 0)
    869     {
    870         iOld = ASMAtomicXchgS32(&pIntMutexSem->iState, 2);
    871         while (iOld != 0)
    872         {
     868    if (RT_UNLIKELY(iOld != 0))
     869    {
     870        iOld = ASMAtomicXchgS32(&pIntMutexSem->iState, 2);
     871        while (iOld != 0)
     872        {
    873873            /*
    874874             * Go to sleep.
     
    884884            {
    885885                Assert(pTimeout);
    886                 iOld = ASMAtomicXchgS32(&pIntMutexSem->iState, 2);
    887886                return VERR_TIMEOUT;
    888887            }
    889             if (rc == 0)
    890                 /* we'll leave the loop now unless another thread is faster */;
     888            if (rc == 0)
     889                /* we'll leave the loop now unless another thread is faster */;
    891890            else if (rc == -EWOULDBLOCK)
    892891                /* retry with new value. */;
     
    903902            }
    904903
    905             iOld = ASMAtomicXchgS32(&pIntMutexSem->iState, 2);
    906         }
     904            iOld = ASMAtomicXchgS32(&pIntMutexSem->iState, 2);
     905        }
    907906    }
    908907
     
    976975    {
    977976        /* somebody is waiting, try wake up one of them. */
    978         pIntMutexSem->iState = 0;
     977        ASMAtomicXchgS32(&pIntMutexSem->iState, 0);
    979978        (void)sys_futex(&pIntMutexSem->iState, FUTEX_WAKE, 1, NULL, NULL, 0);
    980979    }
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