VirtualBox

Changeset 3412

Show
Ignore:
Timestamp:
07/04/07 13:25:35 (2 years ago)
Author:
vboxsync
Message:

Main: Converted USBDeviceFilter and HostUSBDeviceFilter to the new locking scheme.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/VBox/Main/USBDeviceFilterImpl.cpp

    r2981 r3412  
    2727#include "Logging.h" 
    2828 
     29#include <iprt/cpputils.h> 
     30 
    2931//////////////////////////////////////////////////////////////////////////////// 
    3032// USBDeviceFilter 
     
    3436//////////////////////////////////////////////////////////////////////////////// 
    3537 
     38DEFINE_EMPTY_CTOR_DTOR (USBDeviceFilter) 
     39 
    3640HRESULT USBDeviceFilter::FinalConstruct() 
    3741{ 
     
    4852 
    4953/** 
    50  * Initializes the USB device filter object. 
     54 *  Initializes the USB device filter object. 
     55 * 
     56 *  @param aParent  Handle of the parent object. 
    5157 */ 
    5258HRESULT USBDeviceFilter::init (USBController *aParent, 
     
    5864                               INPTR BSTR aPort, INPTR BSTR aRemote) 
    5965{ 
    60     LogFlowMember (("USBDeviceFilter::init (%p)\n", aParent)); 
     66    LogFlowThisFunc (("aParent=%p\n", aParent)); 
    6167 
    6268    ComAssertRet (aParent && aName && *aName, E_INVALIDARG); 
    6369 
    64     AutoLock alock (this); 
    65     ComAssertRet (!isReady(), E_UNEXPECTED); 
    66  
    67     mParent = aParent; 
     70    /* Enclose the state transition NotReady->InInit->Ready */ 
     71    AutoInitSpan autoInitSpan (this); 
     72    AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 
     73 
     74    unconst (mParent) = aParent; 
     75    /* mPeer is left null */ 
     76 
     77    /* register with parent early, since uninit() will unconditionally 
     78     * unregister on failure */ 
     79    mParent->addDependentChild (this); 
    6880 
    6981    mData.allocate(); 
     
    7183    mData->mActive = aActive; 
    7284 
    73     // initialize all filters to any match using null string 
     85    /* initialize all filters to any match using null string */ 
    7486    mData->mVendorId = NULL; 
    7587    mData->mProductId = NULL; 
     
    8395    mInList = false; 
    8496 
    85     // use setters for the attributes below to reuse parsing errors handling 
    86     setReady (true); 
     97    /* use setters for the attributes below to reuse parsing errors 
     98     * handling */ 
     99 
    87100    HRESULT rc = S_OK; 
    88101    do 
    89102    { 
    90103        rc = COMSETTER(VendorId) (aVendorId); 
    91         if (FAILED (rc)) 
    92             break; 
     104        CheckComRCBreakRC (rc); 
    93105        rc = COMSETTER(ProductId) (aProductId); 
    94         if (FAILED (rc)) 
    95             break; 
     106        CheckComRCBreakRC (rc); 
    96107        rc = COMSETTER(Revision) (aRevision); 
    97         if (FAILED (rc)) 
    98             break; 
     108        CheckComRCBreakRC (rc); 
    99109        rc = COMSETTER(Manufacturer) (aManufacturer); 
    100         if (FAILED (rc)) 
    101             break; 
     110        CheckComRCBreakRC (rc); 
    102111        rc = COMSETTER(Product) (aProduct); 
    103         if (FAILED (rc)) 
    104             break; 
     112        CheckComRCBreakRC (rc); 
    105113        rc = COMSETTER(SerialNumber) (aSerialNumber); 
    106         if (FAILED (rc)) 
    107             break; 
     114        CheckComRCBreakRC (rc); 
    108115        rc = COMSETTER(Port) (aPort); 
    109         if (FAILED (rc)) 
    110             break; 
     116        CheckComRCBreakRC (rc); 
    111117        rc = COMSETTER(Remote) (aRemote); 
    112         if (FAILED (rc)) 
    113             break; 
     118        CheckComRCBreakRC (rc); 
    114119    } 
    115120    while (0); 
    116121 
     122    /* Confirm successful initialization when it's the case */ 
    117123    if (SUCCEEDED (rc)) 
    118         mParent->addDependentChild (this); 
    119     else 
    120         setReady (false); 
     124        autoInitSpan.setSucceeded(); 
    121125 
    122126    return rc; 
     
    124128 
    125129/** 
    126  * Initializes the USB device filter object (short version). 
     130 *  Initializes the USB device filter object (short version). 
     131 * 
     132 *  @param aParent  Handle of the parent object. 
    127133 */ 
    128134HRESULT USBDeviceFilter::init (USBController *aParent, INPTR BSTR aName) 
    129135{ 
    130     LogFlowMember (("USBDeviceFilter::init (%p) [short]\n", aParent)); 
     136    LogFlowThisFunc (("aParent=%p\n", aParent)); 
    131137 
    132138    ComAssertRet (aParent && aName && *aName, E_INVALIDARG); 
    133139 
    134     AutoLock alock (this); 
    135     ComAssertRet (!isReady(), E_UNEXPECTED); 
    136  
    137     mParent = aParent; 
    138     // mPeer is left null 
     140    /* Enclose the state transition NotReady->InInit->Ready */ 
     141    AutoInitSpan autoInitSpan (this); 
     142    AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 
     143 
     144    unconst (mParent) = aParent; 
     145    /* mPeer is left null */ 
     146 
     147    /* register with parent early, since uninit() will unconditionally 
     148     * unregister on failure */ 
     149    mParent->addDependentChild (this); 
    139150 
    140151    mData.allocate(); 
     
    143154    mData->mActive = FALSE; 
    144155 
    145     // initialize all filters to any match using null string 
     156    /* initialize all filters to any match using null string */ 
    146157    mData->mVendorId = NULL; 
    147158    mData->mProductId = NULL; 
     
    155166    mInList = false; 
    156167 
    157     mParent->addDependentChild (this); 
    158  
    159     setReady (true); 
     168    /* Confirm successful initialization */ 
     169    autoInitSpan.setSucceeded(); 
     170 
    160171    return S_OK; 
    161172} 
     
    173184 *  @note This object must be destroyed before the original object 
    174185 *  it shares data with is destroyed. 
     186 * 
     187 *  @note Locks @a aThat object for writing if @a aReshare is @c true, or for 
     188 *  reading if @a aReshare is false. 
    175189 */ 
    176190HRESULT USBDeviceFilter::init (USBController *aParent, USBDeviceFilter *aThat, 
    177191                               bool aReshare /* = false */) 
    178192{ 
    179     LogFlowMember (("USBDeviceFilter::init (%p, %p): aReshare=%d\n", 
    180                     aParent, aThat, aReshare)); 
     193    LogFlowThisFunc (("aParent=%p, aThat=%p, aReshare=%RTbool\n", 
     194                      aParent, aThat, aReshare)); 
    181195 
    182196    ComAssertRet (aParent && aThat, E_INVALIDARG); 
    183197 
    184     AutoLock alock (this); 
    185     ComAssertRet (!isReady(), E_UNEXPECTED); 
    186  
    187     mParent = aParent; 
    188  
    189     AutoLock thatlock (aThat); 
     198    /* Enclose the state transition NotReady->InInit->Ready */ 
     199    AutoInitSpan autoInitSpan (this); 
     200    AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 
     201 
     202    unconst (mParent) = aParent; 
     203 
     204    /* register with parent early, since uninit() will unconditionally 
     205     * unregister on failure */ 
     206    mParent->addDependentChild (this); 
     207 
     208    /* sanity */ 
     209    AutoCaller thatCaller (aThat); 
     210    AssertComRCReturnRC (thatCaller.rc()); 
     211 
    190212    if (aReshare) 
    191213    { 
    192         aThat->mPeer = this; 
     214        AutoLock thatLock (aThat); 
     215 
     216        unconst (aThat->mPeer) = this; 
    193217        mData.attach (aThat->mData); 
    194218    } 
    195219    else 
    196220    { 
    197         mPeer = aThat; 
     221        unconst (mPeer) = aThat; 
     222 
     223        AutoReaderLock thatLock (aThat); 
    198224        mData.share (aThat->mData); 
    199225    } 
    200226 
    201     // the arbitrary ID field is not reset because 
    202     // the copy is a shadow of the original 
     227    /* the arbitrary ID field is not reset because 
     228    * the copy is a shadow of the original */ 
    203229 
    204230    mInList = aThat->mInList; 
    205231 
    206     mParent->addDependentChild (this); 
    207  
    208     setReady (true); 
     232    /* Confirm successful initialization */ 
     233    autoInitSpan.setSucceeded(); 
     234 
    209235    return S_OK; 
    210236} 
     
    214240 *  (a kind of copy constructor). This object makes a private copy of data 
    215241 *  of the original object passed as an argument. 
     242 * 
     243 *  @note Locks @a aThat object for reading. 
    216244 */ 
    217245HRESULT USBDeviceFilter::initCopy (USBController *aParent, USBDeviceFilter *aThat) 
    218246{ 
    219     LogFlowMember (("USBDeviceFilter::initCopy (%p, %p)\n", aParent, aThat)); 
     247    LogFlowThisFunc (("aParent=%p, aThat=%p\n", aParent, aThat)); 
    220248 
    221249    ComAssertRet (aParent && aThat, E_INVALIDARG); 
    222250 
    223     AutoLock alock (this); 
    224     ComAssertRet (!isReady(), E_UNEXPECTED); 
    225  
    226     mParent = aParent; 
    227     // mPeer is left null 
    228  
    229     AutoLock thatlock (aThat); 
     251    /* Enclose the state transition NotReady->InInit->Ready */ 
     252    AutoInitSpan autoInitSpan (this); 
     253    AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 
     254 
     255    unconst (mParent) = aParent; 
     256    /* mPeer is left null */ 
     257 
     258    /* register with parent early, since uninit() will unconditionally 
     259     * unregister on failure */ 
     260    mParent->addDependentChild (this); 
     261 
     262    /* sanity */ 
     263    AutoCaller thatCaller (aThat); 
     264    AssertComRCReturnRC (thatCaller.rc()); 
     265 
     266    AutoReaderLock thatLock (aThat); 
    230267    mData.attachCopy (aThat->mData); 
    231268 
    232     // reset the arbitrary ID field 
    233     // (this field is something unique that two distinct objects, even if they 
    234     // are deep copies of each other, should not share) 
     269    /* reset the arbitrary ID field 
     270    * (this field is something unique that two distinct objects, even if they 
     271    * are deep copies of each other, should not share) */ 
    235272    mData->mId = NULL; 
    236273 
    237274    mInList = aThat->mInList; 
    238275 
    239     mParent->addDependentChild (this); 
    240  
    241     setReady (true); 
     276    /* Confirm successful initialization */ 
     277    autoInitSpan.setSucceeded(); 
     278 
    242279    return S_OK; 
    243280} 
     
    249286void USBDeviceFilter::uninit() 
    250287{ 
    251     LogFlowMember (("USBDeviceFilter::uninit()\n")); 
    252  
    253     AutoLock alock (this); 
    254  
    255     LogFlowMember (("USBDeviceFilter::uninit(): isReady=%d\n", isReady())); 
    256  
    257     if (!isReady()) 
     288    LogFlowThisFunc (("\n")); 
     289 
     290    /* Enclose the state transition Ready->InUninit->NotReady */ 
     291    AutoUninitSpan autoUninitSpan (this); 
     292    if (autoUninitSpan.uninitDone()) 
    258293        return; 
    259294 
     
    262297    mData.free(); 
    263298 
    264     setReady (false); 
    265  
    266     alock.leave(); 
    267299    mParent->removeDependentChild (this); 
    268     alock.enter(); 
    269  
    270     mPeer.setNull(); 
    271     mParent.setNull(); 
     300 
     301    unconst (mPeer).setNull(); 
     302    unconst (mParent).setNull(); 
    272303} 
    273304 
     
    280311        return E_POINTER; 
    281312 
    282     AutoLock alock (this); 
    283     CHECK_READY(); 
     313    AutoCaller autoCaller (this); 
     314    CheckComRCReturnRC (autoCaller.rc()); 
     315 
     316    AutoReaderLock alock (this); 
    284317 
    285318    mData->mName.cloneTo (aName); 
     319 
    286320    return S_OK; 
    287321} 
     
    292326        return E_INVALIDARG; 
    293327 
    294     AutoLock alock (this); 
    295     CHECK_READY(); 
    296     CHECK_MACHINE_MUTABILITY (mParent->parent()); 
     328    AutoCaller autoCaller (this); 
     329    CheckComRCReturnRC (autoCaller.rc()); 
     330 
     331    /* the machine needs to be mutable */ 
     332    Machine::AutoMutableStateDependency adep (mParent->parent()); 
     333    CheckComRCReturnRC (adep.rc()); 
     334 
     335    AutoLock alock (this); 
    297336 
    298337    if (mData->mName != aName) 
     
    301340        mData->mName = aName; 
    302341 
    303         // notify parent 
    304         alock.unlock(); 
     342        /* leave the lock before informing callbacks */ 
     343        alock.unlock(); 
     344 
    305345        return mParent->onDeviceFilterChange (this); 
    306346    } 
     
    314354        return E_POINTER; 
    315355 
    316     AutoLock alock (this); 
    317     CHECK_READY(); 
     356    AutoCaller autoCaller (this); 
     357    CheckComRCReturnRC (autoCaller.rc()); 
     358 
     359    AutoReaderLock alock (this); 
    318360 
    319361    *aActive = mData->mActive; 
     362 
    320363    return S_OK; 
    321364} 
     
    323366STDMETHODIMP USBDeviceFilter::COMSETTER(Active) (BOOL aActive) 
    324367{ 
    325     AutoLock alock (this); 
    326     CHECK_READY(); 
    327     CHECK_MACHINE_MUTABILITY (mParent->parent()); 
     368    AutoCaller autoCaller (this); 
     369    CheckComRCReturnRC (autoCaller.rc()); 
     370 
     371    /* the machine needs to be mutable */ 
     372    Machine::AutoMutableStateDependency adep (mParent->parent()); 
     373    CheckComRCReturnRC (adep.rc()); 
     374 
     375    AutoLock alock (this); 
    328376 
    329377    if (mData->mActive != aActive) 
     
    332380        mData->mActive = aActive; 
    333381 
    334         // notify parent 
    335         alock.unlock(); 
     382        /* leave the lock before informing callbacks */ 
     383        alock.unlock(); 
     384 
    336385        return mParent->onDeviceFilterChange (this, TRUE /* aActiveChanged */); 
    337386    } 
     
    345394        return E_POINTER; 
    346395 
    347     AutoLock alock (this); 
    348     CHECK_READY(); 
     396    AutoCaller autoCaller (this); 
     397    CheckComRCReturnRC (autoCaller.rc()); 
     398 
     399    AutoReaderLock alock (this); 
    349400 
    350401    mData->mVendorId.string().cloneTo (aVendorId); 
     402 
    351403    return S_OK; 
    352404} 
     
    354406STDMETHODIMP USBDeviceFilter::COMSETTER(VendorId) (INPTR BSTR aVendorId) 
    355407{ 
    356     AutoLock alock (this); 
    357     CHECK_READY(); 
    358     CHECK_MACHINE_MUTABILITY (mParent->parent()); 
     408    AutoCaller autoCaller (this); 
     409    CheckComRCReturnRC (autoCaller.rc()); 
     410 
     411    /* the machine needs to be mutable */ 
     412    Machine::AutoMutableStateDependency adep (mParent->parent()); 
     413    CheckComRCReturnRC (adep.rc()); 
     414 
     415    AutoLock alock (this); 
    359416 
    360417    if (mData->mVendorId.string() != aVendorId) 
     
    377434        mData->mVendorId = flt; 
    378435 
    379         // notify parent 
    380         alock.unlock(); 
     436        /* leave the lock before informing callbacks */ 
     437        alock.unlock(); 
     438 
    381439        return mParent->onDeviceFilterChange (this); 
    382440    } 
     
    390448        return E_POINTER; 
    391449 
    392     AutoLock alock (this); 
    393     CHECK_READY(); 
     450    AutoCaller autoCaller (this); 
     451    CheckComRCReturnRC (autoCaller.rc()); 
     452 
     453    AutoReaderLock alock (this); 
    394454 
    395455    mData->mProductId.string().cloneTo (aProductId); 
     456 
    396457    return S_OK; 
    397458} 
     
    399460STDMETHODIMP USBDeviceFilter::COMSETTER(ProductId) (INPTR BSTR aProductId) 
    400461{ 
    401     AutoLock alock (this); 
    402     CHECK_READY(); 
    403     CHECK_MACHINE_MUTABILITY (mParent->parent()); 
     462    AutoCaller autoCaller (this); 
     463    CheckComRCReturnRC (autoCaller.rc()); 
     464 
     465    /* the machine needs to be mutable */ 
     466    Machine::AutoMutableStateDependency adep (mParent->parent()); 
     467    CheckComRCReturnRC (adep.rc()); 
     468 
     469    AutoLock alock (this); 
    404470 
    405471    if (mData->mProductId.string() != aProductId) 
     
    422488        mData->mProductId = flt; 
    423489 
    424         // notify parent 
    425         alock.unlock(); 
     490        /* leave the lock before informing callbacks */ 
     491        alock.unlock(); 
     492 
    426493        return mParent->onDeviceFilterChange (this); 
    427494    } 
     
    435502        return E_POINTER; 
    436503 
    437     AutoLock alock (this); 
    438     CHECK_READY(); 
     504    AutoCaller autoCaller (this); 
     505    CheckComRCReturnRC (autoCaller.rc()); 
     506 
     507    AutoReaderLock alock (this); 
    439508 
    440509    mData->mRevision.string().cloneTo (aRevision); 
     510 
    441511    return S_OK; 
    442512} 
     
    444514STDMETHODIMP USBDeviceFilter::COMSETTER(Revision) (INPTR BSTR aRevision) 
    445515{ 
    446     AutoLock alock (this); 
    447     CHECK_READY(); 
    448     CHECK_MACHINE_MUTABILITY (mParent->parent()); 
     516    AutoCaller autoCaller (this); 
     517    CheckComRCReturnRC (autoCaller.rc()); 
     518 
     519    /* the machine needs to be mutable */ 
     520    Machine::AutoMutableStateDependency adep (mParent->parent()); 
     521    CheckComRCReturnRC (adep.rc()); 
     522 
     523    AutoLock alock (this); 
    449524 
    450525    if (mData->mRevision.string() != aRevision) 
     
    467542        mData->mRevision = flt; 
    468543 
    469         // notify parent 
    470         alock.unlock(); 
     544        /* leave the lock before informing callbacks */ 
     545        alock.unlock(); 
     546 
    471547        return mParent->onDeviceFilterChange (this); 
    472548    } 
     
    480556        return E_POINTER; 
    481557 
    482     AutoLock alock (this); 
    483     CHECK_READY(); 
     558    AutoCaller autoCaller (this); 
     559    CheckComRCReturnRC (autoCaller.rc()); 
     560 
     561    AutoReaderLock alock (this); 
    484562 
    485563    mData->mManufacturer.string().cloneTo (aManufacturer); 
     
    489567STDMETHODIMP USBDeviceFilter::COMSETTER(Manufacturer) (INPTR BSTR aManufacturer) 
    490568{ 
    491     AutoLock alock (this); 
    492     CHECK_READY(); 
    493     CHECK_MACHINE_MUTABILITY (mParent->parent()); 
     569    AutoCaller autoCaller (this); 
     570    CheckComRCReturnRC (autoCaller.rc()); 
     571 
     572    /* the machine needs to be mutable */ 
     573    Machine::AutoMutableStateDependency adep (mParent->parent()); 
     574    CheckComRCReturnRC (adep.rc()); 
     575 
     576    AutoLock alock (this); 
    494577 
    495578    if (mData->mManufacturer.string() != aManufacturer) 
     
    505588        mData->mManufacturer = flt; 
    506589 
    507         // notify parent 
    508         alock.unlock(); 
     590        /* leave the lock before informing callbacks */ 
     591        alock.unlock(); 
     592 
    509593        return mParent->onDeviceFilterChange (this); 
    510594    } 
     
    518602        return E_POINTER; 
    519603 
    520     AutoLock alock (this); 
    521     CHECK_READY(); 
     604    AutoCaller autoCaller (this); 
     605    CheckComRCReturnRC (autoCaller.rc()); 
     606 
     607    AutoReaderLock alock (this); 
    522608 
    523609    mData->mProduct.string().cloneTo (aProduct); 
     610 
    524611    return S_OK; 
    525612} 
     
    527614STDMETHODIMP USBDeviceFilter::COMSETTER(Product) (INPTR BSTR aProduct) 
    528615{ 
    529     AutoLock alock (this); 
    530     CHECK_READY(); 
    531     CHECK_MACHINE_MUTABILITY (mParent->parent()); 
     616    AutoCaller autoCaller (this); 
     617    CheckComRCReturnRC (autoCaller.rc()); 
     618 
     619    /* the machine needs to be mutable */ 
     620    Machine::AutoMutableStateDependency adep (mParent->parent()); 
     621    CheckComRCReturnRC (adep.rc()); 
     622 
     623    AutoLock alock (this); 
    532624 
    533625    if (mData->mProduct.string() != aProduct) 
     
    543635        mData->mProduct = flt; 
    544636 
    545         // notify parent 
    546         alock.unlock(); 
     637        /* leave the lock before informing callbacks */ 
     638        alock.unlock(); 
     639 
    547640        return mParent->onDeviceFilterChange (this); 
    548641    } 
     
    556649        return E_POINTER; 
    557650 
    558     AutoLock alock (this); 
    559     CHECK_READY(); 
     651    AutoCaller autoCaller (this); 
     652    CheckComRCReturnRC (autoCaller.rc()); 
     653 
     654    AutoReaderLock alock (this); 
    560655 
    561656    mData->mSerialNumber.string().cloneTo (aSerialNumber); 
     657 
    562658    return S_OK; 
    563659} 
     
    565661STDMETHODIMP USBDeviceFilter::COMSETTER(SerialNumber) (INPTR BSTR aSerialNumber) 
    566662{ 
    567     AutoLock alock (this); 
    568     CHECK_READY(); 
    569     CHECK_MACHINE_MUTABILITY (mParent->parent()); 
     663    AutoCaller autoCaller (this); 
     664    CheckComRCReturnRC (autoCaller.rc()); 
     665 
     666    /* the machine needs to be mutable */ 
     667    Machine::AutoMutableStateDependency adep (mParent->parent()); 
     668    CheckComRCReturnRC (adep.rc()); 
     669 
     670    AutoLock alock (this); 
    570671 
    571672    if (mData->mSerialNumber.string() != aSerialNumber) 
     
    581682        mData->mSerialNumber = flt; 
    582683 
    583         // notify parent 
    584         alock.unlock(); 
     684        /* leave the lock before informing callbacks */ 
     685        alock.unlock(); 
     686 
    585687        return mParent->onDeviceFilterChange (this); 
    586688    } 
     
    594696        return E_POINTER; 
    595697 
    596     AutoLock alock (this); 
    597     CHECK_READY(); 
     698    AutoCaller autoCaller (this); 
     699    CheckComRCReturnRC (autoCaller.rc()); 
     700 
     701    AutoReaderLock alock (this); 
    598702 
    599703    mData->mPort.string().cloneTo (aPort); 
     704 
    600705    return S_OK; 
    601706} 
     
    603708STDMETHODIMP USBDeviceFilter::COMSETTER(Port) (INPTR BSTR aPort) 
    604709{ 
    605     AutoLock alock (this); 
    606     CHECK_READY(); 
    607     CHECK_MACHINE_MUTABILITY (mParent->parent()); 
     710    AutoCaller autoCaller (this); 
     711    CheckComRCReturnRC (autoCaller.rc()); 
     712 
     713    /* the machine needs to be mutable */ 
     714    Machine::AutoMutableStateDependency adep (mParent->parent()); 
     715    CheckComRCReturnRC (adep.rc()); 
     716 
     717    AutoLock alock (this); 
    608718 
    609719    if (mData->mPort.string() != aPort) 
     
    626736        mData->mPort = flt; 
    627737 
    628         // notify parent 
    629         alock.unlock(); 
     738        /* leave the lock before informing callbacks */ 
     739        alock.unlock(); 
     740 
    630741        return mParent->onDeviceFilterChange (this); 
    631742    } 
     
    639750        return E_POINTER; 
    640751 
    641     AutoLock alock (this); 
    642     CHECK_READY(); 
     752    AutoCaller autoCaller (this); 
     753    CheckComRCReturnRC (autoCaller.rc()); 
     754 
     755    AutoReaderLock alock (this); 
    643756 
    644757    mData->mRemote.string().cloneTo (aRemote); 
     758 
    645759    return S_OK; 
    646760} 
     
    648762STDMETHODIMP USBDeviceFilter::COMSETTER(Remote) (INPTR BSTR aRemote) 
    649763{ 
    650     AutoLock alock (this); 
    651     CHECK_READY(); 
    652     CHECK_MACHINE_MUTABILITY (mParent->parent()); 
     764    AutoCaller autoCaller (this); 
     765    CheckComRCReturnRC (autoCaller.rc()); 
     766 
     767    /* the machine needs to be mutable */ 
     768    Machine::AutoMutableStateDependency adep (mParent->parent()); 
     769    CheckComRCReturnRC (adep.rc()); 
     770 
     771    AutoLock alock (this); 
    653772 
    654773    if (mData->mRemote.string() != aRemote) 
     
    664783        mData->mRemote = flt; 
    665784 
    666         // notify parent 
    667         alock.unlock(); 
     785        /* leave the lock before informing callbacks */ 
     786        alock.unlock(); 
     787 
    668788        return mParent->onDeviceFilterChange (this); 
    669789    } 
     
    675795//////////////////////////////////////////////////////////////////////////////// 
    676796 
     797/**  
     798 *  @note Locks this object for writing. 
     799 */ 
     800bool USBDeviceFilter::rollback() 
     801{ 
     802    /* sanity */ 
     803    AutoCaller autoCaller (this); 
     804    AssertComRCReturn (autoCaller.rc(), false); 
     805 
     806    AutoLock alock (this); 
     807 
     808    bool changed = false; 
     809 
     810    if (mData.isBackedUp()) 
     811    { 
     812        /* we need to check all data to see whether anything will be changed 
     813         * after rollback */ 
     814        changed = mData.hasActualChanges(); 
     815        mData.rollback(); 
     816    } 
     817 
     818    return changed; 
     819} 
     820 
     821/**  
     822 *  @note Locks this object for writing, together with the peer object (also 
     823 *  for writing) if there is one. 
     824 */ 
    677825void USBDeviceFilter::commit() 
    678826{ 
    679     AutoLock alock (this); 
     827    /* sanity */ 
     828    AutoCaller autoCaller (this); 
     829    AssertComRCReturnVoid (autoCaller.rc()); 
     830 
     831    /* sanity too */ 
     832    AutoCaller thatCaller (mPeer); 
     833    AssertComRCReturnVoid (thatCaller.rc()); 
     834 
     835    /* lock both for writing since we modify both */ 
     836    AutoMultiLock <2> alock (this->wlock(), AutoLock::maybeWlock (mPeer)); 
     837 
    680838    if (mData.isBackedUp()) 
    681839    { 
     
    683841        if (mPeer) 
    684842        { 
    685             // attach new data to the peer and reshare it 
    686             AutoLock peerlock (mPeer); 
     843            /* attach new data to the peer and reshare it */ 
    687844            mPeer->mData.attach (mData); 
    688845        } 
     
    693850 *  Cancels sharing (if any) by making an independent copy of data. 
    694851 *  This operation also resets this object's peer to NULL. 
     852 * 
     853 *  @note Locks this object for writing, together with the peer object 
     854 *  represented by @a aThat (locked for reading). 
    695855 */ 
    696856void USBDeviceFilter::unshare() 
    697857{ 
    698     AutoLock alock (this); 
     858    /* sanity */ 
     859    AutoCaller autoCaller (this); 
     860    AssertComRCReturnVoid (autoCaller.rc()); 
     861 
     862    /* sanity too */ 
     863    AutoCaller thatCaller (mPeer); 
     864    AssertComRCReturnVoid (thatCaller.rc()); 
     865      
     866    /* peer is not modified, lock it for reading */ 
     867    AutoMultiLock <2> alock (this->wlock(), AutoLock::maybeRlock (mPeer)); 
     868    
    699869    if (mData.isShared()) 
    700870    { 
     871 
    701872        if (!mData.isBackedUp()) 
    702873            mData.backup(); 
     874 
    703875        mData.commit(); 
    704876    } 
    705     mPeer.setNull(); 
     877 
     878    unconst (mPeer).setNull(); 
    706879} 
    707880 
     
    713886//////////////////////////////////////////////////////////////////////////////// 
    714887 
     888DEFINE_EMPTY_CTOR_DTOR (HostUSBDeviceFilter) 
     889 
    715890HRESULT HostUSBDeviceFilter::FinalConstruct() 
    716891{ 
     
    727902 
    728903/** 
    729  * Initializes the USB device filter object. 
     904 *  Initializes the USB device filter object. 
     905 * 
     906 *  @param aParent  Handle of the parent object. 
    730907 */ 
    731908HRESULT HostUSBDeviceFilter::init (Host *aParent, 
     
    738915                                   USBDeviceFilterAction_T aAction) 
    739916{ 
    740     LogFlowMember (("HostUSBDeviceFilter::init(): isReady=%d\n", isReady())); 
     917    LogFlowThisFunc (("aParent=%p\n", aParent)); 
    741918 
    742919    ComAssertRet (aParent && aName && *aName, E_INVALIDARG); 
    743920 
    744     AutoLock alock (this); 
    745     ComAssertRet (!isReady(), E_UNEXPECTED); 
    746  
    747     mParent = aParent; 
     921    /* Enclose the state transition NotReady->InInit->Ready */ 
     922    AutoInitSpan autoInitSpan (this); 
     923    AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 
     924 
     925    unconst (mParent) = aParent; 
     926 
     927    /* register with parent early, since uninit() will unconditionally 
     928     * unregister on failure */ 
     929    mParent->addDependentChild (this); 
    748930 
    749931    mData.allocate(); 
     
    752934    mData->mAction = aAction; 
    753935 
    754     // initialize all filters to any match using null string 
     936    /* initialize all filters to any match using null string */ 
    755937    mData->mVendorId = NULL; 
    756938    mData->mProductId = NULL; 
     
    764946    mInList = false; 
    765947 
    766     // use setters for the attributes below to reuse parsing errors handling 
    767     setReady (true); 
    768     HRESULT rc; 
     948    /* use setters for the attributes below to reuse parsing errors 
     949     * handling */ 
     950 
     951    HRESULT rc = S_OK; 
    769952    do 
    770953    { 
    771954        rc = COMSETTER(VendorId) (aVendorId); 
    772         if (FAILED (rc)) 
    773             break; 
     955        CheckComRCBreakRC (rc); 
    774956        rc = COMSETTER(ProductId) (aProductId); 
    775         if (FAILED (rc)) 
    776             break; 
     957        CheckComRCBreakRC (rc); 
    777958        rc = COMSETTER(Revision) (aRevision); 
    778         if (FAILED (rc)) 
    779             break; 
     959        CheckComRCBreakRC (rc); 
    780960        rc = COMSETTER(Manufacturer) (aManufacturer); 
    781         if (FAILED (rc)) 
    782             break; 
     961        CheckComRCBreakRC (rc); 
    783962        rc = COMSETTER(Product) (aProduct); 
    784         if (FAILED (rc)) 
    785             break; 
     963        CheckComRCBreakRC (rc); 
    786964        rc = COMSETTER(SerialNumber) (aSerialNumber); 
    787         if (FAILED (rc)) 
    788             break; 
     965        CheckComRCBreakRC (rc); 
    789966        rc = COMSETTER(Port) (aPort); 
    790         if (FAILED (rc)) 
    791             break; 
     967        CheckComRCBreakRC (rc); 
    792968    } 
    793969    while (0); 
    794970 
     971    /* Confirm successful initialization when it's the case */ 
    795972    if (SUCCEEDED (rc)) 
    796         mParent->addDependentChild (this); 
    797     else 
    798         setReady (false); 
     973        autoInitSpan.setSucceeded(); 
    799974 
    800975    return rc; 
     
    802977 
    803978/** 
    804  * Initializes the USB device filter object (short version). 
     979 *  Initializes the USB device filter object (short version). 
     980 * 
     981 *  @param aParent  Handle of the parent object. 
    805982 */ 
    806983HRESULT HostUSBDeviceFilter::init (Host *aParent, INPTR BSTR aName) 
    807984{ 
    808     LogFlowMember (("HostUSBDeviceFilter::init(): isReady=%d\n", isReady())); 
     985    LogFlowThisFunc (("aParent=%p\n", aParent)); 
    809986 
    810987    ComAssertRet (aParent && aName && *aName, E_INVALIDARG); 
    811988 
    812     AutoLock alock (this); 
    813     ComAssertRet (!isReady(), E_UNEXPECTED); 
    814  
    815     mParent = aParent; 
     989    /* Enclose the state transition NotReady->InInit->Ready */ 
     990    AutoInitSpan autoInitSpan (this); 
     991    AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 
     992 
     993    unconst (mParent) = aParent; 
     994 
     995    /* register with parent early, since uninit() will unconditionally 
     996     * unregister on failure */ 
     997    mParent->addDependentChild (this); 
    816998 
    817999    mData.allocate(); 
     1000 
    8181001    mData->mName = aName; 
    8191002    mData->mActive = FALSE; 
     
    8221005    mInList = false; 
    8231006 
    824     // initialize all filters using null string (any match) 
     1007    /* initialize all filters to any match using null string */ 
    8251008    mData->mVendorId = NULL; 
    8261009    mData->mProductId = NULL; 
     
    8321015    mData->mRemote = NULL; 
    8331016 
    834     mParent->addDependentChild (this); 
    835  
    836     setReady (true); 
     1017    /* Confirm successful initialization */ 
     1018    autoInitSpan.setSucceeded(); 
     1019 
    8371020    return S_OK; 
    8381021} 
     
    8441027void HostUSBDeviceFilter::uninit() 
    8451028{ 
    846     LogFlowMember (("HostUSBDeviceFilter::uninit()\n")); 
    847  
    848     AutoLock alock (this); 
    849  
    850     LogFlowMember (("HostUSBDeviceFilter::uninit(): isReady=%d\n", isReady())); 
    851  
    852     if (!isReady()) 
     1029    LogFlowThisFunc (("\n")); 
     1030 
     1031    /* Enclose the state transition Ready->InUninit->NotReady */ 
     1032    AutoUninitSpan autoUninitSpan (this); 
     1033    if (autoUninitSpan.uninitDone()) 
    8531034        return; 
    8541035 
     
    8571038    mData.free(); 
    8581039 
    859     setReady (false); 
    860  
    861     alock.leave(); 
    8621040    mParent->removeDependentChild (this); 
    863     alock.enter(); 
    864  
    865     mParent.setNull(); 
     1041 
     1042    unconst (mParent).setNull(); 
    8661043} 
    8671044 
     
    8741051        return E_POINTER; 
    8751052 
    876     AutoLock alock (this); 
    877     CHECK_READY(); 
     1053    AutoCaller autoCaller (this); 
     1054    CheckComRCReturnRC (autoCaller.rc()); 
     1055 
     1056    AutoReaderLock alock (this); 
    8781057 
    8791058    mData->mName.cloneTo (aName); 
     1059 
    8801060    return S_OK; 
    8811061} 
     
    8861066        return E_INVALIDARG; 
    8871067 
    888     AutoLock alock (this); 
    889     CHECK_READY(); 
     1068    AutoCaller autoCaller (this); 
     1069    CheckComRCReturnRC (autoCaller.rc()); 
     1070 
     1071    AutoLock alock (this); 
    8901072 
    8911073    if (mData->mName != aName) 
     
    8931075        mData->mName = aName; 
    8941076 
    895         // notify parent 
    896         alock.unlock(); 
     1077        /* leave the lock before informing callbacks */ 
     1078        alock.unlock(); 
     1079 
    8971080        return mParent->onUSBDeviceFilterChange (this); 
    8981081    } 
     
    9061089        return E_POINTER; 
    9071090 
    908     AutoLock alock (this); 
    909     CHECK_READY(); 
     1091    AutoCaller autoCaller (this); 
     1092    CheckComRCReturnRC (autoCaller.rc()); 
     1093 
     1094    AutoReaderLock alock (this); 
    9101095 
    9111096    *aActive = mData->mActive; 
     1097 
    9121098    return S_OK; 
    9131099} 
     
    9151101STDMETHODIMP HostUSBDeviceFilter::COMSETTER(Active) (BOOL aActive) 
    9161102{ 
    917     AutoLock alock (this); 
    918     CHECK_READY(); 
     1103    AutoCaller autoCaller (this); 
     1104    CheckComRCReturnRC (autoCaller.rc()); 
     1105 
     1106    AutoLock alock (this); 
    9191107 
    9201108    if (mData->mActive != aActive) 
     
    9221110        mData->mActive = aActive; 
    9231111 
    924         // notify parent 
    925         alock.unlock(); 
     1112        /* leave the lock before informing callbacks */ 
     1113        alock.unlock(); 
     1114 
    9261115        return mParent->onUSBDeviceFilterChange (this, TRUE /* aActiveChanged  */); 
    9271116    } 
     
    9351124        return E_POINTER; 
    9361125 
    937     AutoLock alock (this); 
    938     CHECK_READY(); 
     1126    AutoCaller autoCaller (this); 
     1127    CheckComRCReturnRC (autoCaller.rc()); 
     1128 
     1129    AutoReaderLock alock (this); 
    9391130 
    9401131    mData->mVendorId.string().cloneTo (aVendorId); 
     1132 
    9411133    return S_OK; 
    9421134} 
     
    9441136STDMETHODIMP HostUSBDeviceFilter::COMSETTER(VendorId) (INPTR BSTR aVendorId) 
    9451137{ 
    946     AutoLock alock (this); 
    947     CHECK_READY(); 
     1138    AutoCaller autoCaller (this); 
     1139    CheckComRCReturnRC (autoCaller.rc()); 
     1140 
     1141    AutoLock alock (this); 
    9481142 
    9491143    if (mData->mVendorId.string() != aVendorId) 
     
    9651159        mData->mVendorId = flt; 
    9661160 
    967         // notify parent 
    968         alock.unlock(); 
     1161        /* leave the lock before informing callbacks */ 
     1162        alock.unlock(); 
     1163 
    9691164        return mParent->onUSBDeviceFilterChange (this); 
    9701165    } 
     
    9781173        return E_POINTER; 
    9791174 
    980     AutoLock alock (this); 
    981     CHECK_READY(); 
     1175    AutoCaller autoCaller (this); 
     1176    CheckComRCReturnRC (autoCaller.rc()); 
     1177 
     1178    AutoReaderLock alock (this); 
    9821179 
    9831180    mData->mProductId.string().cloneTo (aProductId); 
     1181 
    9841182    return S_OK; 
    9851183} 
     
    9871185STDMETHODIMP HostUSBDeviceFilter::COMSETTER(ProductId) (INPTR BSTR aProductId) 
    9881186{ 
    989     AutoLock alock (this); 
    990     CHECK_READY(); 
     1187    AutoCaller autoCaller (this); 
     1188    CheckComRCReturnRC (autoCaller.rc()); 
     1189 
     1190    AutoLock alock (this); 
    9911191 
    9921192    if (mData->mProductId.string() != aProductId) 
     
    10081208        mData->mProductId = flt; 
    10091209 
    1010         // notify parent 
    1011         alock.unlock(); 
     1210        /* leave the lock before informing callbacks */ 
     1211        alock.unlock(); 
     1212 
    10121213        return mParent->onUSBDeviceFilterChange (this); 
    10131214