VirtualBox

Changeset 4040 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Aug 6, 2007 12:40:31 PM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
23475
Message:

Main: Converted SharedFolder class to the new locking scheme.

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

Legend:

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

    r3668 r4040  
    3434/////////////////////////////////////////////////////////////////////////////
    3535
     36SharedFolder::SharedFolder()
     37    : mParent (NULL)
     38{
     39}
     40
     41SharedFolder::~SharedFolder()
     42{
     43}
     44
    3645HRESULT SharedFolder::FinalConstruct()
    3746{
     
    5968                            const BSTR aName, const BSTR aHostPath)
    6069{
    61     AutoLock alock (this);
    62     ComAssertRet (!isReady(), E_UNEXPECTED);
    63 
    64     mMachine = aMachine;
    65     return protectedInit (aMachine, aName, aHostPath);
     70    /* Enclose the state transition NotReady->InInit->Ready */
     71    AutoInitSpan autoInitSpan (this);
     72    AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED);
     73
     74    unconst (mMachine) = aMachine;
     75
     76    HRESULT rc = protectedInit (aMachine, aName, aHostPath);
     77
     78    /* Confirm a successful initialization when it's the case */
     79    if (SUCCEEDED (rc))
     80        autoInitSpan.setSucceeded();
     81
     82    return rc;
    6683}
    6784
     
    8097    ComAssertRet (aThat, E_INVALIDARG);
    8198
    82     AutoLock alock (this);
    83     ComAssertRet (!isReady(), E_UNEXPECTED);
    84 
    85     mMachine = aMachine;
    86     return protectedInit (aMachine, aThat->mName, aThat->mHostPath);
     99    /* Enclose the state transition NotReady->InInit->Ready */
     100    AutoInitSpan autoInitSpan (this);
     101    AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED);
     102
     103    unconst (mMachine) = aMachine;
     104
     105    HRESULT rc = protectedInit (aMachine, aThat->mData.mName,
     106                                aThat->mData.mHostPath);
     107
     108    /* Confirm a successful initialization when it's the case */
     109    if (SUCCEEDED (rc))
     110        autoInitSpan.setSucceeded();
     111
     112    return rc;
    87113}
    88114
     
    99125                            const BSTR aName, const BSTR aHostPath)
    100126{
    101     AutoLock alock (this);
    102     ComAssertRet (!isReady(), E_UNEXPECTED);
    103 
    104     mConsole = aConsole;
    105     return protectedInit (aConsole, aName, aHostPath);
     127    /* Enclose the state transition NotReady->InInit->Ready */
     128    AutoInitSpan autoInitSpan (this);
     129    AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED);
     130
     131    unconst (mConsole) = aConsole;
     132
     133    HRESULT rc = protectedInit (aConsole, aName, aHostPath);
     134
     135    /* Confirm a successful initialization when it's the case */
     136    if (SUCCEEDED (rc))
     137        autoInitSpan.setSucceeded();
     138
     139    return rc;
    106140}
    107141
     
    118152                            const BSTR aName, const BSTR aHostPath)
    119153{
    120     AutoLock alock (this);
    121     ComAssertRet (!isReady(), E_UNEXPECTED);
    122 
    123     mVirtualBox = aVirtualBox;
    124     return protectedInit (aVirtualBox, aName, aHostPath);
     154    /* Enclose the state transition NotReady->InInit->Ready */
     155    AutoInitSpan autoInitSpan (this);
     156    AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED);
     157
     158    unconst (mVirtualBox) = aVirtualBox;
     159
     160    HRESULT rc = protectedInit (aVirtualBox, aName, aHostPath);
     161
     162    /* Confirm a successful initialization when it's the case */
     163    if (SUCCEEDED (rc))
     164        autoInitSpan.setSucceeded();
     165
     166    return rc;
    125167}
    126168
     
    131173 *      Must be called from under the object's lock!
    132174 */
    133 HRESULT SharedFolder::protectedInit (VirtualBoxBaseWithChildren *aParent,
     175HRESULT SharedFolder::protectedInit (VirtualBoxBaseWithChildrenNEXT *aParent,
    134176                                     const BSTR aName, const BSTR aHostPath)
    135177{
     
    171213            tr ("Shared folder path '%s' is not absolute"), hostPath.raw());
    172214
    173     mParent = aParent;
    174     unconst (mName) = aName;
    175     unconst (mHostPath) = hostPath;
    176 
     215    unconst (mParent) = aParent;
     216
     217    /* register with parent */
    177218    mParent->addDependentChild (this);
    178219
    179     setReady (true);
     220    unconst (mData.mName) = aName;
     221    unconst (mData.mHostPath) = hostPath;
     222
    180223    return S_OK;
    181224}
     
    187230void SharedFolder::uninit()
    188231{
    189     LogFlowMember (("SharedFolder::uninit()\n"));
    190 
    191     AutoLock alock (this);
    192 
    193     LogFlowMember (("SharedFolder::uninit(): isReady=%d\n", isReady()));
    194     if (!isReady())
     232    LogFlowThisFunc (("\n"));
     233
     234    /* Enclose the state transition Ready->InUninit->NotReady */
     235    AutoUninitSpan autoUninitSpan (this);
     236    if (autoUninitSpan.uninitDone())
    195237        return;
    196238
    197     setReady (false);
    198 
    199     alock.leave();
    200     mParent->removeDependentChild (this);
     239    if (mParent)
     240        mParent->removeDependentChild (this);
     241
     242    unconst (mParent) = NULL;
     243
     244    unconst (mMachine).setNull();
     245    unconst (mConsole).setNull();
     246    unconst (mVirtualBox).setNull();
    201247}
    202248
     
    209255        return E_POINTER;
    210256
    211     AutoLock alock (this);
    212     CHECK_READY();
    213 
    214     mName.cloneTo (aName);
     257    AutoCaller autoCaller (this);
     258    CheckComRCReturnRC (autoCaller.rc());
     259
     260    /* mName is constant during life time, no need to lock */
     261    mData.mName.cloneTo (aName);
     262
    215263    return S_OK;
    216264}
     
    221269        return E_POINTER;
    222270
    223     AutoLock alock (this);
    224     CHECK_READY();
    225 
    226     mHostPath.cloneTo (aHostPath);
     271    AutoCaller autoCaller (this);
     272    CheckComRCReturnRC (autoCaller.rc());
     273
     274    /* mHostPath is constant during life time, no need to lock */
     275    mData.mHostPath.cloneTo (aHostPath);
     276
    227277    return S_OK;
    228278}
     
    233283        return E_POINTER;
    234284
    235     AutoLock alock (this);
    236     CHECK_READY();
    237 
    238     // check whether the host path exists
    239     Utf8Str hostPath = Utf8Str (mHostPath);
     285    AutoCaller autoCaller (this);
     286    CheckComRCReturnRC (autoCaller.rc());
     287
     288    /* mName and mHostPath are constant during life time, no need to lock */
     289
     290    /* check whether the host path exists */
     291    Utf8Str hostPath = Utf8Str (mData.mHostPath);
    240292    char hostPathFull [RTPATH_MAX];
    241     int vrc = RTPathExists(hostPath) ? RTPathReal (hostPath, hostPathFull, sizeof (hostPathFull))
     293    int vrc = RTPathExists(hostPath) ? RTPathReal (hostPath, hostPathFull,
     294                                                   sizeof (hostPathFull))
    242295                                     : VERR_PATH_NOT_FOUND;
    243296    if (VBOX_SUCCESS (vrc))
     
    252305            tr ("Invalid shared folder path: '%s' (%Vrc)"), hostPath.raw(), vrc);
    253306
    254     Log (("SharedFolder::COMGETTER(Accessible): WARNING: '%s' "
    255           "is not accessible (%Vrc)\n", hostPath.raw(), vrc));
     307    LogWarningThisFunc (("'%s' is not accessible (%Vrc)\n", hostPath.raw(), vrc));
    256308
    257309    *aAccessible = FALSE;
  • trunk/src/VBox/Main/include/SharedFolderImpl.h

    r2981 r4040  
    3232
    3333class ATL_NO_VTABLE SharedFolder :
     34    public VirtualBoxBaseNEXT,
    3435    public VirtualBoxSupportErrorInfoImpl <SharedFolder, ISharedFolder>,
    3536    public VirtualBoxSupportTranslation <SharedFolder>,
    36     public VirtualBoxBase,
    3737    public ISharedFolder
    3838{
    3939public:
    4040
    41     // to satisfy the ComObjPtr template (we have const members)
    42     SharedFolder() {}
     41    struct Data
     42    {
     43        Data() {}
     44
     45        const Bstr mName;
     46        const Bstr mHostPath;
     47    };
     48
     49    VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (SharedFolder)
    4350
    4451    DECLARE_NOT_AGGREGATABLE(SharedFolder)
     
    5259
    5360    NS_DECL_ISUPPORTS
     61
     62    DECLARE_EMPTY_CTOR_DTOR (SharedFolder)
    5463
    5564    HRESULT FinalConstruct();
     
    6978
    7079    // public methods for internal purposes only
     80    // (ensure there is a caller and a read lock before calling them!)
    7181
    72     const Bstr &name() const { return mName; }
    73     const Bstr &hostPath() const { return mHostPath; }
     82    // public methods that don't need a lock (because access constant data)
     83    // (ensure there is a caller added before calling them!)
     84
     85    const Bstr &name() const { return mData.mName; }
     86    const Bstr &hostPath() const { return mData.mHostPath; }
    7487
    7588    // for VirtualBoxSupportErrorInfoImpl
     
    7891protected:
    7992
    80     HRESULT protectedInit (VirtualBoxBaseWithChildren *aParent,
     93    HRESULT protectedInit (VirtualBoxBaseWithChildrenNEXT *aParent,
    8194                           const BSTR aName, const BSTR aHostPath);
    8295
    8396private:
    8497
    85     VirtualBoxBaseWithChildren *mParent;
     98    VirtualBoxBaseWithChildrenNEXT *const mParent;
    8699
    87100    /* weak parents (only one of them is not null) */
    88     ComObjPtr <Machine, ComWeakRef> mMachine;
    89     ComObjPtr <Console, ComWeakRef> mConsole;
    90     ComObjPtr <VirtualBox, ComWeakRef> mVirtualBox;
     101    const ComObjPtr <Machine, ComWeakRef> mMachine;
     102    const ComObjPtr <Console, ComWeakRef> mConsole;
     103    const ComObjPtr <VirtualBox, ComWeakRef> mVirtualBox;
    91104
    92     const Bstr mName;
    93     const Bstr mHostPath;
     105    Data mData;
    94106};
    95107
     
    117129        if (!found)
    118130            return setError (E_INVALIDARG, SharedFolderCollection::tr (
    119                 "Shared folder named '%ls' could not be found"), aName);
     131                "Could not find the shared folder '%ls'"), aName);
    120132
    121133        return found.queryInterfaceTo (aSharedFolder);
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