Tag: cws_src680_dba202a
User: fs      
Date: 05/11/28 02:50:57

Modified:
 /dba/dbaccess/source/core/dataaccess/
  ModelImpl.cxx, ModelImpl.hxx, databasedocument.cxx, databasedocument.hxx,
  datasource.cxx, datasource.hxx

Log:
 #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

File Changes:

Directory: /dba/dbaccess/source/core/dataaccess/
================================================

File [changed]: ModelImpl.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/ModelImpl.cxx?r1=1.9.12.1&r2=1.9.12.2
Delta lines:  +32 -2
--------------------
--- ModelImpl.cxx       25 Nov 2005 13:37:20 -0000      1.9.12.1
+++ ModelImpl.cxx       28 Nov 2005 10:50:51 -0000      1.9.12.2
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: ModelImpl.cxx,v $
  *
- *  $Revision: 1.9.12.1 $
+ *  $Revision: 1.9.12.2 $
  *
- *  last change: $Author: fs $ $Date: 2005/11/25 13:37:20 $
+ *  last change: $Author: fs $ $Date: 2005/11/28 10:50:51 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -179,6 +179,33 @@
 {
 //........................................................................
 
+//========================================================================
+//= DocumentStorageAccess
+//========================================================================
+//------------------------------------------------------------------------
+SharedMutex::SharedMutex()
+    :m_refCount( 0 )
+{
+}
+
+//------------------------------------------------------------------------
+SharedMutex::~SharedMutex()
+{
+}
+
+//------------------------------------------------------------------------
+void SAL_CALL SharedMutex::acquire()
+{
+    osl_incrementInterlockedCount( &m_refCount );
+}
+
+//------------------------------------------------------------------------
+void SAL_CALL SharedMutex::release()
+{
+    if ( 0 == osl_decrementInterlockedCount( &m_refCount ) )
+        delete this;
+}
+
 //============================================================
 //= DocumentStorageAccess
 //============================================================
@@ -374,6 +401,7 @@
                        ,m_nLoginTimeout(0)
                        ,m_refCount(0)
             ,m_pStorageAccess( NULL )
+            ,m_xMutex( new SharedMutex )
 {
        // some kind of default
        DBG_CTOR(ODatabaseModelImpl,NULL);
@@ -404,6 +432,7 @@
                        ,m_nLoginTimeout(0)
                        ,m_refCount(0)
             ,m_pStorageAccess( NULL )
+            ,m_xMutex( new SharedMutex )
 {
        DBG_CTOR(ODatabaseModelImpl,NULL);
        // adjust our readonly flag
@@ -876,6 +905,7 @@
 // 
-----------------------------------------------------------------------------
 ModelDependentComponent::ModelDependentComponent( const ::rtl::Reference< 
ODatabaseModelImpl >& _model )
     :m_pImpl( _model )
+    ,m_xMutex( _model->getSharedMutex() )
 {
 }
 

File [changed]: ModelImpl.hxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/ModelImpl.hxx?r1=1.8.32.1&r2=1.8.32.2
Delta lines:  +46 -24
---------------------
--- ModelImpl.hxx       25 Nov 2005 13:37:21 -0000      1.8.32.1
+++ ModelImpl.hxx       28 Nov 2005 10:50:52 -0000      1.8.32.2
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: ModelImpl.hxx,v $
  *
- *  $Revision: 1.8.32.1 $
+ *  $Revision: 1.8.32.2 $
  *
- *  last change: $Author: fs $ $Date: 2005/11/25 13:37:21 $
+ *  last change: $Author: fs $ $Date: 2005/11/28 10:50:52 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -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,7 +205,7 @@
     ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDataSource> 
                        m_xDataSource;
 
     DocumentStorageAccess*                                                     
             m_pStorageAccess;
-    ::osl::Mutex                                                               
             m_aMutex;
+    ::rtl::Reference< SharedMutex >                                            
 m_xMutex;
 
 public:
 
@@ -418,7 +438,7 @@
     ::com::sun::star::uno::Reference< 
::com::sun::star::document::XDocumentSubStorageSupplier >
             getDocumentSubStorageSupplier();
 
-    inline ::osl::Mutex&   getMutex() { return m_aMutex; }
+    inline ::rtl::Reference< SharedMutex > getSharedMutex() const { return 
m_xMutex; }
 
        /** @see osl_incrementInterlockedCount.
         */
@@ -437,6 +457,7 @@
 {
 protected:
     ::rtl::Reference< ODatabaseModelImpl >  m_pImpl;
+    ::rtl::Reference< SharedMutex >         m_xMutex;
 
 protected:
     ModelDependentComponent( const ::rtl::Reference< ODatabaseModelImpl >& 
_model );
@@ -445,27 +466,34 @@
     */
     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
 
-        Since our mutex is implemented in the ODatabaseModelImpl, the method 
will throw
-        a ::com::sun::star::lang::DisposedException
-
         @throws ::com::sun::star::lang::DisposedException
-            if the model is already disposed
+            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 )
     {
-        if ( !m_pImpl.is() )
-            throw ::com::sun::star::lang::DisposedException( 
::rtl::OUString(), getThis() );
-        return m_pImpl->getMutex();
+        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
@@ -473,17 +501,11 @@
     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 ::rtl::Reference< ODatabaseModelImpl >
-                        ,public ::osl::ResettableMutexGuard
-                            // order matters! Need to ensure that m_aImplGuard 
is destroyed *before*
-                            // m_pKeepModelAlive, since the latter will also 
destroy the mutex which
-                            // m_aImplGuard refers to.
+class ModelMethodGuard  :public ::osl::ResettableMutexGuard
 {
 private:
-    typedef ::rtl::Reference< ODatabaseModelImpl >  BaseModelGuard;
     typedef ::osl::ResettableMutexGuard             BaseMutexGuard;
 
-
 public:
     /** constructs the guard
 
@@ -494,9 +516,9 @@
             If the given component is already disposed
     */
     ModelMethodGuard( ModelDependentComponent& _component )
-        :BaseModelGuard( _component.getImpl( 
ModelDependentComponent::GuardAccess() ) )
-        ,BaseMutexGuard( _component.getMutex( 
ModelDependentComponent::GuardAccess() ) )
+        :BaseMutexGuard( _component.getMutex( 
ModelDependentComponent::GuardAccess() ) )
     {
+        _component.checkDisposed();
     }
 
     inline void clear()

File [changed]: databasedocument.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/databasedocument.cxx?r1=1.22.26.1&r2=1.22.26.2
Delta lines:  +8 -8
-------------------
--- databasedocument.cxx        25 Nov 2005 13:37:21 -0000      1.22.26.1
+++ databasedocument.cxx        28 Nov 2005 10:50:52 -0000      1.22.26.2
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: databasedocument.cxx,v $
  *
- *  $Revision: 1.22.26.1 $
+ *  $Revision: 1.22.26.2 $
  *
- *  last change: $Author: fs $ $Date: 2005/11/25 13:37:21 $
+ *  last change: $Author: fs $ $Date: 2005/11/28 10:50:52 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -164,11 +164,11 @@
 }
 //--------------------------------------------------------------------------
 ODatabaseDocument::ODatabaseDocument(const 
::rtl::Reference<ODatabaseModelImpl>& _pImpl        )
-            :ODatabaseDocument_OfficeDocument( _pImpl->getMutex() )
-            ,ModelDependentComponent(_pImpl)
-            ,m_aModifyListeners( _pImpl->getMutex() )
-                       ,m_aCloseListener( _pImpl->getMutex() )
-            ,m_aDocEventListeners( _pImpl->getMutex() )
+            :ModelDependentComponent( _pImpl )
+            ,ODatabaseDocument_OfficeDocument( getMutex() )
+            ,m_aModifyListeners( getMutex() )
+                       ,m_aCloseListener( getMutex() )
+            ,m_aDocEventListeners( getMutex() )
 {
        DBG_CTOR(ODatabaseDocument,NULL);
 
@@ -1057,7 +1057,7 @@
     Reference< XModel > xHoldAlive( this );
     {
         {
-            ::osl::ClearableMutexGuard aGuard( m_pImpl->getMutex() );
+            ::osl::ClearableMutexGuard aGuard( getMutex() );
                impl_notifyEvent( "OnUnload", aGuard );
         }
 

File [changed]: databasedocument.hxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/databasedocument.hxx?r1=1.6.26.1&r2=1.6.26.2
Delta lines:  +4 -4
-------------------
--- databasedocument.hxx        25 Nov 2005 13:37:22 -0000      1.6.26.1
+++ databasedocument.hxx        28 Nov 2005 10:50:53 -0000      1.6.26.2
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: databasedocument.hxx,v $
  *
- *  $Revision: 1.6.26.1 $
+ *  $Revision: 1.6.26.2 $
  *
- *  last change: $Author: fs $ $Date: 2005/11/25 13:37:22 $
+ *  last change: $Author: fs $ $Date: 2005/11/28 10:50:53 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -108,8 +108,8 @@
                             //,        
::com::sun::star::document::XStorageBasedDocument
                                                        >       
ODatabaseDocument_OfficeDocument; 
 
-class ODatabaseDocument        :public ODatabaseDocument_OfficeDocument
-                        ,public ModelDependentComponent
+class ODatabaseDocument        :public ModelDependentComponent             // 
ModelDependentComponent must be first!
+                        ,public ODatabaseDocument_OfficeDocument
 {
     ::com::sun::star::uno::Reference< 
::com::sun::star::ui::XUIConfigurationManager>   m_xUIConfigurationManager;
     ::com::sun::star::uno::Reference< 
::com::sun::star::document::XEventListener >      m_xDocEventBroadcaster;

File [changed]: datasource.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/datasource.cxx?r1=1.64.12.1&r2=1.64.12.2
Delta lines:  +6 -6
-------------------
--- datasource.cxx      25 Nov 2005 13:37:22 -0000      1.64.12.1
+++ datasource.cxx      28 Nov 2005 10:50:53 -0000      1.64.12.2
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: datasource.cxx,v $
  *
- *  $Revision: 1.64.12.1 $
+ *  $Revision: 1.64.12.2 $
  *
- *  last change: $Author: fs $ $Date: 2005/11/25 13:37:22 $
+ *  last change: $Author: fs $ $Date: 2005/11/28 10:50:53 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -609,10 +609,10 @@
 //--------------------------------------------------------------------------
 ODatabaseSource::ODatabaseSource(const ::rtl::Reference<ODatabaseModelImpl>& 
_pImpl)
                        :ModelDependentComponent( _pImpl )
-            ,OSubComponent( _pImpl->getMutex(), Reference< XInterface >() )
+            ,OSubComponent( getMutex(), Reference< XInterface >() )
                        ,OPropertySetHelper(OComponentHelper::rBHelper)
-            ,m_aBookmarks( *this, _pImpl->getMutex() )
-            ,m_aFlushListeners( _pImpl->getMutex() )
+            ,m_aBookmarks( *this, getMutex() )
+            ,m_aFlushListeners( getMutex() )
 {
        // some kind of default
        DBG_CTOR(ODatabaseSource,NULL);
@@ -1127,7 +1127,7 @@
                // handle the request
                try
                {
-                       MutexRelease aRelease( m_pImpl->getMutex() );
+                       MutexRelease aRelease( getMutex() );
                                // release the mutex when calling the handler, 
it may need to lock the SolarMutex
                        _rxHandler->handle(xRequest);
                }

File [changed]: datasource.hxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/datasource.hxx?r1=1.33.12.1&r2=1.33.12.2
Delta lines:  +3 -3
-------------------
--- datasource.hxx      25 Nov 2005 13:37:23 -0000      1.33.12.1
+++ datasource.hxx      28 Nov 2005 10:50:54 -0000      1.33.12.2
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: datasource.hxx,v $
  *
- *  $Revision: 1.33.12.1 $
+ *  $Revision: 1.33.12.2 $
  *
- *  last change: $Author: fs $ $Date: 2005/11/25 13:37:23 $
+ *  last change: $Author: fs $ $Date: 2005/11/28 10:50:54 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -177,7 +177,7 @@
                                 >   ODatabaseSource_Base;
 
 
-class ODatabaseSource   :public ModelDependentComponent
+class ODatabaseSource   :public ModelDependentComponent // must be first
                         ,public OSubComponent
                                            ,public ::cppu::OPropertySetHelper
                                            ,public 
::comphelper::OPropertyArrayUsageHelper < ODatabaseSource >




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to