VirtualBox

Changeset 25834 in vbox for trunk/src/VBox/Main/glue


Ignore:
Timestamp:
Jan 14, 2010 4:21:05 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
56614
Message:

Main: finish integration of Main lock validation with IPRT; only enabled with VBOX_WITH_STRICT_LOCKS=1 (do NOT enable unless you want Main to stop working now)

File:
1 edited

Legend:

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

    r25813 r25834  
    4141#include <vector>
    4242#include <list>
     43#include <map>
    4344
    4445namespace util
     
    5152////////////////////////////////////////////////////////////////////////////////
    5253
    53 class RuntimeLockClass
    54 {
    55 };
     54#ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
     55typedef std::map<VBoxLockingClass, RTLOCKVALCLASS> LockValidationClassesMap;
     56LockValidationClassesMap g_mapLockValidationClasses;
     57#endif
    5658
    5759/**
     
    6163void InitAutoLockSystem()
    6264{
    63     RTPrintf("InitAutoLockSystem\n");
     65#ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
     66    struct
     67    {
     68        VBoxLockingClass    cls;
     69        const char          *pcszDescription;
     70    } aClasses[] =
     71    {
     72        { LOCKCLASS_VIRTUALBOXOBJECT, "1-VIRTUALBOXOBJECT" },
     73        { LOCKCLASS_VIRTUALBOXLIST,   "2-VIRTUALBOXLIST" },
     74        { LOCKCLASS_USBPROXYSERVICE,  "3-USBPROXYSERVICE" },
     75        { LOCKCLASS_HOSTOBJECT,       "4-HOSTOBJECT" },
     76        { LOCKCLASS_HOSTLIST,         "5-HOSTLIST" },
     77        { LOCKCLASS_OTHEROBJECT,      "6-OTHEROBJECT" },
     78        { LOCKCLASS_OTHERLIST,        "7-OTHERLIST" },
     79        { LOCKCLASS_OBJECTSTATE,      "8-OBJECTSTATE" }
     80    };
     81
     82    RTLOCKVALCLASS hClass;
     83    int vrc;
     84    for (unsigned i = 0; i < RT_ELEMENTS(aClasses); ++i)
     85    {
     86        vrc = RTLockValidatorClassCreate(&hClass,
     87                                         true, /*fAutodidact*/
     88                                         RT_SRC_POS,
     89                                         aClasses[i].pcszDescription);
     90        AssertRC(vrc);
     91
     92        // teach the new class that the classes created previously can be held
     93        // while the new class is being acquired
     94        for (LockValidationClassesMap::iterator it = g_mapLockValidationClasses.begin();
     95             it != g_mapLockValidationClasses.end();
     96             ++it)
     97        {
     98            RTLOCKVALCLASS &canBeHeld = it->second;
     99            vrc = RTLockValidatorClassAddPriorClass(hClass,
     100                                                    canBeHeld);
     101            AssertRC(vrc);
     102        }
     103
     104        // and store the new class
     105        g_mapLockValidationClasses[aClasses[i].cls] = hClass;
     106    }
     107
     108/*    WriteLockHandle critsect1(LOCKCLASS_VIRTUALBOXOBJECT);
     109    WriteLockHandle critsect2(LOCKCLASS_VIRTUALBOXLIST);
     110
     111    AutoWriteLock lock1(critsect1 COMMA_LOCKVAL_SRC_POS);
     112    AutoWriteLock lock2(critsect2 COMMA_LOCKVAL_SRC_POS);*/
     113#endif
    64114}
    65115
     
    76126
    77127    RTSEMRW                     sem;
    78     MainLockValidationClasses   lockClass;
    79 
    80 #ifdef RT_LOCK_STRICT
     128    VBoxLockingClass   lockClass;
     129
     130#ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
    81131    com::Utf8Str                strDescription;
    82132#endif
    83133};
    84134
    85 RWLockHandle::RWLockHandle(MainLockValidationClasses lockClass)
     135RWLockHandle::RWLockHandle(VBoxLockingClass lockClass)
    86136{
    87137    m = new Data();
     
    89139    m->lockClass = lockClass;
    90140
    91     int vrc = RTSemRWCreateEx(&m->sem, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, NULL);
     141#ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
     142    m->strDescription = com::Utf8StrFmt("r/w %RCv", this);
     143    int vrc = RTSemRWCreateEx(&m->sem, 0 /*fFlags*/, g_mapLockValidationClasses[lockClass], RTLOCKVAL_SUB_CLASS_ANY, NULL);
     144#else
     145    int vrc = RTSemRWCreateEx(&m->sem, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_ANY, NULL);
     146#endif
    92147    AssertRC(vrc);
    93 
    94 #ifdef RT_LOCK_STRICT
    95     m->strDescription = com::Utf8StrFmt("r/w %RCv", this);
    96 #endif
    97148}
    98149
     
    110161/*virtual*/ void RWLockHandle::lockWrite(LOCKVAL_SRC_POS_DECL)
    111162{
    112 #if defined(RT_LOCK_STRICT)
     163#ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
    113164    int vrc = RTSemRWRequestWriteDebug(m->sem, RT_INDEFINITE_WAIT, (uintptr_t)ASMReturnAddress(), RT_SRC_POS_ARGS);
    114165#else
     
    127178/*virtual*/ void RWLockHandle::lockRead(LOCKVAL_SRC_POS_DECL)
    128179{
    129 #if defined(RT_LOCK_STRICT)
     180#ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
    130181    int vrc = RTSemRWRequestReadDebug(m->sem, RT_INDEFINITE_WAIT, (uintptr_t)ASMReturnAddress(), RT_SRC_POS_ARGS);
    131182#else
     
    147198}
    148199
    149 #ifdef RT_LOCK_STRICT
     200#ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
    150201/*virtual*/ const char* RWLockHandle::describe() const
    151202{
     
    166217
    167218    mutable RTCRITSECT          sem;
    168     MainLockValidationClasses   lockClass;
    169 
    170 #ifdef RT_LOCK_STRICT
     219    VBoxLockingClass   lockClass;
     220
     221#ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
    171222    com::Utf8Str                strDescription;
    172223#endif
    173224};
    174225
    175 WriteLockHandle::WriteLockHandle(MainLockValidationClasses lockClass)
     226WriteLockHandle::WriteLockHandle(VBoxLockingClass lockClass)
    176227{
    177228    m = new Data;
     
    179230    m->lockClass = lockClass;
    180231
    181     int vrc = RTCritSectInitEx(&m->sem, 0/*fFlags*/, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, NULL);
     232#ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
     233    m->strDescription = com::Utf8StrFmt("crit %RCv", this);
     234    int vrc = RTCritSectInitEx(&m->sem, 0/*fFlags*/, g_mapLockValidationClasses[lockClass], RTLOCKVAL_SUB_CLASS_ANY, NULL);
     235#else
     236    int vrc = RTCritSectInitEx(&m->sem, 0/*fFlags*/, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_ANY, NULL);
     237#endif
    182238    AssertRC(vrc);
    183 
    184 #ifdef RT_LOCK_STRICT
    185     m->strDescription = com::Utf8StrFmt("crit %RCv", this);
    186 #endif
    187239}
    188240
     
    200252/*virtual*/ void WriteLockHandle::lockWrite(LOCKVAL_SRC_POS_DECL)
    201253{
    202 #if defined(RT_LOCK_STRICT)
     254#ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
    203255    RTCritSectEnterDebug(&m->sem, (uintptr_t)ASMReturnAddress(), RT_SRC_POS_ARGS);
    204256#else
     
    227279}
    228280
    229 #ifdef RT_LOCK_STRICT
     281#ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
    230282/*virtual*/ const char* WriteLockHandle::describe() const
    231283{
     
    246298{
    247299    Data(size_t cHandles
    248 #ifdef RT_LOCK_STRICT
     300#ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
    249301         , const char *pcszFile_,
    250302         unsigned uLine_,
     
    255307          aHandles(cHandles),       // size of array
    256308          acUnlockedInLeave(cHandles)
    257 #ifdef RT_LOCK_STRICT
     309#ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
    258310          , pcszFile(pcszFile_),
    259311          uLine(uLine_),
     
    275327    CountsVector    acUnlockedInLeave;  // for each lock handle, how many times the handle was unlocked in leave(); otherwise 0
    276328
    277 #ifdef RT_LOCK_STRICT
     329#ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
    278330    // information about where the lock occured (passed down from the AutoLock classes)
    279331    const char      *pcszFile;
     
    443495/*virtual*/ void AutoReadLock::callLockImpl(LockHandle &l)
    444496{
    445 #ifdef RT_LOCK_STRICT
     497#ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
    446498    l.lockRead(m->pcszFile, m->uLine, m->pcszFunction);
    447499#else
     
    475527/*virtual*/ void AutoWriteLockBase::callLockImpl(LockHandle &l)
    476528{
    477 #ifdef RT_LOCK_STRICT
     529#ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
    478530    l.lockWrite(m->pcszFile, m->uLine, m->pcszFunction);
    479531#else
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette