VirtualBox

Changeset 25834 in vbox


Ignore:
Timestamp:
Jan 14, 2010 4:21:05 PM (15 years ago)
Author:
vboxsync
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)

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/com/AutoLock.h

    r25813 r25834  
    2727// macros for automatic lock validation; these will amount to nothing
    2828// unless lock validation is enabled for the runtime
    29 #if defined(RT_LOCK_STRICT)
     29#if defined(RT_LOCK_STRICT) && defined (DEBUG)
     30#define VBOX_WITH_MAIN_LOCK_VALIDATION
    3031# define COMMA_LOCKVAL_SRC_POS , RT_SRC_POS
    3132# define LOCKVAL_SRC_POS_DECL RT_SRC_POS_DECL
     
    5758 * LockHandle classes.
    5859 */
    59 enum MainLockValidationClasses
     60enum VBoxLockingClass
    6061{
    6162    LOCKCLASS_NONE = 0,
     
    6364    LOCKCLASS_VIRTUALBOXLIST = 2,           // lock protecting a list in VirtualBox object
    6465                                            // (machines list, hard disk tree, shared folders list, ...)
    65     LOCKCLASS_OTHERLIST = 3,                // lock protecting a list that's elsewhere
     66    LOCKCLASS_USBPROXYSERVICE = 3,          // USB proxy service object lock
     67    LOCKCLASS_HOSTOBJECT = 4,               // Host object lock
     68    LOCKCLASS_HOSTLIST = 5,                 // lock protecting a list in Host object
     69    LOCKCLASS_OTHEROBJECT = 6,              // any regular object member variable lock
     70    LOCKCLASS_OTHERLIST = 7,                // lock protecting a list that's elsewhere
    6671                                            // (e.g. snapshots list in machine object)
    67     LOCKCLASS_OBJECT = 4,                   // any regular object member variable  lock
    68     LOCKCLASS_OBJECTSTATE = 5               // object state lock (handled by AutoCaller classes)
     72    LOCKCLASS_OBJECTSTATE = 8               // object state lock (handled by AutoCaller classes)
    6973};
    7074
     
    111115    virtual void unlockRead() = 0;
    112116
    113 #ifdef RT_LOCK_STRICT
     117#ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
    114118    virtual const char* describe() const = 0;
    115119#endif
     
    132136{
    133137public:
    134     RWLockHandle(MainLockValidationClasses lockClass);
     138    RWLockHandle(VBoxLockingClass lockClass);
    135139    virtual ~RWLockHandle();
    136140
     
    144148    virtual uint32_t writeLockLevel() const;
    145149
    146 #ifdef RT_LOCK_STRICT
     150#ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
    147151    virtual const char* describe() const;
    148152#endif
     
    169173{
    170174public:
    171     WriteLockHandle(MainLockValidationClasses lockClass);
     175    WriteLockHandle(VBoxLockingClass lockClass);
    172176    virtual ~WriteLockHandle();
    173177    virtual bool isWriteLockOnCurrentThread() const;
     
    179183    virtual uint32_t writeLockLevel() const;
    180184
    181 #ifdef RT_LOCK_STRICT
     185#ifdef VBOX_WITH_MAIN_LOCK_VALIDATION
    182186    virtual const char* describe() const;
    183187#endif
  • trunk/src/VBox/Main/HostImpl.cpp

    r25810 r25834  
    152152    Data()
    153153#ifdef VBOX_WITH_USB
    154         : treeLock(LOCKCLASS_OTHERLIST)
     154        : usbListsLock(LOCKCLASS_HOSTLIST)
    155155#endif
    156156    {};
     
    160160
    161161#ifdef VBOX_WITH_USB
    162     WriteLockHandle         treeLock;                   // protects the below two lists
     162    WriteLockHandle         usbListsLock;               // protects the below two lists
    163163
    164164    USBDeviceFilterList     llChildren;                 // all USB device filters
     
    947947    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    948948
    949     AutoMultiWriteLock2 alock(this->lockHandle(), &m->treeLock COMMA_LOCKVAL_SRC_POS);
     949    AutoMultiWriteLock2 alock(this->lockHandle(), &m->usbListsLock COMMA_LOCKVAL_SRC_POS);
    950950
    951951    MultiResult rc = checkUSBProxyService();
     
    13241324    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    13251325
    1326     AutoMultiWriteLock2 alock(this->lockHandle(), &m->treeLock COMMA_LOCKVAL_SRC_POS);
     1326    AutoMultiWriteLock2 alock(this->lockHandle(), &m->usbListsLock COMMA_LOCKVAL_SRC_POS);
    13271327
    13281328    MultiResult rc = checkUSBProxyService();
     
    13841384    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    13851385
    1386     AutoMultiWriteLock2 alock(this->lockHandle(), &m->treeLock COMMA_LOCKVAL_SRC_POS);
     1386    AutoMultiWriteLock2 alock(this->lockHandle(), &m->usbListsLock COMMA_LOCKVAL_SRC_POS);
    13871387
    13881388    MultiResult rc = checkUSBProxyService();
     
    16691669    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    16701670
    1671     AutoMultiWriteLock2 alock(this->lockHandle(), &m->treeLock COMMA_LOCKVAL_SRC_POS);
     1671    AutoMultiWriteLock2 alock(this->lockHandle(), &m->usbListsLock COMMA_LOCKVAL_SRC_POS);
    16721672
    16731673
     
    17041704    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    17051705
    1706     AutoReadLock alock(&m->treeLock COMMA_LOCKVAL_SRC_POS);
     1706    AutoReadLock alock(&m->usbListsLock COMMA_LOCKVAL_SRC_POS);
    17071707
    17081708    data.llUSBDeviceFilters.clear();
     
    17351735    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    17361736
    1737     AutoWriteLock alock(&m->treeLock COMMA_LOCKVAL_SRC_POS);
     1737    AutoWriteLock alock(&m->usbListsLock COMMA_LOCKVAL_SRC_POS);
    17381738
    17391739    m->llChildren.push_back(pChild);
     
    17471747    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    17481748
    1749     AutoWriteLock alock(&m->treeLock COMMA_LOCKVAL_SRC_POS);
     1749    AutoWriteLock alock(&m->usbListsLock COMMA_LOCKVAL_SRC_POS);
    17501750
    17511751    for (USBDeviceFilterList::iterator it = m->llChildren.begin();
     
    18251825void Host::getUSBFilters(Host::USBDeviceFilterList *aGlobalFilters)
    18261826{
    1827     AutoReadLock alock(&m->treeLock COMMA_LOCKVAL_SRC_POS);
     1827    AutoReadLock alock(&m->usbListsLock COMMA_LOCKVAL_SRC_POS);
    18281828
    18291829    *aGlobalFilters = m->llUSBDeviceFilters;
  • trunk/src/VBox/Main/MachineImpl.cpp

    r25809 r25834  
    329329/////////////////////////////////////////////////////////////////////////////
    330330
    331 Machine::Machine() : mType (IsMachine) {}
    332 
    333 Machine::~Machine() {}
     331Machine::Machine()
     332{}
     333
     334Machine::~Machine()
     335{}
    334336
    335337HRESULT Machine::FinalConstruct()
     
    547549HRESULT Machine::registeredInit()
    548550{
    549     AssertReturn(mType == IsMachine, E_FAIL);
     551    AssertReturn(getClassID() == clsidMachine, E_FAIL);
    550552    AssertReturn(!mData->mUuid.isEmpty(), E_FAIL);
    551553    AssertReturn(!mData->mAccessible, E_FAIL);
     
    623625        return;
    624626
    625     Assert (mType == IsMachine);
    626     Assert (!!mData);
     627    Assert(getClassID() == clsidMachine);
     628    Assert(!!mData);
    627629
    628630    LogFlowThisFunc(("initFailed()=%d\n", autoUninitSpan.initFailed()));
     
    21152117    if (    aEnabled
    21162118        &&  mData->mRegistered
    2117         &&  (   mType != IsSessionMachine
     2119        &&  (   getClassID() != clsidSessionMachine
    21182120             || (   mData->mMachineState != MachineState_PoweredOff
    21192121                 && mData->mMachineState != MachineState_Teleported
     
    22582260    if (    aEnabled
    22592261        &&  mData->mRegistered
    2260         &&  (   mType != IsSessionMachine
     2262        &&  (   getClassID() != clsidSessionMachine
    22612263             || (   mData->mMachineState != MachineState_PoweredOff
    22622264                 && mData->mMachineState != MachineState_Teleported
     
    31883190        AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
    31893191
    3190         if (mType == IsSnapshotMachine)
     3192        if (getClassID() == clsidSnapshotMachine)
    31913193        {
    31923194            HRESULT rc = checkStateDependency(MutableStateDep);
     
    53705372        {
    53715373            if (   mData->mRegistered
    5372                 && (   mType != IsSessionMachine  /** @todo This was just convered raw; Check if Running and Paused should actually be included here... (Live Migration) */
     5374                && (   getClassID() != clsidSessionMachine  /** @todo This was just convered raw; Check if Running and Paused should actually be included here... (Live Migration) */
    53735375                    || (   mData->mMachineState != MachineState_Paused
    53745376                        && mData->mMachineState != MachineState_Running
     
    53875389        {
    53885390            if (   mData->mRegistered
    5389                 && (   mType != IsSessionMachine  /** @todo This was just convered raw; Check if Running and Paused should actually be included here... (Live Migration) */
     5391                && (   getClassID() != clsidSessionMachine  /** @todo This was just convered raw; Check if Running and Paused should actually be included here... (Live Migration) */
    53905392                    || (   mData->mMachineState != MachineState_Paused
    53915393                        && mData->mMachineState != MachineState_Running
     
    55605562     * disk attachments will already be uninitialized and deleted, so this
    55615563     * code will not affect them. */
    5562     if (!!mMediaData && (mType == IsMachine || mType == IsSnapshotMachine))
     5564    if (!!mMediaData && (getClassID() == clsidMachine || getClassID() == clsidSnapshotMachine))
    55635565    {
    55645566        for (MediaData::AttachmentList::const_iterator it = mMediaData->mAttachments.begin();
     
    55745576    }
    55755577
    5576     if (mType == IsMachine)
     5578    if (getClassID() == clsidMachine)
    55775579    {
    55785580        /* reset some important fields of mData */
     
    57205722{
    57215723    LogFlowThisFuncEnter();
    5722     AssertReturn(mType == IsMachine, E_FAIL);
     5724    AssertReturn(getClassID() == clsidMachine, E_FAIL);
    57235725
    57245726    AutoCaller autoCaller(this);
     
    58775879                              Snapshot *aParentSnapshot)
    58785880{
    5879     AssertReturn (mType == IsMachine, E_FAIL);
     5881    AssertReturn(getClassID() == clsidMachine, E_FAIL);
    58805882
    58815883    HRESULT rc = S_OK;
     
    59485950HRESULT Machine::loadHardware(const settings::Hardware &data)
    59495951{
    5950     AssertReturn(mType == IsMachine || mType == IsSnapshotMachine, E_FAIL);
     5952    AssertReturn(getClassID() == clsidMachine || getClassID() == clsidSnapshotMachine, E_FAIL);
    59515953
    59525954    HRESULT rc = S_OK;
     
    61346136                                        const Guid *aSnapshotId /* = NULL */)
    61356137{
    6136     AssertReturn (mType == IsMachine || mType == IsSnapshotMachine, E_FAIL);
     6138    AssertReturn(getClassID() == clsidMachine || getClassID() == clsidSnapshotMachine, E_FAIL);
    61376139
    61386140    HRESULT rc = S_OK;
     
    62086210                                    const Guid *aSnapshotId /*= NULL*/)
    62096211{
    6210     AssertReturn ((mType == IsMachine && aSnapshotId == NULL) ||
    6211                   (mType == IsSnapshotMachine && aSnapshotId != NULL), E_FAIL);
     6212    AssertReturn(   (getClassID() == clsidMachine && aSnapshotId == NULL)
     6213                 || (getClassID() == clsidSnapshotMachine && aSnapshotId != NULL),
     6214                 E_FAIL);
    62126215
    62136216    HRESULT rc = S_OK;
     
    63136316                if (FAILED(rc))
    63146317                {
    6315                     if (mType == IsSnapshotMachine)
     6318                    if (getClassID() == clsidSnapshotMachine)
    63166319                    {
    63176320                        // wrap another error message around the "cannot find hard disk" set by findHardDisk
     
    63316334                if (medium->getType() == MediumType_Immutable)
    63326335                {
    6333                     if (mType == IsSnapshotMachine)
     6336                    if (getClassID() == clsidSnapshotMachine)
    63346337                        return setError(E_FAIL,
    63356338                                        tr("Immutable hard disk '%s' with UUID {%RTuuid} cannot be directly attached to snapshot with UUID {%RTuuid} "
     
    63496352                }
    63506353
    6351                 if (    mType != IsSnapshotMachine
     6354                if (    getClassID() != clsidSnapshotMachine
    63526355                     && medium->getChildren().size() != 0
    63536356                   )
     
    63996402        if (!medium.isNull())
    64006403        {
    6401             if (mType == IsSnapshotMachine)
     6404            if (getClassID() == clsidSnapshotMachine)
    64026405                rc = medium->attachTo(mData->mUuid, *aSnapshotId);
    64036406            else
     
    67866789    ensureNoStateDependencies();
    67876790
    6788     AssertReturn(mType == IsMachine || mType == IsSessionMachine, E_FAIL);
     6791    AssertReturn(getClassID() == clsidMachine || getClassID() == clsidSessionMachine, E_FAIL);
    67896792
    67906793    BOOL currentStateModified = mData->mCurrentStateModified;
     
    69006903         * to the client process that creates them) and thus don't need to
    69016904         * inform callbacks. */
    6902         if (mType == IsSessionMachine)
     6905        if (getClassID() == clsidSessionMachine)
    69036906            mParent->onMachineDataChange(mData->mUuid);
    69046907    }
     
    78237826        mMediaData.commit();
    78247827
    7825         if (mType == IsSessionMachine)
     7828        if (getClassID() == clsidSessionMachine)
    78267829        {
    78277830            /* attach new data to the primary machine and reshare it */
     
    82748277    }
    82758278
    8276     if (mType == IsSessionMachine)
     8279    if (getClassID() == clsidSessionMachine)
    82778280    {
    82788281        /* attach new data to the primary machine and reshare it */
     
    82998302void Machine::copyFrom(Machine *aThat)
    83008303{
    8301     AssertReturnVoid (mType == IsMachine || mType == IsSessionMachine);
    8302     AssertReturnVoid (aThat->mType == IsSnapshotMachine);
    8303 
    8304     AssertReturnVoid (!Global::IsOnline (mData->mMachineState));
    8305 
    8306     mHWData.assignCopy (aThat->mHWData);
     8304    AssertReturnVoid(getClassID() == clsidMachine || getClassID() == clsidSessionMachine);
     8305    AssertReturnVoid(aThat->getClassID() == clsidSnapshotMachine);
     8306
     8307    AssertReturnVoid(!Global::IsOnline (mData->mMachineState));
     8308
     8309    mHWData.assignCopy(aThat->mHWData);
    83078310
    83088311    // create copies of all shared folders (mHWData after attiching a copy
     
    84058408{
    84068409    LogFlowThisFunc(("\n"));
    8407 
    8408     /* set the proper type to indicate we're the SessionMachine instance */
    8409     unconst(mType) = IsSessionMachine;
    84108410
    84118411#if defined(RT_OS_WINDOWS)
  • trunk/src/VBox/Main/SnapshotImpl.cpp

    r25696 r25834  
    767767{
    768768    LogFlowThisFunc(("\n"));
    769 
    770     /* set the proper type to indicate we're the SnapshotMachine instance */
    771     unconst(mType) = IsSnapshotMachine;
    772769
    773770    return S_OK;
  • trunk/src/VBox/Main/VirtualBoxBase.cpp

    r25809 r25834  
    7979    {
    8080        AssertCompile (sizeof (RWLockHandle *) == sizeof (void *));
    81         RWLockHandle *objLock = new RWLockHandle(LOCKCLASS_OBJECT);
     81
     82        // locking class is LOCKCLASS_VIRTUALBOXOBJECT for the VirtualBox singleton,
     83        // LOCKCLASS_HOSTOBJECT for the Host object and LOCKCLASS_OBJECT for any other object
     84        RWLockHandle *objLock = new RWLockHandle(getLockingClass());
    8285        if (!ASMAtomicCmpXchgPtr ((void * volatile *) &mObjectLock, objLock, NULL))
    8386        {
  • 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
  • trunk/src/VBox/Main/include/HostImpl.h

    r24403 r25834  
    101101
    102102    // public methods only for internal purposes
     103
     104    /**
     105     * Simple run-time type identification without having to enable C++ RTTI.
     106     * The class IDs are defined in VirtualBoxBase.h.
     107     * @return
     108     */
     109    virtual VBoxClsID getClassID() const
     110    {
     111        return clsidHost;
     112    }
     113
     114    /**
     115     * Override of the default locking class to be used for validating lock
     116     * order with the standard member lock handle.
     117     */
     118    virtual VBoxLockingClass getLockingClass() const
     119    {
     120        return LOCKCLASS_HOSTOBJECT;
     121    }
     122
    103123    HRESULT loadSettings(const settings::Host &data);
    104124    HRESULT saveSettings(settings::Host &data);
  • trunk/src/VBox/Main/include/MachineImpl.h

    r25672 r25834  
    9494
    9595public:
    96 
    97     enum InstanceType { IsMachine, IsSessionMachine, IsSnapshotMachine };
    9896
    9997    enum InitMode { Init_New, Init_Import, Init_Registered };
     
    640638    // public methods only for internal purposes
    641639
    642     InstanceType getType() const { return mType; }
     640    /**
     641     * Simple run-time type identification without having to enable C++ RTTI.
     642     * The class IDs are defined in VirtualBoxBase.h.
     643     * @return
     644     */
     645    virtual VBoxClsID getClassID() const
     646    {
     647        return clsidMachine;
     648    }
    643649
    644650    /// @todo (dmik) add lock and make non-inlined after revising classes
     
    892898    void unregisterMetrics(PerformanceCollector *aCollector, Machine *aMachine);
    893899#endif /* VBOX_WITH_RESOURCE_USAGE_API */
    894 
    895     const InstanceType mType;
    896900
    897901    const ComObjPtr<Machine, ComWeakRef> mPeer;
     
    10071011    // public methods only for internal purposes
    10081012
     1013    /**
     1014     * Simple run-time type identification without having to enable C++ RTTI.
     1015     * The class IDs are defined in VirtualBoxBase.h.
     1016     * @return
     1017     */
     1018    virtual VBoxClsID getClassID() const
     1019    {
     1020        return clsidSessionMachine;
     1021    }
     1022
    10091023    bool checkForDeath();
    10101024
     
    11481162    // public methods only for internal purposes
    11491163
     1164    /**
     1165     * Simple run-time type identification without having to enable C++ RTTI.
     1166     * The class IDs are defined in VirtualBoxBase.h.
     1167     * @return
     1168     */
     1169    virtual VBoxClsID getClassID() const
     1170    {
     1171        return clsidSnapshotMachine;
     1172    }
     1173
    11501174    HRESULT onSnapshotChange(Snapshot *aSnapshot);
    11511175
     
    11661190inline const Guid &Machine::getSnapshotId() const
    11671191{
    1168     return mType != IsSnapshotMachine ? Guid::Empty :
    1169                     static_cast<const SnapshotMachine *>(this)->getSnapshotId();
     1192    return getClassID() != clsidSnapshotMachine
     1193                ? Guid::Empty
     1194                : static_cast<const SnapshotMachine*>(this)->getSnapshotId();
    11701195}
    11711196
     
    11821207inline Machine *Machine::getMachine()
    11831208{
    1184     if (mType == IsSessionMachine)
     1209    if (getClassID() == clsidSessionMachine)
    11851210        return mPeer;
    11861211    return this;
  • trunk/src/VBox/Main/include/SnapshotImpl.h

    r25152 r25834  
    9090
    9191    // public methods only for internal purposes
     92
     93
     94    /**
     95     * Simple run-time type identification without having to enable C++ RTTI.
     96     * The class IDs are defined in VirtualBoxBase.h.
     97     * @return
     98     */
     99    virtual VBoxClsID getClassID() const
     100    {
     101        return clsidSnapshot;
     102    }
     103
    92104    const ComObjPtr<Snapshot>& getParent() const;
    93105
  • trunk/src/VBox/Main/include/VirtualBoxBase.h

    r25813 r25834  
    419419////////////////////////////////////////////////////////////////////////////////
    420420
     421enum VBoxClsID
     422{
     423    clsidVirtualBox,
     424    clsidHost,
     425    clsidMachine,
     426    clsidSessionMachine,
     427    clsidSnapshotMachine,
     428    clsidSnapshot,
     429    clsidOther
     430};
     431
    421432/**
    422433 * Abstract base class for all component classes implementing COM
     
    503514    // util::Lockable interface
    504515    virtual RWLockHandle *lockHandle() const;
     516
     517    /**
     518     * Simple run-time type identification without having to enable C++ RTTI.
     519     * The class IDs are defined in VirtualBoxBase.h.
     520     * @return
     521     */
     522    virtual VBoxClsID getClassID() const
     523    {
     524        return clsidOther;
     525    }
     526
     527    /**
     528     * Override of the default locking class to be used for validating lock
     529     * order with the standard member lock handle.
     530     */
     531    virtual VBoxLockingClass getLockingClass() const
     532    {
     533        return LOCKCLASS_OTHEROBJECT;
     534    }
    505535
    506536    /**
     
    11171147
    11181148class ATL_NO_VTABLE VirtualBoxBase
    1119     : virtual public VirtualBoxBaseProto
    1120     , public CComObjectRootEx<CComMultiThreadModel>
     1149    : virtual public VirtualBoxBaseProto,
     1150      public CComObjectRootEx<CComMultiThreadModel>
    11211151{
    11221152
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r25184 r25834  
    181181
    182182    /* public methods only for internal purposes */
     183
     184    /**
     185     * Simple run-time type identification without having to enable C++ RTTI.
     186     * The class IDs are defined in VirtualBoxBase.h.
     187     * @return
     188     */
     189    virtual VBoxClsID getClassID() const
     190    {
     191        return clsidVirtualBox;
     192    }
     193
     194    /**
     195     * Override of the default locking class to be used for validating lock
     196     * order with the standard member lock handle.
     197     */
     198    virtual VBoxLockingClass getLockingClass() const
     199    {
     200        return LOCKCLASS_VIRTUALBOXOBJECT;
     201    }
     202
    183203#ifdef DEBUG
    184204    void dumpAllBackRefs();
  • trunk/src/VBox/Main/include/objectslist.h

    r25809 r25834  
    5959        // http://www.parashift.com/c++-faq-lite/templates.html#faq-35.18
    6060
    61     ObjectsList(MainLockValidationClasses lockClass)
     61    ObjectsList(VBoxLockingClass lockClass)
    6262        : m_lock(lockClass)
    6363    { }
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