VirtualBox

Ignore:
Timestamp:
Apr 15, 2008 1:53:12 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
29646
Message:

Main: Implemented true AutoReaderLock (#2768).

File:
1 edited

Legend:

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

    r7277 r7992  
    196196        return E_POINTER;
    197197
    198     AutoLock alock (this);
     198    AutoReaderLock alock (this);
    199199    CHECK_READY();
    200200
     
    208208        return E_POINTER;
    209209
    210     AutoLock alock (this);
     210    AutoReaderLock alock (this);
    211211    CHECK_READY();
    212212
     
    220220        return E_POINTER;
    221221
    222     AutoLock alock (this);
     222    AutoReaderLock alock (this);
    223223    CHECK_READY();
    224224
     
    232232        return E_POINTER;
    233233
    234     AutoLock alock (this);
     234    AutoReaderLock alock (this);
    235235    CHECK_READY();
    236236
     
    274274        return E_POINTER;
    275275
    276     AutoLock alock (this);
     276    AutoReaderLock alock (this);
    277277    CHECK_READY();
    278278
     
    286286        return E_POINTER;
    287287
    288     AutoLock lock(this);
    289     CHECK_READY();
    290 
    291     AutoLock chLock (childrenLock());
     288    AutoReaderLock lock(this);
     289    CHECK_READY();
     290
     291    AutoReaderLock chLock (childrenLock());
    292292
    293293    ComObjPtr <HardDiskCollection> collection;
     
    303303        return E_POINTER;
    304304
    305     AutoLock lock(this);
     305    AutoReaderLock lock(this);
    306306    CHECK_READY();
    307307
     
    368368        return E_POINTER;
    369369
    370     AutoLock alock (this);
     370    AutoReaderLock alock (this);
    371371    CHECK_READY();
    372372
     
    380380        return E_POINTER;
    381381
    382     AutoLock alock (this);
     382    AutoReaderLock alock (this);
    383383    CHECK_READY();
    384384
     
    392392        return E_POINTER;
    393393
    394     AutoLock alock (this);
     394    AutoReaderLock alock (this);
    395395    CHECK_READY();
    396396
     
    600600                                     bool aCheckReaders /* = false */)
    601601{
    602     AutoLock alock (this);
     602    AutoReaderLock alock (this);
    603603    CHECK_READY();
    604604
     
    636636bool HardDisk::sameAs (HardDisk *that)
    637637{
    638     AutoLock alock (this);
     638    AutoReaderLock alock (this);
    639639    if (!isReady())
    640640        return false;
     
    744744bool HardDisk::hasForeignChildren()
    745745{
    746     AutoLock alock (this);
     746    AutoReaderLock alock (this);
    747747    AssertReturn (isReady(), false);
    748748
     
    750750
    751751    /* check all children */
    752     AutoLock chLock (childrenLock());
     752    AutoReaderLock chLock (childrenLock());
    753753    for (HardDiskList::const_iterator it = children().begin();
    754754         it != children().end();
     
    756756    {
    757757        ComObjPtr <HardDisk> child = *it;
    758         AutoLock childLock (child);
     758        AutoReaderLock childLock (child);
    759759        if (child->mMachineId != mMachineId)
    760760            return true;
     
    779779        return setError (E_FAIL, errMsg, toString().raw());
    780780
    781     AutoLock chLock (childrenLock());
     781    AutoReaderLock chLock (childrenLock());
    782782
    783783    for (HardDiskList::const_iterator it = children().begin();
     
    814814    AssertReturn (mBusy == true, (void) 0);
    815815
    816     AutoLock chLock (childrenLock());
     816    AutoReaderLock chLock (childrenLock());
    817817
    818818    for (HardDiskList::const_iterator it = children().begin();
     
    831831/**
    832832 *  Checks that this hard disk and all its direct children are accessible.
     833 *
     834 *  @note Locks this object for writing.
    833835 */
    834836HRESULT HardDisk::getAccessibleWithChildren (Bstr &aAccessError)
    835837{
     838    /* getAccessible() needs a write lock */
    836839    AutoLock alock (this);
    837840    AssertReturn (isReady(), E_FAIL);
     
    841844        return rc;
    842845
    843     AutoLock chLock (childrenLock());
     846    AutoReaderLock chLock (childrenLock());
    844847
    845848    for (HardDiskList::const_iterator it = children().begin();
     
    869872HRESULT HardDisk::checkConsistency()
    870873{
    871     AutoLock alock (this);
     874    AutoReaderLock alock (this);
    872875    AssertReturn (isReady(), E_FAIL);
    873876
     
    886889    HRESULT rc = S_OK;
    887890
    888     AutoLock chLock (childrenLock());
     891    AutoReaderLock chLock (childrenLock());
    889892
    890893    if (mParent.isNull() && mType == HardDiskType_Normal &&
     
    10221025
    10231026    /* update paths of all children */
    1024     AutoLock chLock (childrenLock());
     1027    AutoReaderLock chLock (childrenLock());
    10251028    for (HardDiskList::const_iterator it = children().begin();
    10261029         it != children().end();
     
    12621265 *
    12631266 *  @note
    1264  *      Must be called from under the object's lock
     1267 *      Must be called from under the object's read lock
    12651268 */
    12661269HRESULT HardDisk::saveSettings (settings::Key &aHDNode)
     
    12931296
    12941297    /* save all children */
    1295     AutoLock chLock (childrenLock());
     1298    AutoReaderLock chLock (childrenLock());
    12961299    for (HardDiskList::const_iterator it = children().begin();
    12971300         it != children().end();
     
    12991302    {
    13001303        ComObjPtr <HardDisk> child = *it;
    1301         AutoLock childLock (child);
     1304        AutoReaderLock childLock (child);
    13021305
    13031306        Key hdNode = aHDNode.appendKey ("DiffHardDisk");
     
    15061509        return E_POINTER;
    15071510
    1508     AutoLock alock (this);
     1511    AutoReaderLock alock (this);
    15091512    CHECK_READY();
    15101513
     
    15391542        return E_POINTER;
    15401543
    1541     AutoLock alock (this);
     1544    AutoReaderLock alock (this);
    15421545    CHECK_READY();
    15431546
     
    15551558        return E_POINTER;
    15561559
    1557     AutoLock alock (this);
     1560    AutoReaderLock alock (this);
    15581561    CHECK_READY();
    15591562
     
    15701573        return E_POINTER;
    15711574
    1572     AutoLock alock (this);
     1575    AutoReaderLock alock (this);
    15731576    CHECK_READY();
    15741577
     
    16121615        return E_POINTER;
    16131616
    1614     AutoLock alock (this);
     1617    AutoReaderLock alock (this);
    16151618    CHECK_READY();
    16161619
     
    17081711 *                      accessible, otherwise contains a message describing
    17091712 *                      the reason of inaccessibility.
     1713 *
     1714 *  @note Locks this object for writing.
    17101715 */
    17111716HRESULT HVirtualDiskImage::getAccessible (Bstr &aAccessError)
    17121717{
     1718    /* queryInformation() needs a write lock */
    17131719    AutoLock alock (this);
    17141720    CHECK_READY();
     
    17671773    AssertReturn (!aHDNode.isNull() && !aStorageNode.isNull(), E_FAIL);
    17681774
    1769     AutoLock alock (this);
     1775    AutoReaderLock alock (this);
    17701776    CHECK_READY();
    17711777
     
    18221828 *
    18231829 *  @param aShort       if true, a short representation is returned
     1830 *
     1831 *  @note Locks this object for reading.
    18241832 */
    18251833Bstr HVirtualDiskImage::toString (bool aShort /* = false */)
    18261834{
    1827     AutoLock alock (this);
     1835    AutoReaderLock alock (this);
    18281836
    18291837    if (!aShort)
     
    21192127        HRESULT rc = S_OK;
    21202128
    2121         AutoLock chLock (childrenLock());
     2129        AutoReaderLock chLock (childrenLock());
    21222130
    21232131        for (HardDiskList::const_iterator it = children().begin();
     
    23882396 *  @param aAccessError not used when NULL, otherwise see #getAccessible()
    23892397 *
    2390  *  @note Must be called from under the object's lock, only after
     2398 *  @note Must be called from under the object's write lock, only after
    23912399 *        CHECK_BUSY_AND_READERS() succeeds.
    23922400 */
     
    29562964        return E_POINTER;
    29572965
    2958     AutoLock alock (this);
     2966    AutoReaderLock alock (this);
    29592967    CHECK_READY();
    29602968
     
    29852993        return E_POINTER;
    29862994
    2987     AutoLock alock (this);
     2995    AutoReaderLock alock (this);
    29882996    CHECK_READY();
    29892997
     
    29973005        return E_POINTER;
    29983006
    2999     AutoLock alock (this);
     3007    AutoReaderLock alock (this);
    30003008    CHECK_READY();
    30013009
     
    30123020        return E_POINTER;
    30133021
    3014     AutoLock alock (this);
     3022    AutoReaderLock alock (this);
    30153023    CHECK_READY();
    30163024
     
    30443052        return E_POINTER;
    30453053
    3046     AutoLock alock (this);
     3054    AutoReaderLock alock (this);
    30473055    CHECK_READY();
    30483056
     
    30733081        return E_POINTER;
    30743082
    3075     AutoLock alock (this);
     3083    AutoReaderLock alock (this);
    30763084    CHECK_READY();
    30773085
     
    31053113        return E_POINTER;
    31063114
    3107     AutoLock alock (this);
     3115    AutoReaderLock alock (this);
    31083116    CHECK_READY();
    31093117
     
    31343142        return E_POINTER;
    31353143
    3136     AutoLock alock (this);
     3144    AutoReaderLock alock (this);
    31373145    CHECK_READY();
    31383146
     
    31633171        return E_POINTER;
    31643172
    3165     AutoLock alock (this);
     3173    AutoReaderLock alock (this);
    31663174    CHECK_READY();
    31673175
     
    32143222/**
    32153223 *  Checks accessibility of this iSCSI hard disk.
     3224 *
     3225 *  @note Locks this object for writing.
    32163226 */
    32173227HRESULT HISCSIHardDisk::getAccessible (Bstr &aAccessError)
    32183228{
     3229   /* queryInformation() needs a write lock */
    32193230    AutoLock alock (this);
    32203231    CHECK_READY();
     
    32403251    AssertReturn (!aHDNode.isNull() && !aStorageNode.isNull(), E_FAIL);
    32413252
    3242     AutoLock alock (this);
     3253    AutoReaderLock alock (this);
    32433254    CHECK_READY();
    32443255
     
    32673278 *
    32683279 *  @param aShort       if true, a short representation is returned
     3280 *
     3281 *  @note Locks this object for reading.
    32693282 */
    32703283Bstr HISCSIHardDisk::toString (bool aShort /* = false */)
    32713284{
    3272     AutoLock alock (this);
     3285    AutoReaderLock alock (this);
    32733286
    32743287    Bstr str;
     
    33463359 *
    33473360 *  @param aAccessError see #getAccessible()
    3348  *  @note
    3349  *      Must be called from under the object's lock!
     3361 *
     3362 *  @note Must be called from under the object's write lock, only after
     3363 *        CHECK_BUSY_AND_READERS() succeeds.
    33503364 */
    33513365HRESULT HISCSIHardDisk::queryInformation (Bstr &aAccessError)
    33523366{
     3367    AssertReturn (isLockedOnCurrentThread(), E_FAIL);
     3368
     3369    /* create a lock object to completely release it later */
     3370    AutoLock alock (this);
     3371
    33533372    /// @todo (dmik) query info about this iSCSI disk,
    33543373    //  set mSize and mActualSize,
     
    35723591        return E_POINTER;
    35733592
    3574     AutoLock alock (this);
     3593    AutoReaderLock alock (this);
    35753594    CHECK_READY();
    35763595
     
    36093628        return E_POINTER;
    36103629
    3611     AutoLock alock (this);
     3630    AutoReaderLock alock (this);
    36123631    CHECK_READY();
    36133632
     
    36273646        return E_POINTER;
    36283647
    3629     AutoLock alock (this);
     3648    AutoReaderLock alock (this);
    36303649    CHECK_READY();
    36313650
     
    36423661        return E_POINTER;
    36433662
    3644     AutoLock alock (this);
     3663    AutoReaderLock alock (this);
    36453664    CHECK_READY();
    36463665
     
    36843703        return E_POINTER;
    36853704
    3686     AutoLock alock (this);
     3705    AutoReaderLock alock (this);
    36873706    CHECK_READY();
    36883707
     
    37923811 *                      accessible, otherwise contains a message describing
    37933812 *                      the reason of inaccessibility.
     3813 *
     3814 *  @note Locks this object for writing.
    37943815 */
    37953816HRESULT HVMDKImage::getAccessible (Bstr &aAccessError)
    37963817{
     3818   /* queryInformation() needs a write lock */
    37973819    AutoLock alock (this);
    37983820    CHECK_READY();
     
    38513873    AssertReturn (!aHDNode.isNull() && !aStorageNode.isNull(), E_FAIL);
    38523874
    3853     AutoLock alock (this);
     3875    AutoReaderLock alock (this);
    38543876    CHECK_READY();
    38553877
     
    39063928 *
    39073929 *  @param aShort       if true, a short representation is returned
     3930 *
     3931 *  @note Locks this object for reading.
    39083932 */
    39093933Bstr HVMDKImage::toString (bool aShort /* = false */)
    39103934{
    3911     AutoLock alock (this);
     3935    AutoReaderLock alock (this);
    39123936
    39133937    if (!aShort)
     
    44824506        return E_POINTER;
    44834507
    4484     AutoLock alock (this);
     4508    AutoReaderLock alock (this);
    44854509    CHECK_READY();
    44864510
     
    45044528        return E_POINTER;
    45054529
    4506     AutoLock alock (this);
     4530    AutoReaderLock alock (this);
    45074531    CHECK_READY();
    45084532
     
    45164540        return E_POINTER;
    45174541
    4518     AutoLock alock (this);
     4542    AutoReaderLock alock (this);
    45194543    CHECK_READY();
    45204544
     
    45314555        return E_POINTER;
    45324556
    4533     AutoLock alock (this);
     4557    AutoReaderLock alock (this);
    45344558    CHECK_READY();
    45354559
     
    45774601        return E_POINTER;
    45784602
    4579     AutoLock alock (this);
     4603    AutoReaderLock alock (this);
    45804604    CHECK_READY();
    45814605
     
    45894613        return E_POINTER;
    45904614
    4591     AutoLock alock (this);
     4615    AutoReaderLock alock (this);
    45924616    CHECK_READY();
    45934617
     
    46654689 *                      accessible, otherwise contains a message describing
    46664690 *                      the reason of inaccessibility.
     4691 *
     4692 *  @note Locks this object for writing.
    46674693 */
    46684694HRESULT HCustomHardDisk::getAccessible (Bstr &aAccessError)
    46694695{
     4696   /* queryInformation() needs a write lock */
    46704697    AutoLock alock (this);
    46714698    CHECK_READY();
     
    47244751    AssertReturn (!aHDNode.isNull() && !aStorageNode.isNull(), E_FAIL);
    47254752
    4726     AutoLock alock (this);
     4753    AutoReaderLock alock (this);
    47274754    CHECK_READY();
    47284755
     
    47434770 *
    47444771 *  @param aShort       if true, a short representation is returned
     4772 *
     4773 *  @note Locks this object for reading.
    47454774 */
    47464775Bstr HCustomHardDisk::toString (bool aShort /* = false */)
    47474776{
    4748     AutoLock alock (this);
     4777    AutoReaderLock alock (this);
    47494778
    47504779    /// @todo currently, we assume that location is always a file path for
     
    52705299        return E_POINTER;
    52715300
    5272     AutoLock alock (this);
     5301    AutoReaderLock alock (this);
    52735302    CHECK_READY();
    52745303
     
    53075336        return E_POINTER;
    53085337
    5309     AutoLock alock (this);
     5338    AutoReaderLock alock (this);
    53105339    CHECK_READY();
    53115340
     
    53255354        return E_POINTER;
    53265355
    5327     AutoLock alock (this);
     5356    AutoReaderLock alock (this);
    53285357    CHECK_READY();
    53295358
     
    53405369        return E_POINTER;
    53415370
    5342     AutoLock alock (this);
     5371    AutoReaderLock alock (this);
    53435372    CHECK_READY();
    53445373
     
    53825411        return E_POINTER;
    53835412
    5384     AutoLock alock (this);
     5413    AutoReaderLock alock (this);
    53855414    CHECK_READY();
    53865415
     
    54905519 *                      accessible, otherwise contains a message describing
    54915520 *                      the reason of inaccessibility.
     5521 *
     5522 *  @note Locks this object for writing.
    54925523 */
    54935524HRESULT HVHDImage::getAccessible (Bstr &aAccessError)
    54945525{
     5526    /* queryInformation() needs a write lock */
    54955527    AutoLock alock (this);
    54965528    CHECK_READY();
     
    55485580    AssertReturn (!aHDNode.isNull() && !aStorageNode.isNull(), E_FAIL);
    55495581
    5550     AutoLock alock (this);
     5582    AutoReaderLock alock (this);
    55515583    CHECK_READY();
    55525584
     
    56035635 *
    56045636 *  @param aShort       if true, a short representation is returned
     5637 *
     5638 *  @note Locks this object for reading.
    56055639 */
    56065640Bstr HVHDImage::toString (bool aShort /* = false */)
    56075641{
    5608     AutoLock alock (this);
     5642    AutoReaderLock alock (this);
    56095643
    56105644    if (!aShort)
Note: See TracChangeset for help on using the changeset viewer.

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