VirtualBox

Changeset 38717 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Sep 12, 2011 2:48:50 PM (13 years ago)
Author:
vboxsync
Message:

Main/Medium+Machine+AutoLock: Integrate the queryInfo semaphore into the AutoLock infrastructure with the appropriate lock class. Adjust the locking rules for queryInfo and start propagating them up to the callers. Needs more work, but this is comparably simple: just get the mediaTree lock in the caller if the assert triggers.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/glue/AutoLock.cpp

    r33540 r38717  
    55
    66/*
    7  * Copyright (C) 2006-2010 Oracle Corporation
     7 * Copyright (C) 2006-2011 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    7373        { LOCKCLASS_LISTOFMEDIA,        "7-LISTOFMEDIA" },
    7474        { LOCKCLASS_LISTOFOTHEROBJECTS, "8-LISTOFOTHEROBJECTS" },
    75         { LOCKCLASS_OTHEROBJECT,        "9-OTHEROBJECT" },
    76         { LOCKCLASS_USBLIST,            "10-USBLIST" },
    77         { LOCKCLASS_PROGRESSLIST,       "11-PROGRESSLIST" },
    78         { LOCKCLASS_OBJECTSTATE,        "12-OBJECTSTATE" }
     75        { LOCKCLASS_MEDIUMQUERY,        "9-MEDIUMQUERY" },
     76        { LOCKCLASS_OTHEROBJECT,        "10-OTHEROBJECT" },
     77        { LOCKCLASS_USBLIST,            "11-USBLIST" },
     78        { LOCKCLASS_PROGRESSLIST,       "12-PROGRESSLIST" },
     79        { LOCKCLASS_OBJECTSTATE,        "13-OBJECTSTATE" }
    7980    };
    8081
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r38618 r38717  
    1251312513    AssertComRCReturn(autoCaller.rc(), autoCaller.rc());
    1251412514
    12515     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     12515    AutoMultiWriteLock2 alock(this->lockHandle(),
     12516                              &mParent->getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);
    1251612517
    1251712518    AssertReturn(   mData->mMachineState == MachineState_Starting
  • trunk/src/VBox/Main/src-server/MediumImpl.cpp

    r38709 r38717  
    8888          readers(0),
    8989          preLockState(MediumState_NotCreated),
    90           queryInfoSem(NIL_RTSEMRW),
     90          queryInfoSem(LOCKCLASS_MEDIUMQUERY),
    9191          queryInfoRunning(false),
    9292          type(MediumType_Normal),
     
    129129     * which we had here for many years. Catching possible deadlocks is more
    130130     * important than a tiny bit of efficiency. */
    131     RTSEMRW queryInfoSem;
     131    RWLockHandle queryInfoSem;
    132132    bool queryInfoRunning : 1;
    133133
     
    891891    AssertRCReturn(vrc, E_FAIL);
    892892
    893     vrc = RTSemRWCreate(&m->queryInfoSem);
    894     AssertRCReturn(vrc, E_FAIL);
    895 
    896893    return BaseFinalConstruct();
    897894}
     
    13721369    }
    13731370
    1374     RTSemRWDestroy(m->queryInfoSem);
    1375     m->queryInfoSem = NIL_RTSEMRW;
    1376 
    13771371    unconst(m->pVirtualBox) = NULL;
    13781372}
     
    20082002
    20092003    /* queryInfo() locks this for writing. */
    2010     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     2004    AutoMultiWriteLock2 alock(&m->pVirtualBox->getMediaTreeLockHandle(),
     2005                              this->lockHandle() COMMA_LOCKVAL_SRC_POS);
    20112006
    20122007    HRESULT rc = S_OK;
     
    20962091    {
    20972092        alock.leave();
    2098         RTSemRWRequestRead(m->queryInfoSem, RT_INDEFINITE_WAIT);
    2099         RTSemRWReleaseRead(m->queryInfoSem);
     2093        {
     2094            AutoReadLock qlock(m->queryInfoSem COMMA_LOCKVAL_SRC_POS);
     2095        }
    21002096        alock.enter();
    21012097    }
     
    22032199    {
    22042200        alock.leave();
    2205         RTSemRWRequestRead(m->queryInfoSem, RT_INDEFINITE_WAIT);
    2206         RTSemRWReleaseRead(m->queryInfoSem);
     2201        {
     2202            AutoReadLock qlock(m->queryInfoSem COMMA_LOCKVAL_SRC_POS);
     2203        }
    22072204        alock.enter();
    22082205    }
     
    37613758 * Constructs a medium lock list for this medium. The lock is not taken.
    37623759 *
    3763  * @note Locks the medium tree for reading.
     3760 * @note Caller must lock the medium tree for writing.
    37643761 *
    37653762 * @param fFailIfInaccessible If true, this fails with an error if a medium is inaccessible. If false,
     
    37753772                                     MediumLockList &mediumLockList)
    37763773{
     3774    // Medium::queryInfo needs write lock
     3775    Assert(m->pVirtualBox->getMediaTreeLockHandle().isWriteLockOnCurrentThread());
     3776
    37773777    AutoCaller autoCaller(this);
    37783778    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    37793779
    37803780    HRESULT rc = S_OK;
    3781 
    3782     /* we access parent medium objects */
    3783     AutoReadLock treeLock(m->pVirtualBox->getMediaTreeLockHandle() COMMA_LOCKVAL_SRC_POS);
    37843781
    37853782    /* paranoid sanity checking if the medium has a to-be parent medium */
     
    37973794    while (!pMedium.isNull())
    37983795    {
    3799         // need write lock for RefreshState if medium is inaccessible
     3796        // need write lock for queryInfo if medium is inaccessible
    38003797        AutoWriteLock alock(pMedium COMMA_LOCKVAL_SRC_POS);
    38013798
     
    38063803        if (mediumState == MediumState_Inaccessible)
    38073804        {
    3808             rc = pMedium->RefreshState(&mediumState);
     3805            rc = pMedium->queryInfo(false /* fSetImageId */, false /* fSetParentId */);
    38093806            if (FAILED(rc)) return rc;
    38103807
     3808            mediumState = pMedium->getState();
    38113809            if (mediumState == MediumState_Inaccessible)
    38123810            {
     
    52545252 *       accessibility.
    52555253 *
    5256  * @note Locks medium tree for reading and writing (for new diff media checked
    5257  *       for the first time). Locks mParent for reading. Locks this object for
    5258  *       writing.
     5254 * @note Caller must hold medium tree for writing.
     5255 *
     5256 * @note Locks mParent for reading. Locks this object for writing.
    52595257 *
    52605258 * @param fSetImageId Whether to reset the UUID contained in the image file to the UUID in the medium instance data (see SetIDs())
     
    52645262HRESULT Medium::queryInfo(bool fSetImageId, bool fSetParentId)
    52655263{
     5264    Assert(m->pVirtualBox->getMediaTreeLockHandle().isWriteLockOnCurrentThread());
    52665265    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    52675266
     
    52855284        {
    52865285            alock.leave();
    5287             vrc = RTSemRWRequestRead(m->queryInfoSem, RT_INDEFINITE_WAIT);
    5288             RTSemRWReleaseRead(m->queryInfoSem);
    5289             AssertRC(vrc);
     5286            {
     5287                AutoReadLock qlock(m->queryInfoSem COMMA_LOCKVAL_SRC_POS);
     5288            }
    52905289            alock.enter();
    52915290        }
     
    53505349     * violation: here it would be requesting the object lock (at the beginning
    53515350     * of the method), then SemRW, and below the other way round. */
    5352     vrc = RTSemRWRequestWrite(m->queryInfoSem, RT_INDEFINITE_WAIT);
    5353     AssertRCReturn(vrc, E_FAIL);
     5351    AutoWriteLock qlock(m->queryInfoSem COMMA_LOCKVAL_SRC_POS);
    53545352
    53555353    try
     
    55835581
    55845582    /* unblock anyone waiting for the queryInfo results */
    5585     RTSemRWReleaseWrite(m->queryInfoSem);
     5583    qlock.release();
    55865584    m->queryInfoRunning = false;
    55875585
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