VirtualBox

Changeset 73858 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Aug 23, 2018 1:35:07 PM (6 years ago)
Author:
vboxsync
Message:

Main: bugref:8929: Medium::setDescription has been reordered to avoid redudant lock acquire/release operations

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/MediumImpl.cpp

    r73003 r73858  
    16001600        autoCaller.release();
    16011601
    1602         // locking: we need the tree lock first because we access parent pointers
    1603         // and we need to write-lock the media involved
    1604         AutoWriteLock treeLock(m->pVirtualBox->i_getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);
    1605 
    1606         autoCaller.add();
    1607         AssertComRCThrowRC(autoCaller.rc());
    1608 
    1609         AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     1602        // to avoid redundant locking, which just takes a time, just call required functions.
     1603        // the error will be just stored and will be reported after locks will be acquired again
     1604
     1605        const char *pszError = NULL;
     1606
    16101607
    16111608        /* Build the lock list. */
    1612         alock.release();
    1613         autoCaller.release();
    1614         treeLock.release();
    16151609        rc = i_createMediumLockList(true /* fFailIfInaccessible */,
    16161610                                    this /* pToLockWrite */,
     
    16181612                                    NULL,
    16191613                                    *pMediumLockList);
    1620         treeLock.acquire();
     1614        if (FAILED(rc))
     1615        {
     1616            pszError = tr("Failed to create medium lock list for '%s'");
     1617        }
     1618        else
     1619        {
     1620            rc = pMediumLockList->Lock();
     1621            if (FAILED(rc))
     1622                pszError = tr("Failed to lock media '%s'");
     1623        }
     1624
     1625        // locking: we need the tree lock first because we access parent pointers
     1626        // and we need to write-lock the media involved
     1627        AutoWriteLock treeLock(m->pVirtualBox->i_getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);
     1628
    16211629        autoCaller.add();
    16221630        AssertComRCThrowRC(autoCaller.rc());
    1623         alock.acquire();
     1631
     1632        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    16241633
    16251634        if (FAILED(rc))
    1626         {
    1627             throw setError(rc,
    1628                            tr("Failed to create medium lock list for '%s'"),
    1629                            i_getLocationFull().c_str());
    1630         }
    1631 
    1632         alock.release();
    1633         autoCaller.release();
    1634         treeLock.release();
    1635         rc = pMediumLockList->Lock();
    1636         treeLock.acquire();
    1637         autoCaller.add();
    1638         AssertComRCThrowRC(autoCaller.rc());
    1639         alock.acquire();
    1640 
    1641         if (FAILED(rc))
    1642         {
    1643             throw setError(rc,
    1644                            tr("Failed to lock media '%s'"),
    1645                            i_getLocationFull().c_str());
    1646         }
     1635            throw setError(rc, pszError, i_getLocationFull().c_str());
    16471636
    16481637        /* Set a new description */
    1649         if (SUCCEEDED(rc))
    1650         {
    1651             m->strDescription = aDescription;
    1652         }
     1638        m->strDescription = aDescription;
    16531639
    16541640        // save the settings
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