summaryrefslogtreecommitdiff
path: root/cppuhelper
diff options
context:
space:
mode:
authorDaniel Boelzle <dbo@openoffice.org>2002-07-10 14:20:59 +0000
committerDaniel Boelzle <dbo@openoffice.org>2002-07-10 14:20:59 +0000
commitc4229013eeeb691c310afe89ecfcc73d4dd22bce (patch)
treebd95b18c4fee3845d713a1e1aef640cefeebdeca /cppuhelper
parent05ba37abcf1ff8f82d4d4c1837f8675c9ca9a0b9 (diff)
#101182# fixing needed guards for listener management
Diffstat (limited to 'cppuhelper')
-rw-r--r--cppuhelper/source/component.cxx41
-rw-r--r--cppuhelper/source/implbase.cxx32
2 files changed, 53 insertions, 20 deletions
diff --git a/cppuhelper/source/component.cxx b/cppuhelper/source/component.cxx
index db4936136485..03d0a8449c6a 100644
--- a/cppuhelper/source/component.cxx
+++ b/cppuhelper/source/component.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: component.cxx,v $
*
- * $Revision: 1.7 $
+ * $Revision: 1.8 $
*
- * last change: $Author: hr $ $Date: 2001-09-26 15:09:45 $
+ * last change: $Author: dbo $ $Date: 2002-07-10 15:20:59 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -59,6 +59,9 @@
*
************************************************************************/
+#ifndef _RTL_STRING_HXX_
+#include <rtl/string.hxx>
+#endif
#ifndef _OSL_DIAGNOSE_H_
#include <osl/diagnose.h>
#endif
@@ -73,6 +76,7 @@
#endif
using namespace osl;
+using namespace rtl;
using namespace com::sun::star;
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
@@ -130,9 +134,13 @@ void OComponentHelper::release() throw()
{
dispose();
}
- catch(::com::sun::star::uno::Exception&)
+ catch (::com::sun::star::uno::RuntimeException & exc)
{
// release should not throw exceptions
+#ifdef _DEBUG
+ OString msg( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) );
+ OSL_ENSURE( 0, msg.getStr() );
+#endif
}
// only the alive ref holds the object
@@ -208,18 +216,37 @@ void OComponentHelper::dispose()
// notify subclasses to do their dispose
disposing();
}
- catch(::com::sun::star::uno::Exception& e)
+ catch(::com::sun::star::uno::RuntimeException&)
{
// catch exception and throw again but signal that
// the object was disposed. Dispose should be called
// only once.
+ MutexGuard aGuard( rBHelper.rMutex );
+ rBHelper.bDisposed = sal_True;
+ rBHelper.bInDispose = sal_False;
+ throw;
+ }
+ catch (::com::sun::star::uno::Exception & exc)
+ {
+ MutexGuard aGuard( rBHelper.rMutex );
+ rBHelper.bDisposed = sal_True;
+ rBHelper.bInDispose = sal_False;
+ throw RuntimeException(
+ OUString( RTL_CONSTASCII_USTRINGPARAM("unexpected UNO exception caught: ") ) +
+ exc.Message, Reference< XInterface >() );
+ }
+ catch (...)
+ {
+ MutexGuard aGuard( rBHelper.rMutex );
rBHelper.bDisposed = sal_True;
rBHelper.bInDispose = sal_False;
- throw e;
+ throw RuntimeException(
+ OUString( RTL_CONSTASCII_USTRINGPARAM("unexpected non-UNO exception caught: ") ),
+ Reference< XInterface >() );
}
// the values bDispose and bInDisposing must set in this order.
- // No multithread call overcome the "!rBHelper.bDisposed && !rBHelper.bInDispose" guard.
+ MutexGuard aGuard( rBHelper.rMutex );
rBHelper.bDisposed = sal_True;
rBHelper.bInDispose = sal_False;
}
@@ -236,8 +263,10 @@ void OComponentHelper::addEventListener(
const Reference<XEventListener > & rxListener )
throw(::com::sun::star::uno::RuntimeException)
{
+ ClearableMutexGuard aGuard( rBHelper.rMutex );
if (rBHelper.bDisposed || rBHelper.bInDispose)
{
+ aGuard.clear();
Reference< XInterface > x( (XComponent *)this, UNO_QUERY );
rxListener->disposing( EventObject( x ) );
}
diff --git a/cppuhelper/source/implbase.cxx b/cppuhelper/source/implbase.cxx
index 30d270369ede..5d5d64357ad9 100644
--- a/cppuhelper/source/implbase.cxx
+++ b/cppuhelper/source/implbase.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: implbase.cxx,v $
*
- * $Revision: 1.7 $
+ * $Revision: 1.8 $
*
- * last change: $Author: dbo $ $Date: 2002-06-14 13:20:19 $
+ * last change: $Author: dbo $ $Date: 2002-07-10 15:20:59 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -289,16 +289,12 @@ void WeakComponentImplHelperBase::release()
{
dispose();
}
-#ifdef _DEBUG
- catch (Exception & exc)
+ catch (RuntimeException & exc) // don't break throw ()
{
+#ifdef _DEBUG
OString msg( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) );
OSL_ENSURE( 0, msg.getStr() );
- }
#endif
- catch (...)
- {
- OSL_ENSURE( 0, "### unexpected non-UNO exception caught!" );
}
}
OWeakObject::release();
@@ -317,17 +313,20 @@ void WeakComponentImplHelperBase::dispose()
lang::EventObject aEvt( static_cast< OWeakObject * >( this ) );
rBHelper.aLC.disposeAndClear( aEvt );
disposing();
+ MutexGuard aGuard( rBHelper.rMutex );
rBHelper.bDisposed = sal_True;
rBHelper.bInDispose = sal_False;
}
catch (RuntimeException &)
{
+ MutexGuard aGuard( rBHelper.rMutex );
rBHelper.bDisposed = sal_True;
rBHelper.bInDispose = sal_False;
throw;
}
catch (Exception & exc)
{
+ MutexGuard aGuard( rBHelper.rMutex );
rBHelper.bDisposed = sal_True;
rBHelper.bInDispose = sal_False;
#ifdef _DEBUG
@@ -340,6 +339,7 @@ void WeakComponentImplHelperBase::dispose()
}
catch (...)
{
+ MutexGuard aGuard( rBHelper.rMutex );
rBHelper.bDisposed = sal_True;
rBHelper.bInDispose = sal_False;
OSL_ENSURE( 0, "### unexpected non-UNO exception caught!" );
@@ -354,8 +354,10 @@ void WeakComponentImplHelperBase::addEventListener(
Reference< lang::XEventListener > const & xListener )
throw (RuntimeException)
{
+ ClearableMutexGuard aGuard( rBHelper.rMutex );
if (rBHelper.bDisposed || rBHelper.bInDispose)
{
+ aGuard.clear();
lang::EventObject aEvt( static_cast< OWeakObject * >( this ) );
xListener->disposing( aEvt );
}
@@ -422,16 +424,12 @@ void WeakAggComponentImplHelperBase::release()
{
dispose();
}
-#ifdef _DEBUG
- catch (Exception & exc)
+ catch (RuntimeException & exc) // don't break throw ()
{
+#ifdef _DEBUG
OString msg( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) );
OSL_ENSURE( 0, msg.getStr() );
- }
#endif
- catch (...)
- {
- OSL_ENSURE( 0, "### unexpected exception caught!" );
}
}
OWeakAggObject::release();
@@ -450,17 +448,20 @@ void WeakAggComponentImplHelperBase::dispose()
lang::EventObject aEvt( static_cast< OWeakObject * >( this ) );
rBHelper.aLC.disposeAndClear( aEvt );
disposing();
+ MutexGuard aGuard( rBHelper.rMutex );
rBHelper.bDisposed = sal_True;
rBHelper.bInDispose = sal_False;
}
catch (RuntimeException &)
{
+ MutexGuard aGuard( rBHelper.rMutex );
rBHelper.bDisposed = sal_True;
rBHelper.bInDispose = sal_False;
throw;
}
catch (Exception & exc)
{
+ MutexGuard aGuard( rBHelper.rMutex );
rBHelper.bDisposed = sal_True;
rBHelper.bInDispose = sal_False;
#ifdef _DEBUG
@@ -473,6 +474,7 @@ void WeakAggComponentImplHelperBase::dispose()
}
catch (...)
{
+ MutexGuard aGuard( rBHelper.rMutex );
rBHelper.bDisposed = sal_True;
rBHelper.bInDispose = sal_False;
OSL_ENSURE( 0, "### unexpected non-UNO exception caught!" );
@@ -487,8 +489,10 @@ void WeakAggComponentImplHelperBase::addEventListener(
Reference< lang::XEventListener > const & xListener )
throw (RuntimeException)
{
+ ClearableMutexGuard aGuard( rBHelper.rMutex );
if (rBHelper.bDisposed || rBHelper.bInDispose)
{
+ aGuard.clear();
lang::EventObject aEvt( static_cast< OWeakObject * >( this ) );
xListener->disposing( aEvt );
}