From a12db8e9e1960f3f209f1b95547041681566d636 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 30 Jun 2015 14:10:17 +0200 Subject: tdf#92440: Reduce code areas covered by mutex Change-Id: Iec79e088e67e1cddeb8242d069fae911b305f613 --- stoc/source/inspect/introspection.cxx | 45 ++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 14 deletions(-) (limited to 'stoc') diff --git a/stoc/source/inspect/introspection.cxx b/stoc/source/inspect/introspection.cxx index 116b8ed535eb..ca8d99a2095e 100644 --- a/stoc/source/inspect/introspection.cxx +++ b/stoc/source/inspect/introspection.cxx @@ -1537,6 +1537,7 @@ public: private: virtual void SAL_CALL disposing() SAL_OVERRIDE { + osl::MutexGuard g(m_aMutex); reflection_.clear(); classCache_.clear(); typeCache_.clear(); @@ -1572,16 +1573,20 @@ css::uno::Reference Implementation::inspect( css::uno::Any const & aObject) throw (css::uno::RuntimeException, std::exception) { - osl::MutexGuard g(m_aMutex); - if (rBHelper.bDisposed || rBHelper.bInDispose) { - throw css::lang::DisposedException( - getImplementationName(), static_cast(this)); + css::uno::Reference reflection; + { + osl::MutexGuard g(m_aMutex); + if (rBHelper.bDisposed || rBHelper.bInDispose) { + throw css::lang::DisposedException( + getImplementationName(), static_cast(this)); + } + reflection = reflection_; } css::uno::Any aToInspectObj; css::uno::Type t; if (aObject >>= t) { css::uno::Reference c( - reflection_->forName(t.getTypeName())); + reflection->forName(t.getTypeName())); if (!c.is()) { SAL_WARN("stoc", "cannot reflect type " << t.getTypeName()); return css::uno::Reference(); @@ -1632,7 +1637,7 @@ css::uno::Reference Implementation::inspect( const Type* pTypes = SupportedTypesSeq.getConstArray(); for( sal_Int32 i = 0 ; i < nTypeCount ; i++ ) { - pClasses[i] = reflection_->forName(pTypes[i].getTypeName()); + pClasses[i] = reflection->forName(pTypes[i].getTypeName()); } // TODO: Caching! } @@ -1641,7 +1646,7 @@ css::uno::Reference Implementation::inspect( "stoc", "object of type \"" << aToInspectObj.getValueTypeName() << "\" lacks XTypeProvider"); - xImplClass = reflection_->forName(aToInspectObj.getValueTypeName()); + xImplClass = reflection->forName(aToInspectObj.getValueTypeName()); SupportedClassSeq.realloc(1); SupportedClassSeq[0] = xImplClass; } @@ -1651,24 +1656,36 @@ css::uno::Reference Implementation::inspect( if( xPropSet.is() ) xPropSetInfo = xPropSet->getPropertySetInfo(); } else { - xImplClass = reflection_->forName(aToInspectObj.getValueTypeName()); + xImplClass = reflection->forName(aToInspectObj.getValueTypeName()); } if (xTypeProvider.is()) { TypeKey key(xPropSetInfo, xTypeProvider->getTypes()); + + osl::MutexGuard g(m_aMutex); + if (rBHelper.bDisposed || rBHelper.bInDispose) { + throw css::lang::DisposedException( + getImplementationName(), static_cast(this)); + } pAccess = typeCache_.find(key); if (pAccess.is()) { return new ImplIntrospectionAccess(aToInspectObj, pAccess); } - pAccess = new IntrospectionAccessStatic_Impl(reflection_); + pAccess = new IntrospectionAccessStatic_Impl(reflection); typeCache_.insert(key, pAccess); } else if (xImplClass.is()) { ClassKey key(xPropSetInfo, xImplClass, SupportedClassSeq); + + osl::MutexGuard g(m_aMutex); + if (rBHelper.bDisposed || rBHelper.bInDispose) { + throw css::lang::DisposedException( + getImplementationName(), static_cast(this)); + } pAccess = classCache_.find(key); if (pAccess.is()) { return new ImplIntrospectionAccess(aToInspectObj, pAccess); } - pAccess = new IntrospectionAccessStatic_Impl(reflection_); + pAccess = new IntrospectionAccessStatic_Impl(reflection); classCache_.insert(key, pAccess); } @@ -1681,7 +1698,7 @@ css::uno::Reference Implementation::inspect( sal_Int32 i; if( !pAccess.is() ) - pAccess = new IntrospectionAccessStatic_Impl( reflection_ ); + pAccess = new IntrospectionAccessStatic_Impl( reflection ); // Referenzen auf wichtige Daten von pAccess sal_Int32& rPropCount = pAccess->mnPropCount; @@ -2317,7 +2334,7 @@ css::uno::Reference Implementation::inspect( // void als Default-Klasse eintragen css::uno::Reference xListenerClass( - reflection_->forName( + reflection->forName( cppu::UnoType::get() .getTypeName())); // ALT: Reference xListenerClass = Void_getReflection()->getIdlClass(); @@ -2329,7 +2346,7 @@ css::uno::Reference Implementation::inspect( css::uno::Reference xEventListenerClass( - reflection_->forName( + reflection->forName( cppu::UnoType< css::lang::XEventListener>::get() .getTypeName())); @@ -2404,7 +2421,7 @@ css::uno::Reference Implementation::inspect( // Ist es ein Interface oder eine struct? //Reference xClassRef = aToInspectObj.getReflection()->getIdlClass(); css::uno::Reference xClassRef( - reflection_->forName(aToInspectObj.getValueTypeName())); + reflection->forName(aToInspectObj.getValueTypeName())); if( !xClassRef.is() ) { SAL_WARN( "stoc", "Can't get XIdlClass from Reflection" ); -- cgit