User: obo Date: 05/12/21 05:34:45 Modified: /dba/dbaccess/source/core/dataaccess/ ModelImpl.hxx
Log: INTEGRATION: CWS dba202a (1.8.32); FILE MERGED 2005/11/28 10:50:52 fs 1.8.32.2: #126702# improve the previous fix: don't crash if components are destroyed in "wrong" order keep mutex alive as long as at least one of DataSource/DatabaseDocument/ModelImpl is alive 2005/11/25 13:37:21 fs 1.8.32.1: #126702# DatabaseDocument and DataSource share a common mutex instances now (held by ModelImpl) / DatabaseDocument::clearConnections more tolerant against re-entrance File Changes: Directory: /dba/dbaccess/source/core/dataaccess/ ================================================ File [changed]: ModelImpl.hxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/ModelImpl.hxx?r1=1.8&r2=1.9 Delta lines: +108 -5 --------------------- --- ModelImpl.hxx 8 Sep 2005 10:17:45 -0000 1.8 +++ ModelImpl.hxx 21 Dec 2005 13:34:42 -0000 1.9 @@ -170,11 +170,31 @@ class OSharedConnectionManager; //============================================================ +//= SharedMutex +//============================================================ +class SharedMutex +{ +private: + oslInterlockedCount m_refCount; + ::osl::Mutex m_aMutex; + +public: + SharedMutex(); + + void SAL_CALL acquire(); + void SAL_CALL release(); + + inline ::osl::Mutex& getMutex() { return m_aMutex; } + +private: + ~SharedMutex(); +}; + +//============================================================ //= ODatabaseModelImpl //============================================================ DECLARE_STL_USTRINGACCESS_MAP(::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >,TStorages); - class ODatabaseContext; class DocumentStorageAccess; class OSharedConnectionManager; @@ -185,6 +205,7 @@ ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDataSource> m_xDataSource; DocumentStorageAccess* m_pStorageAccess; + ::rtl::Reference< SharedMutex > m_xMutex; public: @@ -404,6 +425,7 @@ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > createNewModel_deliverOwnership(); struct ResetModelAccess { friend class ODatabaseDocument; private: ResetModelAccess() { } }; + /** resets the model to NULL Only to be called when the model is being disposed @@ -416,7 +438,7 @@ ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentSubStorageSupplier > getDocumentSubStorageSupplier(); -// void clear(); + inline ::rtl::Reference< SharedMutex > getSharedMutex() const { return m_xMutex; } /** @see osl_incrementInterlockedCount. */ @@ -427,6 +449,87 @@ virtual oslInterlockedCount SAL_CALL release(); +}; + +/** a small base class for UNO components whose functionality depends on a ODatabaseModelImpl +*/ +class ModelDependentComponent +{ +protected: + ::rtl::Reference< ODatabaseModelImpl > m_pImpl; + ::rtl::Reference< SharedMutex > m_xMutex; + +protected: + ModelDependentComponent( const ::rtl::Reference< ODatabaseModelImpl >& _model ); + + /** returns the component itself + */ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getThis() = 0; + + inline ::osl::Mutex& getMutex() + { + return m_xMutex->getMutex(); + } + +public: + struct GuardAccess { friend class ModelMethodGuard; private: GuardAccess() { } }; + + /** returns the mutex used for thread safety + + @throws ::com::sun::star::lang::DisposedException + if m_pImpl is <NULL/>. Usually, you will set this member in your derived + component's <code>dispose</code> method to <NULL/>. + */ + inline ::osl::Mutex& getMutex( GuardAccess ) + { + return getMutex(); + } + inline ::rtl::Reference< ODatabaseModelImpl > getImpl( GuardAccess ) + { + return m_pImpl; + } + + void checkDisposed() + { + if ( !m_pImpl.is() ) + throw ::com::sun::star::lang::DisposedException( ::rtl::OUString::createFromAscii( "Component is already disposed." ), getThis() ); + } +}; + +/** a guard for public methods of objects dependent on a ODatabaseModelImpl instance + + Just put this guard onto the stack at the beginning of your method. Don't bother yourself + with a MutexGuard, checks for being disposed, and the like. +*/ +class ModelMethodGuard :public ::osl::ResettableMutexGuard +{ +private: + typedef ::osl::ResettableMutexGuard BaseMutexGuard; + +public: + /** constructs the guard + + @param _component + the component whose functionality depends on a ODatabaseModelImpl instance + + @throws ::com::sun::star::lang::DisposedException + If the given component is already disposed + */ + ModelMethodGuard( ModelDependentComponent& _component ) + :BaseMutexGuard( _component.getMutex( ModelDependentComponent::GuardAccess() ) ) + { + _component.checkDisposed(); + } + + inline void clear() + { + BaseMutexGuard::clear(); + } + + inline void reset() + { + BaseMutexGuard::reset(); + } }; //........................................................................ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
