VirtualBox

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


Ignore:
Timestamp:
Apr 30, 2008 2:29:20 PM (17 years ago)
Author:
vboxsync
Message:

Main/AutoLock: Added self deadlock detector (affects release builds too). Undef VBOX_MAIN_AUTOLOCK_TRAP in AutoLock.h to disable it.

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

Legend:

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

    r8424 r8508  
    2727{
    2828
     29
    2930RWLockHandle::RWLockHandle()
    3031{
     
    5354#endif /* VBOX_MAIN_USE_SEMRW */
    5455}
     56
    5557
    5658RWLockHandle::~RWLockHandle()
     
    6971}
    7072
     73
    7174bool RWLockHandle::isWriteLockOnCurrentThread() const
    7275{
     
    8588}
    8689
     90
    8791void RWLockHandle::lockWrite()
    8892{
     
    100104    if (mWriteLockThread != threadSelf)
    101105    {
     106# ifdef VBOX_MAIN_AUTOLOCK_TRAP
     107        if (mReadLockCount != 0)
     108        {
     109            ReaderMap::const_iterator reader = mReaders.find (threadSelf);
     110            if (reader != mReaders.end() && reader->second != 0)
     111            {
     112                AssertReleaseMsgFailedReturnVoid ((
     113                    "SELF DEADLOCK DETECTED on Thread %0x: lockWrite() after "
     114                    "lockRead(): reader count = %d!\n",
     115                    threadSelf, reader->second));
     116            }
     117        }
     118# endif /* VBOX_MAIN_AUTOLOCK_TRAP */
     119
    102120        if (mReadLockCount != 0 || mWriteLockThread != NIL_RTNATIVETHREAD ||
    103121            mWriteLockPending != 0 /* respect other pending writers */)
     
    127145}
    128146
     147
    129148void RWLockHandle::unlockWrite()
    130149{
     
    163182}
    164183
     184
    165185void RWLockHandle::lockRead()
    166186{
     
    175195
    176196    RTNATIVETHREAD threadSelf = RTThreadNativeSelf();
     197
     198# ifdef VBOX_MAIN_AUTOLOCK_TRAP
     199    if (!mReaders.count (threadSelf))
     200        mReaders [threadSelf] = 0;
     201    ++ mReaders [threadSelf];
     202# endif /* VBOX_MAIN_AUTOLOCK_TRAP */
    177203
    178204    bool isWriteLock = mWriteLockLevel != 0;
     
    223249}
    224250
     251
    225252void RWLockHandle::unlockRead()
    226253{
     
    248275            {
    249276                -- mSelfReadLockCount;
     277
     278# ifdef VBOX_MAIN_AUTOLOCK_TRAP
     279                -- mReaders [threadSelf];
     280# endif /* VBOX_MAIN_AUTOLOCK_TRAP */
    250281            }
    251282        }
     
    264295                    RTSemEventSignal (mGoWriteSem);
    265296            }
    266         }
    267     }
    268 
    269     RTCritSectLeave (&mCritSect);
    270 
    271 #endif /* VBOX_MAIN_USE_SEMRW */
    272 }
     297
     298# ifdef VBOX_MAIN_AUTOLOCK_TRAP
     299            -- mReaders [threadSelf];
     300# endif /* VBOX_MAIN_AUTOLOCK_TRAP */
     301        }
     302    }
     303
     304    RTCritSectLeave (&mCritSect);
     305
     306#endif /* VBOX_MAIN_USE_SEMRW */
     307}
     308
    273309
    274310uint32_t RWLockHandle::writeLockLevel() const
     
    287323}
    288324
     325
    289326} /* namespace util */
    290327
  • trunk/src/VBox/Main/include/AutoLock.h

    r8421 r8508  
    2323#define ____H_AUTOLOCK
    2424
     25/// @todo temporary
     26#define VBOX_MAIN_AUTOLOCK_TRAP
     27
    2528#include <iprt/cdefs.h>
    2629#include <iprt/types.h>
     
    3841#ifdef VBOX_MAIN_USE_SEMRW
    3942# include <iprt/semaphore.h>
     43#else
     44# ifdef VBOX_MAIN_AUTOLOCK_TRAP
     45#  include <map>
     46# endif
    4047#endif
    4148
     
    198205    uint32_t mWriteLockLevel;
    199206    uint32_t mWriteLockPending;
     207
     208# ifdef VBOX_MAIN_AUTOLOCK_TRAP
     209
     210    typedef std::map <RTNATIVETHREAD, uint32_t> ReaderMap;
     211    ReaderMap mReaders;
     212
     213# endif /* VBOX_MAIN_AUTOLOCK_TRAP */
    200214
    201215#endif /* VBOX_MAIN_USE_SEMRW */
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