VirtualBox

Changeset 14412 in vbox for trunk


Ignore:
Timestamp:
Nov 20, 2008 1:27:06 PM (16 years ago)
Author:
vboxsync
Message:

semevent-linux.cpp: Use ASMAtomicCmpXchgExU32 to avoid doing unlocked accesses.

File:
1 edited

Legend:

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

    r10839 r14412  
    120120     * Invalidate the semaphore and wake up anyone waiting on it.
    121121     */
    122     ASMAtomicXchgSize(&pThis->iMagic, RTSEMEVENT_MAGIC + 1);
     122    ASMAtomicXchgSize(&pThis->iMagic, RTSEMEVENT_MAGIC | UINT32_C(0x80000000));
    123123    if (ASMAtomicXchgS32(&pThis->cWaiters, INT32_MIN / 2) > 0)
    124124    {
     
    148148    for (unsigned i = 0;; i++)
    149149    {
    150         int32_t iCur = pThis->cWaiters;
    151         if (iCur == 0)
    152         {
    153             if (ASMAtomicCmpXchgS32(&pThis->cWaiters, -1, 0))
    154                 break; /* nobody is waiting */
    155         }
     150        int32_t iCur;
     151        if (ASMAtomicCmpXchgExS32(&pThis->cWaiters, -1, 0, &iCur))
     152            break; /* nobody is waiting */
    156153        else if (iCur < 0)
    157154            break; /* already signaled */
     
    189186            }
    190187        }
     188
     189        /* Check the magic to fend off races with RTSemEventDestroy. */
     190        if (RT_UNLIKELY(pThis->iMagic != RTSEMEVENT_MAGIC))
     191            return VERR_SEM_DESTROYED;
    191192    }
    192193    return VINF_SUCCESS;
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