VirtualBox

Changeset 25894 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jan 18, 2010 2:16:58 PM (15 years ago)
Author:
vboxsync
Message:

Main: less locks: use the same lock for several lists

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

Legend:

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

    r25880 r25894  
    175175    Data()
    176176        : pMainConfigFile(NULL),
    177           ollMachines(LOCKCLASS_LISTOFMACHINES),
    178           ollGuestOSTypes(LOCKCLASS_LISTOFOTHEROBJECTS),
    179           ollHardDisks(LOCKCLASS_LISTOFMEDIA),
    180           ollDVDImages(LOCKCLASS_LISTOFMEDIA),
    181           ollFloppyImages(LOCKCLASS_LISTOFMEDIA),
    182           ollSharedFolders(LOCKCLASS_LISTOFOTHEROBJECTS),
    183           ollDHCPServers(LOCKCLASS_LISTOFOTHEROBJECTS),
     177          lockMachines(LOCKCLASS_LISTOFMACHINES),
     178          ollMachines(lockMachines),
     179          lockGuestOSTypes(LOCKCLASS_LISTOFOTHEROBJECTS),
     180          ollGuestOSTypes(lockGuestOSTypes),
     181          lockMedia(LOCKCLASS_LISTOFMEDIA),
     182          ollHardDisks(lockMedia),
     183          ollDVDImages(lockMedia),
     184          ollFloppyImages(lockMedia),
     185          lockSharedFolders(LOCKCLASS_LISTOFOTHEROBJECTS),
     186          ollSharedFolders(lockSharedFolders),
     187          lockDHCPServers(LOCKCLASS_LISTOFOTHEROBJECTS),
     188          ollDHCPServers(lockDHCPServers),
    184189          mtxProgressOperations(LOCKCLASS_PROGRESSLIST),
    185190          updateReq(UPDATEREQARG),
     
    203208#endif /* VBOX_WITH_RESOURCE_USAGE_API */
    204209
    205     // the following lists all have an RWLockHandle as a member and are locked
    206     // individually; getting the VirtualBox object lock is NOT necessary, but
    207     // see the remarks which ObjectsList method lock themselves and which require
    208     // external locking
     210    // Each of the following lists use a particular lock handle that protects the
     211    // list as a whole. As opposed to version 3.1 and earlier, these lists no
     212    // longer need the main VirtualBox object lock, but only the respective list
     213    // lock. In each case, the locking order is defined that the list must be
     214    // requested before object locks of members of the lists (see the order definitions
     215    // in AutoLock.h; e.g. LOCKCLASS_LISTOFMACHINES before LOCKCLASS_MACHINEOBJECT).
     216    RWLockHandle                        lockMachines;
    209217    MachinesOList                       ollMachines;
     218
     219    RWLockHandle                        lockGuestOSTypes;
    210220    GuestOSTypesOList                   ollGuestOSTypes;
    211221
    212     MediaOList                          ollHardDisks,           // only base hard disks; the RWLockHandle in here is also used
    213                                                                 // for hardDiskTreeLockHandle()
     222    // All the media lists are protected by the following locking handle:
     223    RWLockHandle                        lockMedia;
     224    MediaOList                          ollHardDisks,
    214225                                        ollDVDImages,
    215226                                        ollFloppyImages;
     227    // the hard disks map is an additional map sorted by UUID for quick lookup
     228    // and contains ALL hard disks (base and differencing); it is protected by
     229    // the same lock as the other media lists above
     230    HardDiskMap                         mapHardDisks;
     231
     232    RWLockHandle                        lockSharedFolders;
    216233    SharedFoldersOList                  ollSharedFolders;
     234
     235    RWLockHandle                        lockDHCPServers;
    217236    DHCPServersOList                    ollDHCPServers;
    218237
    219     // the hard disks map is an additional map sorted by UUID for quick lookup
    220     // and contains ALL hard disks (base and differencing);
    221     // the map must also be protected by ollHardDisks.getLockHandle()!
    222     HardDiskMap                         mapHardDisks;
    223 
     238    RWLockHandle                        mtxProgressOperations;
    224239    ProgressMap                         mapProgressOperations;
    225240    CallbackList                        llCallbacks;
    226241
    227     RWLockHandle                        mtxProgressOperations;
    228242
    229243    // the following are data for the client watcher thread
     
    36583672    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    36593673
    3660     ObjectsList<Medium> ollAll(LOCKCLASS_LISTOFMEDIA);
     3674    RWLockHandle tmpLock(LOCKCLASS_LISTOFMEDIA);        // not really necessary but the ObjectsList<> constructor wants one
     3675    ObjectsList<Medium> ollAll(tmpLock);
    36613676    ollAll.appendOtherList(m->ollDVDImages);
    36623677    ollAll.appendOtherList(m->ollFloppyImages);
  • trunk/src/VBox/Main/include/objectslist.h

    r25834 r25894  
    5959        // http://www.parashift.com/c++-faq-lite/templates.html#faq-35.18
    6060
    61     ObjectsList(VBoxLockingClass lockClass)
    62         : m_lock(lockClass)
     61    ObjectsList(RWLockHandle &lockHandle)
     62        : m_lock(lockHandle)
    6363    { }
    6464
     
    201201private:
    202202    MyList          m_ll;
    203     RWLockHandle    m_lock;
     203    RWLockHandle    &m_lock;
    204204};
    205205
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