VirtualBox

Changeset 25184 in vbox for trunk/src


Ignore:
Timestamp:
Dec 4, 2009 11:37:03 AM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
55652
Message:

Main: bring back r55600 with fix for broken machine creation

Location:
trunk/src/VBox/Main
Files:
1 added
11 edited

Legend:

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

    r25182 r25184  
    5252        return;
    5353
    54 //    /* we uninit children and reset mParent
    55 //     * and VirtualBox::removeDependentChild() needs a write lock */
    56 //    AutoMultiWriteLock2 alock (mVirtualBox->lockHandle(), this->treeLock());
    57 
    58     mVirtualBox->removeDependentChild (this);
    59 
    6054    unconst(mVirtualBox).setNull();
    6155}
     
    7872    m.upperIP = "0.0.0.0";
    7973
    80     /* register with VirtualBox early, since uninit() will
    81      * unconditionally unregister on failure */
    82     aVirtualBox->addDependentChild (this);
    83 
    8474    /* Confirm a successful initialization */
    8575    autoInitSpan.setSucceeded();
     
    9787    /* share VirtualBox weakly (parent remains NULL so far) */
    9888    unconst(mVirtualBox) = aVirtualBox;
    99 
    100     aVirtualBox->addDependentChild (this);
    10189
    10290    unconst(mName) = data.strNetworkName;
  • trunk/src/VBox/Main/MachineImpl.cpp

    r25182 r25184  
    395395    unconst(mParent) = aParent;
    396396
    397     /* register with parent early, since uninit() will unconditionally
    398      * unregister on failure */
    399     mParent->addDependentChild (this);
    400 
    401397    /* allocate the essential machine data structure (the rest will be
    402398     * allocated later by initDataAndChildObjects() */
     
    691687    /* free the essential data structure last */
    692688    mData.free();
    693 
    694     mParent->removeDependentChild (this);
    695689
    696690    LogFlowThisFuncLeave();
     
    50995093 *  children for writing.
    51005094 */
    5101 HRESULT Machine::trySetRegistered (BOOL aRegistered)
     5095HRESULT Machine::trySetRegistered(BOOL argNewRegistered)
    51025096{
    51035097    AssertReturn(mParent->isWriteLockOnCurrentThread(), E_FAIL);
     
    51115105    ensureNoStateDependencies();
    51125106
    5113     ComAssertRet (mData->mRegistered != aRegistered, E_FAIL);
     5107    ComAssertRet(mData->mRegistered != argNewRegistered, E_FAIL);
    51145108
    51155109    if (!mData->mAccessible)
     
    51185112
    51195113        /* inaccessible machines can only be unregistered */
    5120         AssertReturn(!aRegistered, E_FAIL);
     5114        AssertReturn(!argNewRegistered, E_FAIL);
    51215115
    51225116        /* Uninitialize ourselves here because currently there may be no
     
    51355129    AssertReturn(autoCaller.state() == Ready, E_FAIL);
    51365130
    5137     if (aRegistered)
     5131    if (argNewRegistered)
    51385132    {
    51395133        if (mData->mRegistered)
     
    51815175     * so create it by calling saveSettings() too. */
    51825176    if (    isModified()
    5183          || (aRegistered && !mData->m_pMachineConfigFile->fileExists())
     5177         || (argNewRegistered && !mData->m_pMachineConfigFile->fileExists())
    51845178       )
    51855179    {
     
    51955189        commit();
    51965190
    5197         mData->mRegistered = aRegistered;
     5191        mData->mRegistered = argNewRegistered;
    51985192    }
    51995193    else
     
    54645458    for (ULONG slot = 0; slot < RT_ELEMENTS (mNetworkAdapters); slot ++)
    54655459    {
    5466         if (mNetworkAdapters [slot])
    5467         {
    5468             mNetworkAdapters [slot]->uninit();
    5469             unconst(mNetworkAdapters [slot]).setNull();
     5460        if (mNetworkAdapters[slot])
     5461        {
     5462            mNetworkAdapters[slot]->uninit();
     5463            unconst(mNetworkAdapters[slot]).setNull();
    54705464        }
    54715465    }
     
    54855479    for (ULONG slot = 0; slot < RT_ELEMENTS (mParallelPorts); slot ++)
    54865480    {
    5487         if (mParallelPorts [slot])
    5488         {
    5489             mParallelPorts [slot]->uninit();
    5490             unconst(mParallelPorts [slot]).setNull();
     5481        if (mParallelPorts[slot])
     5482        {
     5483            mParallelPorts[slot]->uninit();
     5484            unconst(mParallelPorts[slot]).setNull();
    54915485        }
    54925486    }
     
    54945488    for (ULONG slot = 0; slot < RT_ELEMENTS (mSerialPorts); slot ++)
    54955489    {
    5496         if (mSerialPorts [slot])
    5497         {
    5498             mSerialPorts [slot]->uninit();
    5499             unconst(mSerialPorts [slot]).setNull();
     5490        if (mSerialPorts[slot])
     5491        {
     5492            mSerialPorts[slot]->uninit();
     5493            unconst(mSerialPorts[slot]).setNull();
    55005494        }
    55015495    }
     
    90249018    ComAssertRet (!control.isNull(), E_INVALIDARG);
    90259019
    9026     /* Creating a Progress object requires the VirtualBox children lock, and
     9020    /* Creating a Progress object requires the VirtualBox lock, and
    90279021     * thus locking it here is required by the lock order rules. */
    9028     AutoMultiWriteLock2 alock(mParent->childrenLock(), this->lockHandle());
    9029 
    9030     if (control.equalsTo (mData->mSession.mDirectControl))
     9022    AutoMultiWriteLock2 alock(mParent->lockHandle(), this->lockHandle());
     9023
     9024    if (control.equalsTo(mData->mSession.mDirectControl))
    90319025    {
    90329026        ComAssertRet (aProgress, E_POINTER);
  • trunk/src/VBox/Main/MediumImpl.cpp

    r25182 r25184  
    896896    unconst(m->pVirtualBox) = aVirtualBox;
    897897
    898     /* register with VirtualBox early, since uninit() will
    899      * unconditionally unregister on failure */
    900     aVirtualBox->addDependentChild(this);
    901 
    902898    /* no storage yet */
    903899    m->state = MediumState_NotCreated;
     
    995991    unconst(m->pVirtualBox) = aVirtualBox;
    996992
    997     /* register with VirtualBox early, since uninit() will
    998      * unconditionally unregister on failure */
    999     aVirtualBox->addDependentChild(this);
    1000 
    1001993    /* there must be a storage unit */
    1002994    m->state = MediumState_Created;
     
    10821074    /* register with VirtualBox/parent early, since uninit() will
    10831075     * unconditionally unregister on failure */
    1084     if (aParent == NULL)
    1085         // base disk: add to global list
    1086         aVirtualBox->addDependentChild(this);
    1087     else
     1076    if (aParent)
    10881077    {
    10891078        // differencing image: add to parent
     
    12261215    /* share VirtualBox weakly (parent remains NULL so far) */
    12271216    unconst(m->pVirtualBox) = aVirtualBox;
    1228     aVirtualBox->addDependentChild(this);
    12291217
    12301218    /* fake up a UUID which is unique, but also reproducible */
     
    13141302            deparent();
    13151303        }
    1316         else
    1317             // base image: remove it from the global list
    1318             m->pVirtualBox->removeDependentChild(this);
    13191304    }
    13201305
     
    23332318    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    23342319
    2335     ComObjPtr<Medium> diff;
    2336     HRESULT rc = m->pVirtualBox->cast(aTarget, diff);
    2337     if (FAILED(rc)) return rc;
     2320    ComObjPtr<Medium> diff = static_cast<Medium*>(aTarget);
    23382321
    23392322    AutoWriteLock alock(this);
     
    23462329    /* We want to be locked for reading as long as our diff child is being
    23472330     * created */
    2348     rc = LockRead(NULL);
     2331    HRESULT rc = LockRead(NULL);
    23492332    if (FAILED(rc)) return rc;
    23502333
     
    23862369    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    23872370
    2388     ComObjPtr <Medium> target;
    2389     HRESULT rc = m->pVirtualBox->cast(aTarget, target);
    2390     if (FAILED(rc)) return rc;
    2391     ComObjPtr <Medium> parent;
     2371    ComObjPtr<Medium> target = static_cast<Medium*>(aTarget);
     2372    ComObjPtr<Medium> parent;
    23922373    if (aParent)
    2393     {
    2394         rc = m->pVirtualBox->cast(aParent, parent);
    2395         if (FAILED(rc)) return rc;
    2396     }
     2374        parent = static_cast<Medium*>(aParent);
    23972375
    23982376    AutoMultiWriteLock3 alock(this, target, parent);
    23992377
    2400     ComObjPtr <Progress> progress;
     2378    ComObjPtr<Progress> progress;
     2379    HRESULT rc = S_OK;
    24012380
    24022381    try
     
    38763855                    }
    38773856
    3878                     /* deassociate from VirtualBox, associate with parent */
    3879 
    3880                     m->pVirtualBox->removeDependentChild(this);
    3881 
    38823857                    /* we set mParent & children() */
    38833858                    AutoWriteLock treeLock(m->pVirtualBox->hardDiskTreeLockHandle());
     
    47034678
    47044679    if (m->pParent)
    4705     {
    4706         /* deassociate from the parent, associate with VirtualBox */
    4707         m->pVirtualBox->addDependentChild(this);
    47084680        deparent();
    4709     }
    47104681
    47114682    HRESULT rc = E_FAIL;
     
    47134684    {
    47144685        case DeviceType_DVD:
    4715             rc = m->pVirtualBox->unregisterDVDImage(this);
     4686            rc = m->pVirtualBox->unregisterImage(this, DeviceType_DVD);
    47164687            break;
    47174688        case DeviceType_Floppy:
    4718             rc = m->pVirtualBox->unregisterFloppyImage(this);
     4689            rc = m->pVirtualBox->unregisterImage(this, DeviceType_Floppy);
    47194690            break;
    47204691        case DeviceType_HardDisk:
     
    47334704            m->pParent = pParentBackup;
    47344705            m->pParent->m->llChildren.push_back(this);
    4735             m->pVirtualBox->removeDependentChild(this);
    47364706        }
    47374707    }
     
    51395109                Assert(target->m->pParent.isNull());
    51405110
    5141                 /* associate the child with the parent and deassociate from
    5142                  * VirtualBox */
     5111                /* associate the child with the parent */
    51435112                target->m->pParent = that;
    51445113                that->m->llChildren.push_back(target);
    5145                 target->m->pVirtualBox->removeDependentChild(target);
    51465114
    51475115                /** @todo r=klaus neither target nor that->base() are locked,
     
    51585126
    51595127                if (FAILED(rc))
    5160                 {
    51615128                    /* break the parent association on failure to register */
    5162                     target->m->pVirtualBox->addDependentChild(target);
    51635129                    that->deparent();
    5164                 }
    51655130            }
    51665131
     
    53725337                        source->deparent();
    53735338                    }
    5374                     else
    5375                     {
    5376                         target->m->pVirtualBox->addDependentChild(target);
    5377                         target->m->pVirtualBox->removeDependentChild(source);
    5378                     }
    53795339
    53805340                    /* then, register again */
     
    56505610                        target->m->pParent = parent;
    56515611                        parent->m->llChildren.push_back(target);
    5652                         target->m->pVirtualBox->removeDependentChild(target);
    56535612
    56545613                        /* register with mVirtualBox as the last step and move to
     
    56585617
    56595618                        if (FAILED(rc))
    5660                         {
    56615619                            /* break parent association on failure to register */
    5662                             target->m->pVirtualBox->addDependentChild(target);
    56635620                            target->deparent();     // removes target from parent
    5664                         }
    56655621                    }
    56665622                    else
  • trunk/src/VBox/Main/PerformanceImpl.cpp

    r25182 r25184  
    528528    if (!SUCCEEDED(autoCaller.rc())) return;
    529529
    530     Log(("PerformanceCollector::suspendSampling\n"));
    531530    int rc = RTTimerLRStop(m.sampler);
    532531    AssertRC(rc);
     
    538537    if (!SUCCEEDED(autoCaller.rc())) return;
    539538
    540     Log(("PerformanceCollector::resumeSampling\n"));
    541539    int rc = RTTimerLRStart(m.sampler, 0);
    542540    AssertRC(rc);
     
    556554    if (collector->mMagic == MAGIC)
    557555    {
    558 Log(("staticSamplerCallback %RX64\n", RTTimeNanoTS()));
    559556        collector->samplerCallback();
    560557    }
  • trunk/src/VBox/Main/ProgressImpl.cpp

    r25182 r25184  
    121121    /* share parent weakly */
    122122    unconst(mParent) = aParent;
    123 
    124     /* register with parent early, since uninit() will unconditionally
    125      * unregister on failure */
    126     mParent->addDependentChild (this);
    127123#endif
    128124
     
    194190        if (aAutoUninitSpan.initFailed() && !mId.isEmpty())
    195191            mParent->removeProgress (mId);
    196 
    197         mParent->removeDependentChild (this);
    198192
    199193        unconst(mParent).setNull();
  • trunk/src/VBox/Main/SharedFolderImpl.cpp

    r25182 r25184  
    161161    unconst(mVirtualBox) = aVirtualBox;
    162162
    163     HRESULT rc = protectedInit (aVirtualBox, aName, aHostPath, aWritable);
     163    HRESULT rc = protectedInit(aVirtualBox, aName, aHostPath, aWritable);
    164164
    165165    /* Confirm a successful initialization when it's the case */
     
    176176 *      Must be called from under the object's lock!
    177177 */
    178 HRESULT SharedFolder::protectedInit (VirtualBoxBaseWithChildrenNEXT *aParent,
    179                                      CBSTR aName, CBSTR aHostPath, BOOL aWritable)
     178HRESULT SharedFolder::protectedInit(VirtualBoxBase *aParent,
     179                                    CBSTR aName,
     180                                    CBSTR aHostPath,
     181                                    BOOL aWritable)
    180182{
    181183    LogFlowThisFunc(("aName={%ls}, aHostPath={%ls}, aWritable={%d}\n",
     
    221223    unconst(mParent) = aParent;
    222224
    223     /* register with parent */
    224     mParent->addDependentChild (this);
    225 
    226225    unconst(m.name) = aName;
    227226    unconst(m.hostPath) = hostPath;
     
    243242    if (autoUninitSpan.uninitDone())
    244243        return;
    245 
    246     if (mParent)
    247         mParent->removeDependentChild (this);
    248244
    249245    unconst(mParent) = NULL;
  • trunk/src/VBox/Main/VirtualBoxBase.cpp

    r25182 r25184  
    3838#include "Logging.h"
    3939
    40 // VirtualBoxBaseProto methods
     40#include "objectslist.h"
     41
     42////////////////////////////////////////////////////////////////////////////////
     43//
     44// VirtualBoxBaseProto
     45//
    4146////////////////////////////////////////////////////////////////////////////////
    4247
     
    286291}
    287292
     293////////////////////////////////////////////////////////////////////////////////
     294//
    288295// VirtualBoxBaseProto::AutoInitSpan methods
     296//
    289297////////////////////////////////////////////////////////////////////////////////
    290298
     
    637645}
    638646
    639 // VirtualBoxBase methods
     647////////////////////////////////////////////////////////////////////////////////
     648//
     649// VirtualBoxBase
     650//
    640651////////////////////////////////////////////////////////////////////////////////
    641652
     
    675686}
    676687
    677 // VirtualBoxSupportTranslationBase methods
     688////////////////////////////////////////////////////////////////////////////////
     689//
     690// VirtualBoxSupportTranslationBase
     691//
    678692////////////////////////////////////////////////////////////////////////////////
    679693
     
    738752}
    739753
    740 // VirtualBoxSupportErrorInfoImplBase methods
     754////////////////////////////////////////////////////////////////////////////////
     755//
     756// VirtualBoxSupportErrorInfoImplBase
     757//
    741758////////////////////////////////////////////////////////////////////////////////
    742759
     
    912929}
    913930
    914 // VirtualBoxBaseWithChildrenNEXT methods
    915 ////////////////////////////////////////////////////////////////////////////////
    916931
    917932/**
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r25182 r25184  
    7070
    7171#include "Logging.h"
     72#include "objectslist.h"
    7273
    7374#ifdef RT_OS_WINDOWS
     
    8283
    8384#define VBOX_GLOBAL_SETTINGS_FILE "VirtualBox.xml"
    84 
    85 typedef std::vector< ComObjPtr<Machine> > MachineVector;
    86 
    87 typedef std::list< ComObjPtr<Machine> > MachineList;
    88 typedef std::vector< ComObjPtr<SessionMachine> > SessionMachineVector;
    89 typedef std::list< ComObjPtr<GuestOSType> > GuestOSTypeList;
    90 
    91 typedef std::map<Guid, ComPtr<IProgress> > ProgressMap;
    92 
    93 typedef std::list <ComObjPtr<SharedFolder> > SharedFolderList;
    94 typedef std::list <ComObjPtr<DHCPServer> > DHCPServerList;
    95 
    96 typedef std::map<Guid, ComObjPtr<Medium> > HardDiskMap;
    97 
    9885
    9986////////////////////////////////////////////////////////////////////////////////
     
    169156#endif
    170157
     158typedef ObjectsList<Machine> MachinesOList;
     159typedef ObjectsList<Medium> MediaOList;
     160typedef ObjectsList<GuestOSType> GuestOSTypesOList;
     161typedef ObjectsList<SharedFolder> SharedFoldersOList;
     162typedef ObjectsList<DHCPServer> DHCPServersOList;
     163
     164typedef std::map<Guid, ComPtr<IProgress> > ProgressMap;
     165typedef std::map<Guid, ComObjPtr<Medium> > HardDiskMap;
     166
    171167/**
    172168 *  Main VirtualBox data structure.
     
    198194#endif /* VBOX_WITH_RESOURCE_USAGE_API */
    199195
    200     MachineList                         llMachines;
    201     GuestOSTypeList                     llGuestOSTypes;
     196    // the following lists all have an RWLockHandle as a member and are locked
     197    // individually; getting the VirtualBox object lock is NOT necessary, but
     198    // see the remarks which ObjectsList method lock themselves and which require
     199    // external locking
     200    MachinesOList                       ollMachines;
     201    GuestOSTypesOList                   ollGuestOSTypes;
     202
     203    MediaOList                          ollHardDisks,           // only base hard disks; the RWLockHandle in here is also used
     204                                                                // for hardDiskTreeLockHandle()
     205                                        ollDVDImages,
     206                                        ollFloppyImages;
     207    SharedFoldersOList                  ollSharedFolders;
     208    DHCPServersOList                    ollDHCPServers;
     209
     210    // the hard disks map is an additional map sorted by UUID for quick lookup
     211    // and contains ALL hard disks (base and differencing);
     212    // the map must also be protected by ollHardDisks.getLockHandle()!
     213    HardDiskMap                         mapHardDisks;
    202214
    203215    ProgressMap                         mapProgressOperations;
    204 
    205     MediaList                           llHardDisks,
    206                                         llDVDImages,
    207                                         llFloppyImages;
    208     SharedFolderList                    llSharedFolders;
    209     DHCPServerList                      llDHCPServers;
    210 
    211     /// @todo NEWMEDIA do we really need this map? Used only in
    212     /// find() it seems
    213     HardDiskMap                         mapHardDisks;
    214 
    215216    CallbackList                        llCallbacks;
    216217
    217218    RWLockHandle                        mtxProgressOperations;
    218219            // protects mutex operations; "leaf" lock, no other lock may be requested after this
    219     RWLockHandle                        mtxHardDiskTree;
    220             // protects the hard disk tree; this is implemented here, but only requested through
    221             // Medium::treeLock, which returns exactly this
    222     RWLockHandle                        mtxChildrenMap;
    223             // used for VirtualBoxWithChildrenNEXT management
    224220
    225221    // the following are data for the client watcher thread
     
    373369                                          Global::sOSTypes [i].numSerialEnabled);
    374370                if (SUCCEEDED(rc))
    375                     m->llGuestOSTypes.push_back (guestOSTypeObj);
     371                    m->ollGuestOSTypes.addChild(guestOSTypeObj);
    376372            }
    377373            ComAssertComRCThrowRC (rc);
     
    533529        if (FAILED(rc)) return rc;
    534530
    535         rc = registerDVDImage(pImage, false /* aSaveRegistry */);
     531        rc = registerImage(pImage, DeviceType_DVD, false /* aSaveRegistry */);
    536532        if (FAILED(rc)) return rc;
    537533    }
     
    548544        if (FAILED(rc)) return rc;
    549545
    550         rc = registerFloppyImage(pImage, false /* aSaveRegistry */);
     546        rc = registerImage(pImage, DeviceType_Floppy, false /* aSaveRegistry */);
    551547        if (FAILED(rc)) return rc;
    552548    }
     
    568564    /* tell all our child objects we've been uninitialized */
    569565
    570     LogFlowThisFunc(("Uninitializing machines (%d)...\n", m->llMachines.size()));
    571     if (m->llMachines.size())
    572     {
    573         MachineList::iterator it = m->llMachines.begin();
    574         while (it != m->llMachines.end())
    575             (*it++)->uninit();
    576         m->llMachines.clear();
    577     }
    578 
    579     /* Uninit all other children still referenced by clients (unregistered
    580      * machines, hard disks, DVD/floppy images, server-side progress
    581      * operations). */
    582     uninitDependentChildren();
    583 
    584     m->mapHardDisks.clear();
    585 
    586     m->llFloppyImages.clear();
    587     m->llDVDImages.clear();
    588     m->llHardDisks.clear();
    589     m->llDHCPServers.clear();
     566    LogFlowThisFunc(("Uninitializing machines (%d)...\n", m->ollMachines.size()));
     567    m->ollMachines.uninitAll();
     568    m->ollFloppyImages.uninitAll();
     569    m->ollDVDImages.uninitAll();
     570    m->ollHardDisks.uninitAll();
     571    m->ollDHCPServers.uninitAll();
    590572
    591573    m->mapProgressOperations.clear();
    592574
    593     m->llGuestOSTypes.clear();
     575    m->ollGuestOSTypes.uninitAll();
    594576
    595577    /* Note that we release singleton children after we've all other children.
     
    788770    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    789771
    790     AutoReadLock alock(this);
    791 
    792     SafeIfaceArray<IMachine> machines(m->llMachines);
     772    AutoReadLock al(m->ollMachines.getLockHandle());
     773    SafeIfaceArray<IMachine> machines(m->ollMachines.getList());
    793774    machines.detachTo(ComSafeArrayOutArg(aMachines));
    794775
     
    804785    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    805786
    806     AutoReadLock alock(this);
    807 
    808     SafeIfaceArray<IMedium> hardDisks(m->llHardDisks);
     787    AutoReadLock al(m->ollHardDisks.getLockHandle());
     788    SafeIfaceArray<IMedium> hardDisks(m->ollHardDisks.getList());
    809789    hardDisks.detachTo(ComSafeArrayOutArg(aHardDisks));
    810790
     
    812792}
    813793
    814 STDMETHODIMP
    815 VirtualBox::COMGETTER(DVDImages) (ComSafeArrayOut(IMedium *, aDVDImages))
     794STDMETHODIMP VirtualBox::COMGETTER(DVDImages) (ComSafeArrayOut(IMedium *, aDVDImages))
    816795{
    817796    if (ComSafeArrayOutIsNull(aDVDImages))
     
    821800    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    822801
    823     AutoReadLock alock(this);
    824 
    825     SafeIfaceArray<IMedium> images(m->llDVDImages);
     802    AutoReadLock al(m->ollDVDImages.getLockHandle());
     803    SafeIfaceArray<IMedium> images(m->ollDVDImages.getList());
    826804    images.detachTo(ComSafeArrayOutArg(aDVDImages));
    827805
     
    829807}
    830808
    831 STDMETHODIMP
    832 VirtualBox::COMGETTER(FloppyImages) (ComSafeArrayOut(IMedium *, aFloppyImages))
     809STDMETHODIMP VirtualBox::COMGETTER(FloppyImages) (ComSafeArrayOut(IMedium *, aFloppyImages))
    833810{
    834811    if (ComSafeArrayOutIsNull(aFloppyImages))
     
    838815    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    839816
    840     AutoReadLock alock(this);
    841 
    842     SafeIfaceArray<IMedium> images(m->llFloppyImages);
     817    AutoReadLock al(m->ollFloppyImages.getLockHandle());
     818    SafeIfaceArray<IMedium> images(m->ollFloppyImages.getList());
    843819    images.detachTo(ComSafeArrayOutArg(aFloppyImages));
    844820
     
    855831    /* protect mProgressOperations */
    856832    AutoReadLock safeLock(m->mtxProgressOperations);
    857 
    858833    SafeIfaceArray<IProgress> progress(m->mapProgressOperations);
    859834    progress.detachTo(ComSafeArrayOutArg(aOperations));
     
    869844    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    870845
    871     AutoReadLock alock(this);
    872 
    873     SafeIfaceArray<IGuestOSType> ostypes(m->llGuestOSTypes);
     846    AutoReadLock al(m->ollGuestOSTypes.getLockHandle());
     847    SafeIfaceArray<IGuestOSType> ostypes(m->ollGuestOSTypes.getList());
    874848    ostypes.detachTo(ComSafeArrayOutArg(aGuestOSTypes));
    875849
     
    877851}
    878852
    879 STDMETHODIMP
    880 VirtualBox::COMGETTER(SharedFolders) (ComSafeArrayOut(ISharedFolder *, aSharedFolders))
     853STDMETHODIMP VirtualBox::COMGETTER(SharedFolders) (ComSafeArrayOut(ISharedFolder *, aSharedFolders))
    881854{
    882855#ifndef RT_OS_WINDOWS
     
    919892    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    920893
    921     AutoReadLock alock(this);
    922 
    923     SafeIfaceArray<IDHCPServer> svrs (m->llDHCPServers);
     894    AutoReadLock al(m->ollDHCPServers.getLockHandle());
     895    SafeIfaceArray<IDHCPServer> svrs (m->ollDHCPServers.getList());
    924896    svrs.detachTo(ComSafeArrayOutArg(aDHCPServers));
    925897
     
    11771149
    11781150/** @note Locks objects! */
    1179 STDMETHODIMP VirtualBox::RegisterMachine (IMachine *aMachine)
     1151STDMETHODIMP VirtualBox::RegisterMachine(IMachine *aMachine)
    11801152{
    11811153    CheckComArgNotNull(aMachine);
     
    11901162    if (FAILED(rc)) return rc;
    11911163
    1192     /* We need the children map lock here to keep the getDependentChild() result
    1193      * valid until we finish */
    1194     AutoReadLock chLock (childrenLock());
    1195 
    11961164    /* We can safely cast child to Machine * here because only Machine
    11971165     * implementations of IMachine can be among our children. */
    1198     Machine *machine = static_cast <Machine *> (getDependentChild (aMachine));
    1199     if (machine == NULL)
    1200     {
    1201         /* this machine was not created by CreateMachine() or opened by
    1202          * OpenMachine() or loaded during startup */
    1203         return setError (VBOX_E_INVALID_OBJECT_STATE,
    1204             tr ("The machine named '%ls' is not created within this "
    1205                 "VirtualBox instance"), name.raw());
    1206     }
    1207 
    1208     AutoCaller machCaller (machine);
    1209     ComAssertComRCRetRC (machCaller.rc());
    1210 
    1211     rc = registerMachine (machine);
    1212 
     1166    Machine *pMachine = static_cast<Machine*>(aMachine);
     1167
     1168    AutoCaller machCaller(pMachine);
     1169    ComAssertComRCRetRC(machCaller.rc());
     1170
     1171    rc = registerMachine(pMachine);
    12131172    /* fire an event */
    12141173    if (SUCCEEDED(rc))
    1215         onMachineRegistered(machine->getId(), TRUE);
     1174        onMachineRegistered(pMachine->getId(), TRUE);
    12161175
    12171176    return rc;
     
    12191178
    12201179/** @note Locks objects! */
    1221 STDMETHODIMP VirtualBox::GetMachine (IN_BSTR aId, IMachine **aMachine)
     1180STDMETHODIMP VirtualBox::GetMachine(IN_BSTR aId, IMachine **aMachine)
    12221181{
    12231182    CheckComArgOutSafeArrayPointerValid(aMachine);
     
    12361195
    12371196/** @note Locks this object for reading, then some machine objects for reading. */
    1238 STDMETHODIMP VirtualBox::FindMachine (IN_BSTR aName, IMachine **aMachine)
     1197STDMETHODIMP VirtualBox::FindMachine(IN_BSTR aName, IMachine **aMachine)
    12391198{
    12401199    LogFlowThisFuncEnter();
     
    12481207
    12491208    /* start with not found */
    1250     ComObjPtr<Machine> machine;
    1251     MachineList machines;
    1252     {
    1253         /* take a copy for safe iteration outside the lock */
    1254         AutoReadLock alock(this);
    1255         machines = m->llMachines;
    1256     }
    1257 
    1258     for (MachineList::iterator it = machines.begin();
    1259          !machine && it != machines.end();
    1260          ++ it)
     1209    ComObjPtr<Machine> pMachineFound;
     1210
     1211    AutoReadLock al(m->ollMachines.getLockHandle());
     1212    for (MachinesOList::iterator it = m->ollMachines.begin();
     1213         it != m->ollMachines.end();
     1214         ++it)
    12611215    {
    12621216        ComObjPtr<Machine> &pMachine2 = *it;
     
    12691223            AutoReadLock machLock(pMachine2);
    12701224            if (pMachine2->getName() == aName)
    1271                 machine = pMachine2;
     1225            {
     1226                pMachineFound = pMachine2;
     1227                break;
     1228            }
    12721229        }
    12731230    }
    12741231
    12751232    /* this will set (*machine) to NULL if machineObj is null */
    1276     machine.queryInterfaceTo(aMachine);
    1277 
    1278     HRESULT rc = machine
     1233    pMachineFound.queryInterfaceTo(aMachine);
     1234
     1235    HRESULT rc = pMachineFound
    12791236        ? S_OK
    1280         : setError (VBOX_E_OBJECT_NOT_FOUND,
    1281             tr ("Could not find a registered machine named '%ls'"), aName);
     1237        : setError(VBOX_E_OBJECT_NOT_FOUND,
     1238                   tr("Could not find a registered machine named '%ls'"), aName);
    12821239
    12831240    LogFlowThisFunc(("aName=\"%ls\", aMachine=%p, rc=%08X\n", aName, *aMachine, rc));
     
    12881245
    12891246/** @note Locks objects! */
    1290 STDMETHODIMP VirtualBox::UnregisterMachine (IN_BSTR  aId,
    1291                                             IMachine **aMachine)
     1247STDMETHODIMP VirtualBox::UnregisterMachine(IN_BSTR  aId,
     1248                                           IMachine **aMachine)
    12921249{
    12931250    Guid id(aId);
     
    12981255    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    12991256
     1257    // find machine from the given ID
     1258    ComObjPtr<Machine> pMachine;
     1259    HRESULT rc = findMachine(id, true /* setError */, &pMachine);
     1260    if (FAILED(rc)) return rc;
     1261
     1262    // trySetRegistered needs VirtualBox object write lock
    13001263    AutoWriteLock alock(this);
    1301 
    1302     ComObjPtr<Machine> machine;
    1303 
    1304     HRESULT rc = findMachine (id, true /* setError */, &machine);
     1264    rc = pMachine->trySetRegistered(FALSE);
    13051265    if (FAILED(rc)) return rc;
    13061266
    1307     rc = machine->trySetRegistered (FALSE);
    1308     if (FAILED(rc)) return rc;
    1309 
    13101267    /* remove from the collection of registered machines */
    1311     m->llMachines.remove (machine);
     1268    m->ollMachines.removeChild(pMachine);
    13121269
    13131270    /* save the global registry */
     
    13151272
    13161273    /* return the unregistered machine to the caller */
    1317     machine.queryInterfaceTo(aMachine);
     1274    pMachine.queryInterfaceTo(aMachine);
    13181275
    13191276    /* fire an event */
    1320     onMachineRegistered (id, FALSE);
     1277    onMachineRegistered(id, FALSE);
    13211278
    13221279    return rc;
     
    14611418    if (SUCCEEDED(rc))
    14621419    {
    1463         rc = registerDVDImage (image);
     1420        rc = registerImage(image, DeviceType_DVD);
    14641421
    14651422        if (SUCCEEDED(rc))
     
    15281485    if (SUCCEEDED(rc))
    15291486    {
    1530         rc = registerFloppyImage (image);
     1487        rc = registerImage(image, DeviceType_Floppy);
    15311488
    15321489        if (SUCCEEDED(rc))
     
    16161573    *aType = NULL;
    16171574
    1618     AutoReadLock alock(this);
    1619 
    1620     for (GuestOSTypeList::iterator it = m->llGuestOSTypes.begin();
    1621          it != m->llGuestOSTypes.end();
    1622          ++ it)
     1575    AutoReadLock alock(m->ollGuestOSTypes.getLockHandle());
     1576    for (GuestOSTypesOList::iterator it = m->ollGuestOSTypes.begin();
     1577         it != m->ollGuestOSTypes.end();
     1578         ++it)
    16231579    {
    16241580        const Bstr &typeId = (*it)->id();
     
    16371593}
    16381594
    1639 STDMETHODIMP
    1640 VirtualBox::CreateSharedFolder (IN_BSTR aName, IN_BSTR aHostPath, BOOL /* aWritable */)
     1595STDMETHODIMP VirtualBox::CreateSharedFolder(IN_BSTR aName, IN_BSTR aHostPath, BOOL /* aWritable */)
    16411596{
    16421597    CheckComArgNotNull(aName);
     
    16491604}
    16501605
    1651 STDMETHODIMP VirtualBox::RemoveSharedFolder (IN_BSTR aName)
     1606STDMETHODIMP VirtualBox::RemoveSharedFolder(IN_BSTR aName)
    16521607{
    16531608    CheckComArgNotNull(aName);
     
    20061961void VirtualBox::dumpAllBackRefs()
    20071962{
    2008     for (MediaList::const_iterator mt = m->llHardDisks.begin();
    2009          mt != m->llHardDisks.end();
    2010          ++mt)
    2011     {
    2012         ComObjPtr<Medium> pMedium = *mt;
    2013         pMedium->dumpBackRefs();
    2014     }
    2015     for (MediaList::const_iterator mt = m->llDVDImages.begin();
    2016          mt != m->llDVDImages.end();
    2017          ++mt)
    2018     {
    2019         ComObjPtr<Medium> pMedium = *mt;
    2020         pMedium->dumpBackRefs();
     1963    {
     1964        AutoReadLock al(m->ollHardDisks.getLockHandle());
     1965        for (MediaList::const_iterator mt = m->ollHardDisks.begin();
     1966             mt != m->ollHardDisks.end();
     1967             ++mt)
     1968        {
     1969            ComObjPtr<Medium> pMedium = *mt;
     1970            pMedium->dumpBackRefs();
     1971        }
     1972    }
     1973    {
     1974        AutoReadLock al(m->ollDVDImages.getLockHandle());
     1975        for (MediaList::const_iterator mt = m->ollDVDImages.begin();
     1976             mt != m->ollDVDImages.end();
     1977             ++mt)
     1978        {
     1979            ComObjPtr<Medium> pMedium = *mt;
     1980            pMedium->dumpBackRefs();
     1981        }
    20211982    }
    20221983}
     
    26622623{
    26632624    ComObjPtr<GuestOSType> type;
    2664 
    26652625    AutoCaller autoCaller(this);
    26662626    AssertComRCReturn(autoCaller.rc(), type);
    26672627
    2668     AutoReadLock alock(this);
    2669 
    26702628    /* unknown type must always be the first */
    2671     ComAssertRet (m->llGuestOSTypes.size() > 0, type);
    2672 
    2673     type = m->llGuestOSTypes.front();
    2674     return type;
     2629    ComAssertRet(m->ollGuestOSTypes.size() > 0, type);
     2630
     2631    return m->ollGuestOSTypes.front();
    26752632}
    26762633
     
    27032660    AutoReadLock alock(this);
    27042661
    2705     for (MachineList::iterator it = m->llMachines.begin();
    2706          it != m->llMachines.end();
     2662    for (MachinesOList::iterator it = m->ollMachines.begin();
     2663         it != m->ollMachines.end();
    27072664         ++it)
    27082665    {
     
    27392696                                ComObjPtr<Machine> *aMachine /* = NULL */)
    27402697{
     2698    HRESULT rc = VBOX_E_OBJECT_NOT_FOUND;
     2699
    27412700    AutoCaller autoCaller(this);
    27422701    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    27432702
    2744     bool found = false;
    2745 
    2746     {
    2747         AutoReadLock alock(this);
    2748 
    2749         for (MachineList::iterator it = m->llMachines.begin();
    2750              !found && it != m->llMachines.end();
    2751              ++ it)
     2703    {
     2704        AutoReadLock al(m->ollMachines.getLockHandle());
     2705
     2706        for (MachinesOList::iterator it = m->ollMachines.begin();
     2707             it != m->ollMachines.end();
     2708             ++it)
    27522709        {
    27532710            ComObjPtr<Machine> pMachine2 = *it;
     
    27562713            AssertComRC(machCaller.rc());
    27572714
    2758             found = pMachine2->getId() == aId;
    2759             if (found && aMachine)
    2760                 *aMachine = pMachine2;
    2761         }
    2762     }
    2763 
    2764     HRESULT rc = found ? S_OK : VBOX_E_OBJECT_NOT_FOUND;
    2765 
    2766     if (aSetError && !found)
    2767     {
    2768         setError (VBOX_E_OBJECT_NOT_FOUND,
    2769             tr ("Could not find a registered machine with UUID {%RTuuid}"),
    2770             aId.raw());
    2771     }
     2715            if (pMachine2->getId() == aId)
     2716            {
     2717                rc = S_OK;
     2718                if (aMachine)
     2719                    *aMachine = pMachine2;
     2720                break;
     2721            }
     2722        }
     2723    }
     2724
     2725    if (aSetError && FAILED(rc))
     2726        setError(VBOX_E_OBJECT_NOT_FOUND,
     2727                 tr("Could not find a registered machine with UUID {%RTuuid}"),
     2728                 aId.raw());
    27722729
    27732730    return rc;
     
    27962753    AssertReturn(aId || aLocation, E_INVALIDARG);
    27972754
    2798     AutoReadLock alock(this);
     2755    // we use the hard disks map, but it is protected by the
     2756    // hard disk _list_ lock handle
     2757    AutoReadLock alock(m->ollHardDisks.getLockHandle());
    27992758
    28002759    /* first, look up by UUID in the map if UUID is provided */
    28012760    if (aId)
    28022761    {
    2803         HardDiskMap::const_iterator it = m->mapHardDisks.find (*aId);
     2762        HardDiskMap::const_iterator it = m->mapHardDisks.find(*aId);
    28042763        if (it != m->mapHardDisks.end())
    28052764        {
     
    28872846    }
    28882847
    2889     AutoReadLock alock(this);
     2848    AutoReadLock alock(m->ollDVDImages.getLockHandle());
    28902849
    28912850    bool found = false;
    28922851
    2893     for (MediaList::const_iterator it = m->llDVDImages.begin();
    2894          it != m->llDVDImages.end();
     2852    for (MediaList::const_iterator it = m->ollDVDImages.begin();
     2853         it != m->ollDVDImages.end();
    28952854         ++ it)
    28962855    {
     
    29632922    }
    29642923
    2965     AutoReadLock alock(this);
     2924    AutoReadLock alock(m->ollFloppyImages.getLockHandle());
    29662925
    29672926    bool found = false;
    29682927
    2969     for (MediaList::const_iterator it = m->llFloppyImages.begin();
    2970          it != m->llFloppyImages.end();
     2928    for (MediaList::const_iterator it = m->ollFloppyImages.begin();
     2929         it != m->ollFloppyImages.end();
    29712930         ++ it)
    29722931    {
     
    30092968                                    GuestOSType*& pGuestOSType)
    30102969{
    3011     AutoReadLock alock(this);
    3012 
    30132970    /* Look for a GuestOSType object */
    3014     AssertMsg(m->llGuestOSTypes.size() != 0,
     2971    AssertMsg(m->ollGuestOSTypes.size() != 0,
    30152972              ("Guest OS types array must be filled"));
    30162973
     
    30212978    }
    30222979
    3023     for (GuestOSTypeList::const_iterator it = m->llGuestOSTypes.begin();
    3024          it != m->llGuestOSTypes.end();
     2980    AutoReadLock alock(m->ollGuestOSTypes.getLockHandle());
     2981    for (GuestOSTypesOList::const_iterator it = m->ollGuestOSTypes.begin();
     2982         it != m->ollGuestOSTypes.end();
    30252983         ++it)
    30262984    {
     
    31663124 * @note Locks this object and media objects for reading.
    31673125 */
    3168 HRESULT VirtualBox::checkMediaForConflicts2 (const Guid &aId,
    3169                                              const Utf8Str &aLocation,
    3170                                              Utf8Str &aConflict)
     3126HRESULT VirtualBox::checkMediaForConflicts2(const Guid &aId,
     3127                                            const Utf8Str &aLocation,
     3128                                            Utf8Str &aConflict)
    31713129{
    31723130    aConflict.setNull();
     
    32393197    HRESULT rc = S_OK;
    32403198
    3241     /* serialize file access (prevents concurrent reads and writes) */
    3242     AutoWriteLock alock(this);
    3243 
    32443199    try
    32453200    {
    32463201        // machines
    3247         m->pMainConfigFile->llMachines.clear();
    3248         for (MachineList::iterator it = m->llMachines.begin();
    3249              it != m->llMachines.end();
    3250              ++it)
    3251         {
    3252             settings::MachineRegistryEntry mre;
    3253             rc = (*it)->saveRegistryEntry(mre);
    3254             m->pMainConfigFile->llMachines.push_back(mre);
     3202        settings::MachinesRegistry machinesTemp;
     3203        {
     3204            AutoReadLock al(m->ollMachines.getLockHandle());
     3205            for (MachinesOList::iterator it = m->ollMachines.begin();
     3206                 it != m->ollMachines.end();
     3207                 ++it)
     3208            {
     3209                settings::MachineRegistryEntry mre;
     3210                rc = (*it)->saveRegistryEntry(mre);
     3211                machinesTemp.push_back(mre);
     3212            }
    32553213        }
    32563214
    32573215        // hard disks
    3258         m->pMainConfigFile->llHardDisks.clear();
    3259         for (MediaList::const_iterator it = m->llHardDisks.begin();
    3260              it != m->llHardDisks.end();
    3261              ++it)
    3262         {
    3263             settings::Medium med;
    3264             rc = (*it)->saveSettings(med);
    3265             m->pMainConfigFile->llHardDisks.push_back(med);
    3266             if (FAILED(rc)) throw rc;
     3216        settings::MediaList hardDisksTemp;
     3217        {
     3218            AutoReadLock al(m->ollHardDisks.getLockHandle());
     3219            for (MediaList::const_iterator it = m->ollHardDisks.begin();
     3220                 it != m->ollHardDisks.end();
     3221                 ++it)
     3222            {
     3223                settings::Medium med;
     3224                rc = (*it)->saveSettings(med);
     3225                if (FAILED(rc)) throw rc;
     3226                hardDisksTemp.push_back(med);
     3227            }
    32673228        }
    32683229
    32693230        /* CD/DVD images */
    3270         m->pMainConfigFile->llDvdImages.clear();
    3271         for (MediaList::const_iterator it = m->llDVDImages.begin();
    3272              it != m->llDVDImages.end();
    3273              ++it)
    3274         {
    3275             settings::Medium med;
    3276             rc = (*it)->saveSettings(med);
    3277             if (FAILED(rc)) throw rc;
    3278             m->pMainConfigFile->llDvdImages.push_back(med);
     3231        settings::MediaList dvdsTemp;
     3232        {
     3233            AutoReadLock al(m->ollDVDImages.getLockHandle());
     3234            for (MediaList::const_iterator it = m->ollDVDImages.begin();
     3235                 it != m->ollDVDImages.end();
     3236                 ++it)
     3237            {
     3238                settings::Medium med;
     3239                rc = (*it)->saveSettings(med);
     3240                if (FAILED(rc)) throw rc;
     3241                dvdsTemp.push_back(med);
     3242            }
    32793243        }
    32803244
    32813245        /* floppy images */
    3282         m->pMainConfigFile->llFloppyImages.clear();
    3283         for (MediaList::const_iterator it = m->llFloppyImages.begin();
    3284              it != m->llFloppyImages.end();
    3285              ++it)
    3286         {
    3287             settings::Medium med;
    3288             rc = (*it)->saveSettings(med);
    3289             if (FAILED(rc)) throw rc;
    3290             m->pMainConfigFile->llFloppyImages.push_back(med);
    3291         }
    3292 
    3293         m->pMainConfigFile->llDhcpServers.clear();
    3294         for (DHCPServerList::const_iterator it =
    3295                 m->llDHCPServers.begin();
    3296                 it != m->llDHCPServers.end();
    3297                 ++ it)
    3298         {
    3299             settings::DHCPServer d;
    3300             rc = (*it)->saveSettings(d);
    3301             if (FAILED(rc)) throw rc;
    3302             m->pMainConfigFile->llDhcpServers.push_back(d);
    3303         }
     3246        settings::MediaList floppiesTemp;
     3247        {
     3248            AutoReadLock al(m->ollFloppyImages.getLockHandle());
     3249            for (MediaList::const_iterator it = m->ollFloppyImages.begin();
     3250                 it != m->ollFloppyImages.end();
     3251                 ++it)
     3252            {
     3253                settings::Medium med;
     3254                rc = (*it)->saveSettings(med);
     3255                if (FAILED(rc)) throw rc;
     3256                floppiesTemp.push_back(med);
     3257            }
     3258        }
     3259
     3260        settings::DHCPServersList dhcpServersTemp;
     3261        {
     3262            AutoReadLock al(m->ollDHCPServers.getLockHandle());
     3263            for (DHCPServersOList::const_iterator it = m->ollDHCPServers.begin();
     3264                 it != m->ollDHCPServers.end();
     3265                 ++it)
     3266            {
     3267                settings::DHCPServer d;
     3268                rc = (*it)->saveSettings(d);
     3269                if (FAILED(rc)) throw rc;
     3270                dhcpServersTemp.push_back(d);
     3271            }
     3272        }
     3273
     3274        /* finally, lock VirtualBox object for writing */
     3275        AutoWriteLock alock(this);
     3276
     3277        /* now copy the temp data to the config file under the VirtualBox lock */
     3278        m->pMainConfigFile->llMachines = machinesTemp;
     3279        m->pMainConfigFile->llHardDisks = hardDisksTemp;
     3280        m->pMainConfigFile->llDvdImages = dvdsTemp;
     3281        m->pMainConfigFile->llFloppyImages = floppiesTemp;
     3282        m->pMainConfigFile->llDhcpServers = dhcpServersTemp;
     3283
     3284        // leave extra data alone, it's still in the config file
    33043285
    33053286        /* host data (USB filters) */
     
    33103291        if (FAILED(rc)) throw rc;
    33113292
    3312         // now write out the XML
     3293        // and write out the XML, still under the lock
    33133294        m->pMainConfigFile->write(m->strSettingsFilePath);
    33143295    }
     
    33483329    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    33493330
    3350     AutoWriteLock alock(this);
    3351 
    33523331    HRESULT rc = S_OK;
    33533332
     
    33733352    if (autoCaller.state() != InInit)
    33743353    {
    3375         /* Machine::trySetRegistered() will commit and save machine settings */
     3354        // trySetRegistered needs VirtualBox object write lock;
     3355        // it will commit and save machine settings
     3356        AutoWriteLock alock(this);
    33763357        rc = aMachine->trySetRegistered(TRUE);
    33773358        if (FAILED(rc)) return rc;
     
    33793360
    33803361    /* add to the collection of registered machines */
    3381     m->llMachines.push_back(aMachine);
     3362    m->ollMachines.addChild(aMachine);
    33823363
    33833364    if (autoCaller.state() != InInit)
     
    34103391    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    34113392
    3412     AutoWriteLock alock(this);
    3413 
    3414     AutoCaller hardDiskCaller (aHardDisk);
     3393    AutoCaller hardDiskCaller(aHardDisk);
    34153394    AssertComRCReturn(hardDiskCaller.rc(), hardDiskCaller.rc());
    34163395
    3417     AutoReadLock hardDiskLock (aHardDisk);
    3418 
    3419     Utf8Str strConflict;
    3420     HRESULT rc = checkMediaForConflicts2(aHardDisk->getId(),
    3421                                          aHardDisk->getLocationFull(),
    3422                                          strConflict);
    3423     if (FAILED(rc)) return rc;
    3424 
    3425     if (strConflict.length())
    3426     {
    3427         return setError(E_INVALIDARG,
    3428                         tr("Cannot register the hard disk '%s' with UUID {%RTuuid} because a %s already exists in the media registry ('%s')"),
    3429                         aHardDisk->getLocationFull().raw(),
    3430                         aHardDisk->getId().raw(),
    3431                         strConflict.raw(),
    3432                         m->strSettingsFilePath.raw());
    3433     }
    3434 
    3435     if (aHardDisk->getParent().isNull())
    3436     {
    3437         /* base (root) hard disk */
    3438         m->llHardDisks.push_back (aHardDisk);
    3439     }
    3440 
    3441     m->mapHardDisks.insert(HardDiskMap::value_type(aHardDisk->getId(),
    3442                                                    HardDiskMap::mapped_type(aHardDisk)));
     3396    Guid id;
     3397    Utf8Str strLocationFull;
     3398    ComObjPtr<Medium> pParent;
     3399    {
     3400        AutoReadLock hardDiskLock(aHardDisk);
     3401        id = aHardDisk->getId();
     3402        strLocationFull = aHardDisk->getLocationFull();
     3403        pParent = aHardDisk->getParent();
     3404    }
     3405
     3406    HRESULT rc;
     3407    {
     3408        // lock the hard disk lists (list + map) while checking for conflicts
     3409        AutoWriteLock al(m->ollHardDisks.getLockHandle());
     3410
     3411        Utf8Str strConflict;
     3412        rc = checkMediaForConflicts2(id,
     3413                                     strLocationFull,
     3414                                     strConflict);
     3415        if (FAILED(rc)) return rc;
     3416        if (strConflict.length())
     3417            return setError(E_INVALIDARG,
     3418                            tr("Cannot register the hard disk '%s' with UUID {%RTuuid} because a %s already exists in the media registry ('%s')"),
     3419                            strLocationFull.raw(),
     3420                            id.raw(),
     3421                            strConflict.raw(),
     3422                            m->strSettingsFilePath.raw());
     3423
     3424        // store base (root) hard disks in the list
     3425        if (pParent.isNull())
     3426            m->ollHardDisks.getList().push_back(aHardDisk);
     3427                    // access the list directly because we already locked the list above
     3428
     3429        // store all hard disks (even differencing images) in the map
     3430        m->mapHardDisks[id] = aHardDisk;
     3431    }
    34433432
    34443433    if (aSaveRegistry)
    34453434    {
    34463435        rc = saveSettings();
    3447         if (FAILED (rc))
     3436        if (FAILED(rc))
    34483437            unregisterHardDisk(aHardDisk, false /* aSaveRegistry */);
    34493438    }
     
    34753464    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    34763465
    3477     AutoWriteLock alock(this);
    3478 
    34793466    AutoCaller hardDiskCaller (aHardDisk);
    34803467    AssertComRCReturn(hardDiskCaller.rc(), hardDiskCaller.rc());
    34813468
    3482     AutoReadLock hardDiskLock (aHardDisk);
    3483 
    3484     size_t cnt = m->mapHardDisks.erase(aHardDisk->getId());
    3485     Assert(cnt == 1);
    3486     NOREF(cnt);
    3487 
    3488     if (aHardDisk->getParent().isNull())
    3489     {
    3490         /* base (root) hard disk */
    3491         m->llHardDisks.remove(aHardDisk);
     3469    Guid id;
     3470    ComObjPtr<Medium> pParent;
     3471    {
     3472        AutoReadLock hardDiskLock(aHardDisk);
     3473        id = aHardDisk->getId();
     3474        pParent = aHardDisk->getParent();
     3475    }
     3476
     3477    {
     3478        // lock the hard disk lists (list + map)
     3479        AutoWriteLock al(m->ollHardDisks.getLockHandle());
     3480
     3481        // remove base (root) hard disks from the list
     3482        if (pParent.isNull())
     3483            m->ollHardDisks.getList().remove(aHardDisk);
     3484                    // access the list directly because we already locked the list above
     3485
     3486        // remove all hard disks (even differencing images) from map
     3487        size_t cnt = m->mapHardDisks.erase(id);
     3488        Assert(cnt == 1);
     3489        NOREF(cnt);
    34923490    }
    34933491
     
    34973495    {
    34983496        rc = saveSettings();
    3499         if (FAILED (rc))
     3497        if (FAILED(rc))
    35003498            registerHardDisk(aHardDisk, false /* aSaveRegistry */);
    35013499    }
     
    35053503
    35063504/**
    3507  * Remembers the given image by storing it in the CD/DVD image registry.
    3508  *
    3509  * @param aImage        Image object to remember.
     3505 * Remembers the given image by storing it in the CD/DVD or floppy image registry.
     3506 *
     3507 * @param argImage      Image object to remember.
     3508 * @param argType       Either DeviceType_DVD or DeviceType_Floppy.
    35103509 * @param aSaveRegistry @c true to save the image registry to disk (default).
    35113510 *
     
    35193518 * @note Locks this object for writing and @a aImage for reading.
    35203519 */
    3521 HRESULT VirtualBox::registerDVDImage (Medium *aImage,
    3522                                       bool aSaveRegistry /*= true*/)
    3523 {
    3524     AssertReturn(aImage != NULL, E_INVALIDARG);
     3520HRESULT VirtualBox::registerImage(Medium *argImage,
     3521                                  DeviceType_T argType,
     3522                                  bool argSaveRegistry /*= true*/)
     3523{
     3524    AssertReturn(argImage != NULL, E_INVALIDARG);
    35253525
    35263526    AutoCaller autoCaller(this);
    35273527    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    35283528
    3529     AutoWriteLock alock(this);
    3530 
    3531     AutoCaller imageCaller (aImage);
     3529    AutoCaller imageCaller(argImage);
    35323530    AssertComRCReturn(imageCaller.rc(), imageCaller.rc());
    35333531
    3534     AutoReadLock imageLock (aImage);
    3535 
    3536     Utf8Str strConflict;
    3537     HRESULT rc = checkMediaForConflicts2(aImage->getId(),
    3538                                          aImage->getLocationFull(),
    3539                                          strConflict);
    3540     if (FAILED(rc)) return rc;
    3541 
    3542     if (strConflict.length())
    3543     {
    3544         return setError(VBOX_E_INVALID_OBJECT_STATE,
    3545                         tr("Cannot register the CD/DVD image '%s' with UUID {%RTuuid} because a %s already exists in the media registry ('%s')"),
    3546                         aImage->getLocationFull().raw(),
    3547                         aImage->getId().raw(),
    3548                         strConflict.raw(),
    3549                         m->strSettingsFilePath.raw());
    3550     }
    3551 
    3552     /* add to the collection */
    3553     m->llDVDImages.push_back (aImage);
    3554 
    3555     if (aSaveRegistry)
     3532    Guid id;
     3533    Utf8Str strLocationFull;
     3534    ComObjPtr<Medium> pParent;
     3535    {
     3536        AutoReadLock al(argImage);
     3537        id = argImage->getId();
     3538        strLocationFull = argImage->getLocationFull();
     3539        pParent = argImage->getParent();
     3540    }
     3541
     3542    // work on DVDs or floppies list?
     3543    ObjectsList<Medium> &oll = (argType == DeviceType_DVD) ? m->ollDVDImages : m->ollFloppyImages;
     3544
     3545    HRESULT rc;
     3546    {
     3547        // lock the images lists (list + map) while checking for conflicts
     3548        AutoWriteLock al(oll.getLockHandle());
     3549
     3550        Utf8Str strConflict;
     3551        rc = checkMediaForConflicts2(id,
     3552                                     strLocationFull,
     3553                                     strConflict);
     3554        if (FAILED(rc)) return rc;
     3555
     3556        if (strConflict.length())
     3557            return setError(VBOX_E_INVALID_OBJECT_STATE,
     3558                            tr("Cannot register the image '%s' with UUID {%RTuuid} because a %s already exists in the media registry ('%s')"),
     3559                            strLocationFull.raw(),
     3560                            id.raw(),
     3561                            strConflict.raw(),
     3562                            m->strSettingsFilePath.raw());
     3563
     3564        // add to the collection
     3565        oll.getList().push_back(argImage);
     3566                // access the list directly because we already locked the list above
     3567    }
     3568
     3569    if (argSaveRegistry)
    35563570    {
    35573571        rc = saveSettings();
    3558         if (FAILED (rc))
    3559             unregisterDVDImage (aImage, false /* aSaveRegistry */);
     3572        if (FAILED(rc))
     3573            unregisterImage(argImage, argType, false /* aSaveRegistry */);
    35603574    }
    35613575
     
    35643578
    35653579/**
    3566  * Removes the given image from the CD/DVD image registry registry.
    3567  *
    3568  * @param aImage        Image object to remove.
    3569  * @param aSaveRegistry @c true to save hard disk registry to disk (default).
     3580 * Removes the given image from the CD/DVD or floppy image registry.
     3581 *
     3582 * @param argImage        Image object to remove.
     3583 * @param argType         Either DeviceType_DVD or DeviceType_Floppy.
     3584 * @param argSaveRegistry @c true to save hard disk registry to disk (default).
    35703585 *
    35713586 * When @a aSaveRegistry is @c true, this operation may fail because of the
     
    35783593 * @note Locks this object for writing and @a aImage for reading.
    35793594 */
    3580 HRESULT VirtualBox::unregisterDVDImage (Medium *aImage,
    3581                                         bool aSaveRegistry /*= true*/)
    3582 {
    3583     AssertReturn(aImage != NULL, E_INVALIDARG);
     3595HRESULT VirtualBox::unregisterImage(Medium *argImage,
     3596                                    DeviceType_T argType,
     3597                                    bool argSaveRegistry /*= true*/)
     3598{
     3599    AssertReturn(argImage != NULL, E_INVALIDARG);
    35843600
    35853601    AutoCaller autoCaller(this);
    35863602    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    35873603
    3588     AutoWriteLock alock(this);
    3589 
    3590     AutoCaller imageCaller (aImage);
     3604    AutoCaller imageCaller(argImage);
    35913605    AssertComRCReturn(imageCaller.rc(), imageCaller.rc());
    35923606
    3593     AutoReadLock imageLock (aImage);
    3594 
    3595     m->llDVDImages.remove (aImage);
     3607    Guid id;
     3608    ComObjPtr<Medium> pParent;
     3609    {
     3610        AutoReadLock al(argImage);
     3611        id = argImage->getId();
     3612        pParent = argImage->getParent();
     3613    }
     3614
     3615    // work on DVDs or floppies list?
     3616    ObjectsList<Medium> &oll = (argType == DeviceType_DVD) ? m->ollDVDImages : m->ollFloppyImages;
     3617
     3618    oll.removeChild(argImage);
    35963619
    35973620    HRESULT rc = S_OK;
    35983621
    3599     if (aSaveRegistry)
     3622    if (argSaveRegistry)
    36003623    {
    36013624        rc = saveSettings();
    3602         if (FAILED (rc))
    3603             registerDVDImage (aImage, false /* aSaveRegistry */);
     3625        if (FAILED(rc))
     3626            registerImage(argImage, argType, false /* aSaveRegistry */);
    36043627    }
    36053628
    36063629    return rc;
    3607 }
    3608 
    3609 /**
    3610  * Remembers the given image by storing it in the floppy image registry.
    3611  *
    3612  * @param aImage        Image object to remember.
    3613  * @param aSaveRegistry @c true to save the image registry to disk (default).
    3614  *
    3615  * When @a aSaveRegistry is @c true, this operation may fail because of the
    3616  * failed #saveSettings() method it calls. In this case, the image object
    3617  * will not be remembered. It is therefore the responsibility of the caller to
    3618  * call this method as the last step of some action that requires registration
    3619  * in order to make sure that only fully functional image objects get
    3620  * registered.
    3621  *
    3622  * @note Locks this object for writing and @a aImage for reading.
    3623  */
    3624 HRESULT VirtualBox::registerFloppyImage(Medium *aImage,
    3625                                         bool aSaveRegistry /*= true*/)
    3626 {
    3627     AssertReturn(aImage != NULL, E_INVALIDARG);
    3628 
    3629     AutoCaller autoCaller(this);
    3630     AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    3631 
    3632     AutoWriteLock alock(this);
    3633 
    3634     AutoCaller imageCaller (aImage);
    3635     AssertComRCReturn(imageCaller.rc(), imageCaller.rc());
    3636 
    3637     AutoReadLock imageLock (aImage);
    3638 
    3639     Utf8Str strConflict;
    3640     HRESULT rc = checkMediaForConflicts2(aImage->getId(),
    3641                                          aImage->getLocationFull(),
    3642                                          strConflict);
    3643     if (FAILED(rc)) return rc;
    3644 
    3645     if (strConflict.length())
    3646     {
    3647         return setError(VBOX_E_INVALID_OBJECT_STATE,
    3648                         tr("Cannot register the floppy image '%s' with UUID {%RTuuid} because a %s already exists in the media registry ('%s')"),
    3649                         aImage->getLocationFull().raw(),
    3650                         aImage->getId().raw(),
    3651                         strConflict.raw(),
    3652                         m->strSettingsFilePath.raw());
    3653     }
    3654 
    3655     /* add to the collection */
    3656     m->llFloppyImages.push_back (aImage);
    3657 
    3658     if (aSaveRegistry)
    3659     {
    3660         rc = saveSettings();
    3661         if (FAILED (rc))
    3662             unregisterFloppyImage(aImage, false /* aSaveRegistry */);
    3663     }
    3664 
    3665     return rc;
    3666 }
    3667 
    3668 /**
    3669  * Removes the given image from the floppy image registry registry.
    3670  *
    3671  * @param aImage        Image object to remove.
    3672  * @param aSaveRegistry @c true to save hard disk registry to disk (default).
    3673  *
    3674  * When @a aSaveRegistry is @c true, this operation may fail because of the
    3675  * failed #saveSettings() method it calls. In this case, the image object
    3676  * will NOT be removed from the registry when this method returns. It is
    3677  * therefore the responsibility of the caller to call this method as the first
    3678  * step of some action that requires unregistration, before calling uninit() on
    3679  * @a aImage.
    3680  *
    3681  * @note Locks this object for writing and @a aImage for reading.
    3682  */
    3683 HRESULT VirtualBox::unregisterFloppyImage(Medium *aImage,
    3684                                           bool aSaveRegistry /*= true*/)
    3685 {
    3686     AssertReturn(aImage != NULL, E_INVALIDARG);
    3687 
    3688     AutoCaller autoCaller(this);
    3689     AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    3690 
    3691     AutoWriteLock alock(this);
    3692 
    3693     AutoCaller imageCaller (aImage);
    3694     AssertComRCReturn(imageCaller.rc(), imageCaller.rc());
    3695 
    3696     AutoReadLock imageLock (aImage);
    3697 
    3698     m->llFloppyImages.remove (aImage);
    3699 
    3700     HRESULT rc = S_OK;
    3701 
    3702     if (aSaveRegistry)
    3703     {
    3704         rc = saveSettings();
    3705         if (FAILED (rc))
    3706             registerFloppyImage (aImage, false /* aSaveRegistry */);
    3707     }
    3708 
    3709     return rc;
    3710 }
    3711 
    3712 /**
    3713  * Attempts to cast from a raw interface pointer to an underlying object.
    3714  * On success, @a aTo will contain the object reference. On failure, @a aTo will
    3715  * be set to @c null and an extended error info will be returned.
    3716  *
    3717  * @param aFrom     Interface pointer to cast from.
    3718  * @param aTo       Where to store a reference to the underlying object.
    3719  *
    3720  * @note Locks #childrenLock() for reading.
    3721  */
    3722 HRESULT VirtualBox::cast (IMedium *aFrom, ComObjPtr<Medium> &aTo)
    3723 {
    3724     AssertReturn(aFrom != NULL, E_INVALIDARG);
    3725 
    3726     AutoCaller autoCaller(this);
    3727     AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    3728 
    3729     /* We need the children map lock here to keep the getDependentChild() result
    3730      * valid until we finish */
    3731     AutoReadLock chLock (childrenLock());
    3732 
    3733     VirtualBoxBase *child = getDependentChild (aFrom);
    3734     if (!child)
    3735         return setError (E_FAIL, tr ("The given hard disk object is not created "
    3736                                      "within this VirtualBox instance"));
    3737 
    3738     /* we can safely cast child to Medium * here because only Medium
    3739      * implementations of IMedium can be among our children */
    3740 
    3741     aTo = static_cast<Medium*>(child);
    3742 
    3743     return S_OK;
    37443630}
    37453631
     
    37543640 * @note Locks this object + DVD, Floppy and HardDisk children for writing.
    37553641 */
    3756 HRESULT VirtualBox::updateSettings (const char *aOldPath, const char *aNewPath)
     3642HRESULT VirtualBox::updateSettings(const char *aOldPath, const char *aNewPath)
    37573643{
    37583644    LogFlowThisFunc(("aOldPath={%s} aNewPath={%s}\n", aOldPath, aNewPath));
     
    37643650    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    37653651
    3766     AutoWriteLock alock(this);
    3767 
    3768     /* check DVD paths */
    3769     for (MediaList::iterator it = m->llDVDImages.begin();
    3770          it != m->llDVDImages.end();
     3652    ObjectsList<Medium> ollAll;
     3653    ollAll.appendOtherList(m->ollDVDImages);
     3654    ollAll.appendOtherList(m->ollFloppyImages);
     3655    ollAll.appendOtherList(m->ollHardDisks);
     3656
     3657    for (MediaList::iterator it = ollAll.begin();
     3658         it != ollAll.end();
    37713659         ++ it)
    37723660    {
    37733661        (*it)->updatePath(aOldPath, aNewPath);
    3774     }
    3775 
    3776     /* check Floppy paths */
    3777     for (MediaList::iterator it = m->llFloppyImages.begin();
    3778          it != m->llFloppyImages  .end();
    3779          ++ it)
    3780     {
    3781         (*it)->updatePath(aOldPath, aNewPath);
    3782     }
    3783 
    3784     /* check HardDisk paths */
    3785     for (MediaList::const_iterator it = m->llHardDisks.begin();
    3786          it != m->llHardDisks.end();
    3787          ++ it)
    3788     {
    3789         (*it)->updatePaths(aOldPath, aNewPath);
    37903662    }
    37913663
     
    38993771RWLockHandle& VirtualBox::hardDiskTreeLockHandle()
    39003772{
    3901     return m->mtxHardDiskTree;
    3902 }
    3903 
    3904 /**
    3905  * Reimplements VirtualBoxWithTypedChildren::childrenLock() to return a
    3906  * dedicated lock instead of the main object lock. The dedicated lock for
    3907  * child map operations frees callers of init() methods of these children
    3908  * from acquiring a write parent (VirtualBox) lock (which would be mandatory
    3909  * otherwise). Since VirtualBox has a lot of heterogenous children which
    3910  * init() methods are called here and there, it definitely makes sense.
    3911  */
    3912 RWLockHandle* VirtualBox::childrenLock()
    3913 {
    3914     return &m->mtxChildrenMap;
     3773    return m->ollHardDisks.getLockHandle();
    39153774}
    39163775
     
    39243783    LogFlowFuncEnter();
    39253784
    3926     VirtualBox *that = (VirtualBox *) pvUser;
    3927     Assert (that);
     3785    VirtualBox *that = (VirtualBox*)pvUser;
     3786    Assert(that);
     3787
     3788    typedef std::vector< ComObjPtr<Machine> > MachineVector;
     3789    typedef std::vector< ComObjPtr<SessionMachine> > SessionMachineVector;
    39283790
    39293791    SessionMachineVector machines;
     
    39783840            {
    39793841                /* machine mutex is released */
    3980                 (machines [rc - WAIT_OBJECT_0 - 1])->checkForDeath();
     3842                (machines[rc - WAIT_OBJECT_0 - 1])->checkForDeath();
    39813843                update = true;
    39823844            }
     
    39843846            {
    39853847                /* machine mutex is abandoned due to client process termination */
    3986                 (machines [rc - WAIT_ABANDONED_0 - 1])->checkForDeath();
     3848                (machines[rc - WAIT_ABANDONED_0 - 1])->checkForDeath();
    39873849                update = true;
    39883850            }
     
    39983860            {
    39993861                /* close old process handles */
    4000                 for (size_t i = 1 + cnt; i < 1 + cnt + cntSpawned; ++ i)
    4001                     CloseHandle (handles [i]);
    4002 
    4003                 AutoReadLock thatLock (that);
     3862                for (size_t i = 1 + cnt; i < 1 + cnt + cntSpawned; ++i)
     3863                    CloseHandle(handles[i]);
     3864
     3865                // lock the machines list for reading
     3866                AutoReadLock thatLock(that->m->ollMachines.getLockHandle());
    40043867
    40053868                /* obtain a new set of opened machines */
     
    40073870                machines.clear();
    40083871
    4009                 for (MachineList::iterator it = that->m->llMachines.begin();
    4010                      it != that->m->llMachines.end(); ++ it)
     3872                for (MachinesOList::iterator it = that->m->ollMachines.begin();
     3873                     it != that->m->ollMachines.end();
     3874                     ++it)
    40113875                {
    40123876                    /// @todo handle situations with more than 64 objects
     
    40163880                    ComObjPtr<SessionMachine> sm;
    40173881                    HANDLE ipcSem;
    4018                     if ((*it)->isSessionOpenOrClosing (sm, NULL, &ipcSem))
     3882                    if ((*it)->isSessionOpenOrClosing(sm, NULL, &ipcSem))
    40193883                    {
    4020                         machines.push_back (sm);
    4021                         handles [1 + cnt] = ipcSem;
    4022                         ++ cnt;
     3884                        machines.push_back(sm);
     3885                        handles[1 + cnt] = ipcSem;
     3886                        ++cnt;
    40233887                    }
    40243888                }
     
    40303894                spawnedMachines.clear();
    40313895
    4032                 for (MachineList::iterator it = that->m->llMachines.begin();
    4033                      it != that->m->llMachines.end(); ++ it)
     3896                for (MachinesOList::iterator it = that->m->ollMachines.begin();
     3897                     it != that->m->ollMachines.end();
     3898                     ++it)
    40343899                {
    40353900                    /// @todo handle situations with more than 64 objects
     
    40383903
    40393904                    RTPROCESS pid;
    4040                     if ((*it)->isSessionSpawning (&pid))
     3905                    if ((*it)->isSessionSpawning(&pid))
    40413906                    {
    4042                         HANDLE ph = OpenProcess (SYNCHRONIZE, FALSE, pid);
     3907                        HANDLE ph = OpenProcess(SYNCHRONIZE, FALSE, pid);
    40433908                        AssertMsg (ph != NULL, ("OpenProcess (pid=%d) failed with %d\n",
    40443909                                                pid, GetLastError()));
    40453910                        if (rc == 0)
    40463911                        {
    4047                             spawnedMachines.push_back (*it);
    4048                             handles [1 + cnt + cntSpawned] = ph;
    4049                             ++ cntSpawned;
     3912                            spawnedMachines.push_back(*it);
     3913                            handles[1 + cnt + cntSpawned] = ph;
     3914                            ++cntSpawned;
    40503915                        }
    40513916                    }
     
    40533918
    40543919                LogFlowFunc (("UPDATE: spawned session count = %d\n", cntSpawned));
     3920
     3921                // machines lock unwinds here
    40553922            }
    40563923        }
     
    40903957            autoCaller.release();
    40913958
    4092             int vrc = RTSemEventWait (that->m->updateReq, 500);
     3959            int vrc = RTSemEventWait(that->m->updateReq, 500);
    40933960
    40943961            /* Restore the caller before using VirtualBox. If it fails, this
     
    41293996#ifdef DEBUG
    41303997                            {
    4131                                 AutoReadLock machineLock (machines [semId]);
     3998                                AutoReadLock machineLock(machines[semId]);
    41323999                                LogFlowFunc (("released mutex: machine='%ls'\n",
    4133                                               machines [semId]->name().raw()));
     4000                                              machines[semId]->name().raw()));
    41344001                            }
    41354002#endif
    4136                             machines [semId]->checkForDeath();
     4003                            machines[semId]->checkForDeath();
    41374004                        }
    41384005                        update = true;
     
    41594026#ifdef DEBUG
    41604027                                    {
    4161                                         AutoReadLock machineLock (machines [semId]);
    4162                                         LogFlowFunc (("mutex owner dead: machine='%ls'\n",
    4163                                                       machines [i]->name().raw()));
     4028                                        AutoReadLock machineLock(machines[semId]);
     4029                                        LogFlowFunc(("mutex owner dead: machine='%ls'\n",
     4030                                                     machines[i]->name().raw()));
    41644031                                    }
    41654032#endif
    4166                                     machines [i]->checkForDeath();
     4033                                    machines[i]->checkForDeath();
    41674034                                }
    41684035                            }
     
    41984065                    machines.clear();
    41994066
    4200                     for (MachineList::iterator it = that->m->llMachines.begin();
     4067                    for (MachinesOList::iterator it = that->m->llMachines.begin();
    42014068                         it != that->m->llMachines.end(); ++ it)
    42024069                    {
     
    42114078                        {
    42124079                            machines.push_back (sm);
    4213                             handles [cnt].hsemCur = (HSEM) ipcSem;
    4214                             handles [cnt].ulUser = cnt;
     4080                            handles[cnt].hsemCur = (HSEM) ipcSem;
     4081                            handles[cnt].ulUser = cnt;
    42154082                            ++ cnt;
    42164083                        }
     
    42364103                    spawnedMachines.clear();
    42374104
    4238                     for (MachineList::iterator it = that->m->llMachines.begin();
     4105                    for (MachinesOList::iterator it = that->m->llMachines.begin();
    42394106                         it != that->m->llMachines.end(); ++ it)
    42404107                    {
     
    42904157                /* RT_SUCCESS(rc) means an update event is signaled */
    42914158
    4292                 AutoReadLock thatLock (that);
     4159                // lock the machines list for reading
     4160                AutoReadLock thatLock(that->m->ollMachines.getLockHandle());
    42934161
    42944162                if (RT_SUCCESS(rc) || update)
     
    42974165                    machines.clear();
    42984166
    4299                     for (MachineList::iterator it = that->m->llMachines.begin();
    4300                          it != that->m->llMachines.end(); ++ it)
     4167                    for (MachinesOList::iterator it = that->m->ollMachines.begin();
     4168                         it != that->m->ollMachines.end();
     4169                         ++it)
    43014170                    {
    43024171                        ComObjPtr<SessionMachine> sm;
    4303                         if ((*it)->isSessionOpenOrClosing (sm))
    4304                             machines.push_back (sm);
     4172                        if ((*it)->isSessionOpenOrClosing(sm))
     4173                            machines.push_back(sm);
    43054174                    }
    43064175
    43074176                    cnt = machines.size();
    4308                     LogFlowFunc (("UPDATE: direct session count = %d\n", cnt));
     4177                    LogFlowFunc(("UPDATE: direct session count = %d\n", cnt));
    43094178                }
    43104179
     
    43144183                    spawnedMachines.clear();
    43154184
    4316                     for (MachineList::iterator it = that->m->llMachines.begin();
    4317                          it != that->m->llMachines.end(); ++ it)
     4185                    for (MachinesOList::iterator it = that->m->ollMachines.begin();
     4186                         it != that->m->ollMachines.end();
     4187                         ++it)
    43184188                    {
    43194189                        if ((*it)->isSessionSpawning())
    4320                             spawnedMachines.push_back (*it);
     4190                            spawnedMachines.push_back(*it);
    43214191                    }
    43224192
    43234193                    cntSpawned = spawnedMachines.size();
    4324                     LogFlowFunc (("UPDATE: spawned session count = %d\n", cntSpawned));
     4194                    LogFlowFunc(("UPDATE: spawned session count = %d\n", cntSpawned));
    43254195                }
     4196
     4197                // machines lock unwinds here
    43264198            }
    43274199
     
    44904362}
    44914363
    4492 //STDMETHODIMP VirtualBox::FindDHCPServerForInterface (IHostNetworkInterface * aIinterface, IDHCPServer ** aServer)
    4493 //{
    4494 //    return E_NOTIMPL;
    4495 //}
    4496 
    4497 STDMETHODIMP VirtualBox::FindDHCPServerByNetworkName (IN_BSTR aName, IDHCPServer ** aServer)
     4364STDMETHODIMP VirtualBox::FindDHCPServerByNetworkName(IN_BSTR aName, IDHCPServer ** aServer)
    44984365{
    44994366    CheckComArgNotNull(aName);
     
    45024369    AutoCaller autoCaller(this);
    45034370    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    4504 
    4505     AutoWriteLock alock(this);
    45064371
    45074372    HRESULT rc;
     
    45094374    ComPtr<DHCPServer> found;
    45104375
    4511     for (DHCPServerList::const_iterator it =
    4512             m->llDHCPServers.begin();
    4513          it != m->llDHCPServers.end();
    4514          ++ it)
    4515     {
    4516         rc = (*it)->COMGETTER(NetworkName) (bstr.asOutParam());
     4376    AutoReadLock alock(m->ollDHCPServers.getLockHandle());
     4377
     4378    for (DHCPServersOList::const_iterator it = m->ollDHCPServers.begin();
     4379         it != m->ollDHCPServers.end();
     4380         ++it)
     4381    {
     4382        rc = (*it)->COMGETTER(NetworkName)(bstr.asOutParam());
    45174383        if (FAILED(rc)) throw rc;
    45184384
    4519         if(bstr == aName)
     4385        if (bstr == aName)
    45204386        {
    45214387            found = *it;
     
    45584424 */
    45594425HRESULT VirtualBox::registerDHCPServer(DHCPServer *aDHCPServer,
    4560                                      bool aSaveRegistry /*= true*/)
     4426                                       bool aSaveRegistry /*= true*/)
    45614427{
    45624428    AssertReturn(aDHCPServer != NULL, E_INVALIDARG);
     
    45654431    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    45664432
    4567     AutoWriteLock alock(this);
    4568 
    4569     AutoCaller dhcpServerCaller (aDHCPServer);
     4433    AutoCaller dhcpServerCaller(aDHCPServer);
    45704434    AssertComRCReturn(dhcpServerCaller.rc(), dhcpServerCaller.rc());
    4571 
    4572     AutoReadLock dhcpServerLock (aDHCPServer);
    45734435
    45744436    Bstr name;
    45754437    HRESULT rc;
    4576     rc = aDHCPServer->COMGETTER(NetworkName) (name.asOutParam());
     4438    rc = aDHCPServer->COMGETTER(NetworkName)(name.asOutParam());
    45774439    if (FAILED(rc)) return rc;
    45784440
    45794441    ComPtr<IDHCPServer> existing;
    45804442    rc = FindDHCPServerByNetworkName(name.mutableRaw(), existing.asOutParam());
    4581     if(SUCCEEDED(rc))
     4443    if (SUCCEEDED(rc))
    45824444    {
    45834445        return E_INVALIDARG;
    45844446    }
     4447
    45854448    rc = S_OK;
    45864449
    4587     m->llDHCPServers.push_back (aDHCPServer);
     4450    m->ollDHCPServers.addChild(aDHCPServer);
    45884451
    45894452    if (aSaveRegistry)
     
    46254488    AssertComRCReturn(dhcpServerCaller.rc(), dhcpServerCaller.rc());
    46264489
    4627     AutoReadLock dhcpServerLock (aDHCPServer);
    4628 
    4629     m->llDHCPServers.remove (aDHCPServer);
     4490    m->ollDHCPServers.removeChild(aDHCPServer);
    46304491
    46314492    HRESULT rc = S_OK;
  • trunk/src/VBox/Main/include/SharedFolderImpl.h

    r25182 r25184  
    3131
    3232class ATL_NO_VTABLE SharedFolder :
    33     public VirtualBoxBase,
     33    public VirtualBoxBaseWithChildrenNEXT,
    3434    public VirtualBoxSupportErrorInfoImpl<SharedFolder, ISharedFolder>,
    3535    public VirtualBoxSupportTranslation<SharedFolder>,
     
    9494protected:
    9595
    96     HRESULT protectedInit (VirtualBoxBaseWithChildrenNEXT *aParent,
    97                            CBSTR aName, CBSTR aHostPath, BOOL aWritable);
     96    HRESULT protectedInit(VirtualBoxBase *aParent,
     97                          CBSTR aName, CBSTR aHostPath, BOOL aWritable);
    9898
    9999private:
    100100
    101     VirtualBoxBaseWithChildrenNEXT *const mParent;
     101    VirtualBoxBase *const mParent;
    102102
    103103    /* weak parents (only one of them is not null) */
  • trunk/src/VBox/Main/include/StorageControllerImpl.h

    r25182 r25184  
    3232
    3333class ATL_NO_VTABLE StorageController :
    34     public VirtualBoxBaseWithChildrenNEXT,
     34    public VirtualBoxBase,
    3535    public VirtualBoxSupportErrorInfoImpl<StorageController, IStorageController>,
    3636    public VirtualBoxSupportTranslation<StorageController>,
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r25182 r25184  
    6060
    6161class ATL_NO_VTABLE VirtualBox :
    62     public VirtualBoxBaseWithChildrenNEXT,
     62    public VirtualBoxBase,
    6363    public VirtualBoxSupportErrorInfoImpl<VirtualBox, IVirtualBox>,
    6464    public VirtualBoxSupportTranslation<VirtualBox>,
     
    257257    HRESULT unregisterHardDisk(Medium *aHardDisk, bool aSaveRegistry = true);
    258258
    259     HRESULT registerDVDImage(Medium *aImage, bool aSaveRegistry = true);
    260     HRESULT unregisterDVDImage(Medium *aImage, bool aSaveRegistry = true);
    261 
    262     HRESULT registerFloppyImage (Medium *aImage, bool aSaveRegistry = true);
    263     HRESULT unregisterFloppyImage (Medium *aImage, bool aSaveRegistry = true);
    264 
    265     HRESULT cast (IMedium *aFrom, ComObjPtr<Medium> &aTo);
     259    HRESULT registerImage(Medium *aImage, DeviceType_T argType, bool aSaveRegistry = true);
     260    HRESULT unregisterImage(Medium *aImage, DeviceType_T argType, bool aSaveRegistry = true);
    266261
    267262    HRESULT saveSettings();
     
    275270
    276271    RWLockHandle& hardDiskTreeLockHandle();
    277     RWLockHandle* childrenLock();
    278272
    279273    /* for VirtualBoxSupportErrorInfoImpl */
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