VirtualBox

Changeset 8421 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Apr 28, 2008 1:32:35 PM (17 years ago)
Author:
vboxsync
Message:

Main/AutoLock: Distinguish between the number of normal read locks and read locks nested into a write lock (to make sure the reader wait sempahore is properly reset before waiting on it).

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/AutoLock.cpp

    r8321 r8421  
    4646
    4747    mReadLockCount = 0;
     48    mSelfReadLockCount = 0;
     49
    4850    mWriteLockLevel = 0;
    4951    mWriteLockPending = 0;
     
    9496    RTCritSectEnter (&mCritSect);
    9597
    96     if (mWriteLockThread != RTThreadNativeSelf())
     98    RTNATIVETHREAD threadSelf = RTThreadNativeSelf();
     99
     100    if (mWriteLockThread != threadSelf)
    97101    {
    98102        if (mReadLockCount != 0 || mWriteLockThread != NIL_RTNATIVETHREAD ||
     
    110114        Assert (mWriteLockLevel == 0);
    111115        Assert (mWriteLockThread == NIL_RTNATIVETHREAD);
    112 
    113         mWriteLockThread = RTThreadNativeSelf();
     116        Assert (mSelfReadLockCount == 0 /* missing unlockRead()? */);
     117
     118        mWriteLockThread = threadSelf;
    114119    }
    115120
     
    139144        if (mWriteLockLevel == 0)
    140145        {
     146            Assert (mSelfReadLockCount == 0
     147                    /* mixed unlockWrite()/unlockRead() order? */);
     148
    141149            mWriteLockThread = NIL_RTNATIVETHREAD;
    142150
     
    166174    RTCritSectEnter (&mCritSect);
    167175
    168     ++ mReadLockCount;
    169     Assert (mReadLockCount != 0 /* read lock overflow? */);
     176    RTNATIVETHREAD threadSelf = RTThreadNativeSelf();
    170177
    171178    bool isWriteLock = mWriteLockLevel != 0;
    172179    bool isFirstReadLock = mReadLockCount == 1;
    173180
    174     if (isWriteLock && mWriteLockThread == RTThreadNativeSelf())
    175     {
    176         /* read lock nested into the write lock, cause return immediately */
     181    if (isWriteLock && mWriteLockThread == threadSelf)
     182    {
     183        /* read lock nested into the write lock */
     184        ++ mSelfReadLockCount;
     185        Assert (mSelfReadLockCount != 0 /* self read lock overflow? */);
     186
     187        /* cause to return immediately */
    177188        isWriteLock = false;
    178189    }
    179190    else
    180191    {
     192        ++ mReadLockCount;
     193        Assert (mReadLockCount != 0 /* read lock overflow? */);
     194
    181195        if (!isWriteLock)
    182196        {
     197            Assert (mSelfReadLockCount == 0 /* missing unlockRead()? */);
     198
    183199            /* write locks are top priority, so let them go if they are
    184200             * pending */
     
    218234    RTCritSectEnter (&mCritSect);
    219235
    220     Assert (mReadLockCount != 0 /* unlockRead() w/o preceding lockRead()? */);
    221     if (mReadLockCount != 0)
    222     {
    223         if (mWriteLockLevel != 0)
    224         {
    225             /* read unlock nested into the write lock, just decrease the
    226              * counter */
    227             Assert (mWriteLockThread == RTThreadNativeSelf()
    228                     /* unlockRead() after lockWrite()? */);
    229             if (mWriteLockThread == RTThreadNativeSelf())
    230                 -- mReadLockCount;
    231         }
    232         else
     236    RTNATIVETHREAD threadSelf = RTThreadNativeSelf();
     237
     238    if (mWriteLockLevel != 0)
     239    {
     240        /* read unlock nested into the write lock */
     241        Assert (mWriteLockThread == threadSelf
     242                /* unlockRead() after lockWrite()? */);
     243        if (mWriteLockThread == threadSelf)
     244        {
     245            Assert (mSelfReadLockCount != 0
     246                    /* unlockRead() w/o preceding lockRead()? */);
     247            if (mSelfReadLockCount != 0)
     248            {
     249                -- mSelfReadLockCount;
     250            }
     251        }
     252    }
     253    else
     254    {
     255        Assert (mReadLockCount != 0
     256                /* unlockRead() w/o preceding lockRead()? */);
     257        if (mReadLockCount != 0)
    233258        {
    234259            -- mReadLockCount;
  • trunk/src/VBox/Main/include/AutoLock.h

    r8321 r8421  
    193193    RTNATIVETHREAD mWriteLockThread;
    194194
    195     uint32_t mReadLockCount;
     195    uint32_t mReadLockCount;     /*< Number of read locks */
     196    uint32_t mSelfReadLockCount; /*< Number of read locks nested in write lock */
     197
    196198    uint32_t mWriteLockLevel;
    197199    uint32_t mWriteLockPending;
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