summaryrefslogtreecommitdiff
path: root/cppuhelper/source/component_context.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'cppuhelper/source/component_context.cxx')
-rw-r--r--cppuhelper/source/component_context.cxx64
1 files changed, 31 insertions, 33 deletions
diff --git a/cppuhelper/source/component_context.cxx b/cppuhelper/source/component_context.cxx
index 1aa3d33e5c35..da070bdf027c 100644
--- a/cppuhelper/source/component_context.cxx
+++ b/cppuhelper/source/component_context.cxx
@@ -27,9 +27,11 @@
#include <uno/lbnames.h>
#include <uno/mapping.hxx>
+#include <cppuhelper/basemutex.hxx>
#include <cppuhelper/compbase.hxx>
#include <cppuhelper/component_context.hxx>
#include <cppuhelper/implbase.hxx>
+#include <compbase2.hxx>
#include <com/sun/star/container/XNameContainer.hpp>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
@@ -43,8 +45,9 @@
#include <comphelper/sequence.hxx>
#include <memory>
+#include <utility>
-constexpr OUStringLiteral SMGR_SINGLETON = u"/singletons/com.sun.star.lang.theServiceManager";
+constexpr OUString SMGR_SINGLETON = u"/singletons/com.sun.star.lang.theServiceManager"_ustr;
constexpr OUStringLiteral TDMGR_SINGLETON = u"/singletons/com.sun.star.reflection.theTypeDescriptionManager";
constexpr OUStringLiteral AC_SINGLETON = u"/singletons/com.sun.star.security.theAccessController";
@@ -55,20 +58,24 @@ using namespace ::com::sun::star;
namespace cppu
{
-static void try_dispose( Reference< XInterface > const & xInstance )
+static void try_dispose( std::unique_lock<std::mutex>& rGuard, Reference< XInterface > const & xInstance )
{
Reference< lang::XComponent > xComp( xInstance, UNO_QUERY );
if (xComp.is())
{
+ rGuard.unlock();
xComp->dispose();
+ rGuard.lock();
}
}
-static void try_dispose( Reference< lang::XComponent > const & xComp )
+static void try_dispose( std::unique_lock<std::mutex>& rGuard, Reference< lang::XComponent > const & xComp )
{
if (xComp.is())
{
+ rGuard.unlock();
xComp->dispose();
+ rGuard.lock();
}
}
@@ -113,16 +120,8 @@ void DisposingForwarder::disposing( lang::EventObject const & )
namespace {
-struct MutexHolder
-{
-protected:
- Mutex m_mutex;
-};
-
-
class ComponentContext
- : private MutexHolder
- , public WeakComponentImplHelper< XComponentContext,
+ : public cppuhelper::WeakComponentImplHelper2< XComponentContext,
container::XNameContainer >
{
protected:
@@ -133,8 +132,8 @@ protected:
Any value;
bool lateInit;
- ContextEntry( Any const & value_, bool lateInit_ )
- : value( value_ )
+ ContextEntry( Any value_, bool lateInit_ )
+ : value(std::move( value_ ))
, lateInit( lateInit_ )
{}
};
@@ -146,7 +145,7 @@ protected:
protected:
Any lookupMap( OUString const & rName );
- virtual void SAL_CALL disposing() override;
+ virtual void disposing(std::unique_lock<std::mutex>&) override;
public:
ComponentContext(
ContextEntry_Init const * pEntries, sal_Int32 nEntries,
@@ -184,7 +183,7 @@ void ComponentContext::insertByName(
/* lateInit_: */
name.startsWith( "/singletons/" ) &&
!element.hasValue() );
- MutexGuard guard( m_mutex );
+ std::unique_lock guard( m_aMutex );
std::pair<t_map::iterator, bool> insertion( m_map.emplace(
name, entry ) );
if (! insertion.second)
@@ -196,7 +195,7 @@ void ComponentContext::insertByName(
void ComponentContext::removeByName( OUString const & name )
{
- MutexGuard guard( m_mutex );
+ std::unique_lock guard( m_aMutex );
t_map::iterator iFind( m_map.find( name ) );
if (iFind == m_map.end())
throw container::NoSuchElementException(
@@ -211,7 +210,7 @@ void ComponentContext::removeByName( OUString const & name )
void ComponentContext::replaceByName(
OUString const & name, Any const & element )
{
- MutexGuard guard( m_mutex );
+ std::unique_lock guard( m_aMutex );
t_map::iterator iFind( m_map.find( name ) );
if (iFind == m_map.end())
throw container::NoSuchElementException(
@@ -240,14 +239,14 @@ Any ComponentContext::getByName( OUString const & name )
Sequence<OUString> ComponentContext::getElementNames()
{
- MutexGuard guard( m_mutex );
+ std::unique_lock guard( m_aMutex );
return comphelper::mapKeysToSequence(m_map);
}
sal_Bool ComponentContext::hasByName( OUString const & name )
{
- MutexGuard guard( m_mutex );
+ std::unique_lock guard( m_aMutex );
return m_map.find( name ) != m_map.end();
}
@@ -261,14 +260,14 @@ Type ComponentContext::getElementType()
sal_Bool ComponentContext::hasElements()
{
- MutexGuard guard( m_mutex );
+ std::unique_lock guard( m_aMutex );
return ! m_map.empty();
}
Any ComponentContext::lookupMap( OUString const & rName )
{
- ResettableMutexGuard guard( m_mutex );
+ std::unique_lock guard( m_aMutex );
t_map::iterator iFind( m_map.find( rName ) );
if (iFind == m_map.end())
return Any();
@@ -279,7 +278,7 @@ Any ComponentContext::lookupMap( OUString const & rName )
// late init singleton entry
Reference< XInterface > xInstance;
- guard.clear();
+ guard.unlock();
try
{
@@ -339,7 +338,7 @@ Any ComponentContext::lookupMap( OUString const & rName )
"cppuhelper", "no service object raising singleton " << rName);
Any ret;
- guard.reset();
+ guard.lock();
iFind = m_map.find( rName );
if (iFind != m_map.end())
{
@@ -352,9 +351,8 @@ Any ComponentContext::lookupMap( OUString const & rName )
}
ret = rEntry.value;
}
- guard.clear();
if (ret != xInstance) {
- try_dispose( xInstance );
+ try_dispose( guard, xInstance );
}
return ret;
}
@@ -389,7 +387,7 @@ Reference< lang::XMultiComponentFactory > ComponentContext::getServiceManager()
return m_xSMgr;
}
-void ComponentContext::disposing()
+void ComponentContext::disposing(std::unique_lock<std::mutex>& rGuard)
{
Reference< lang::XComponent > xTDMgr, xAC; // to be disposed separately
@@ -403,7 +401,6 @@ void ComponentContext::disposing()
if (rEntry.lateInit)
{
// late init
- MutexGuard guard( m_mutex );
if (rEntry.lateInit)
{
rEntry.value.clear(); // release factory
@@ -426,19 +423,21 @@ void ComponentContext::disposing()
}
else // dispose immediately
{
+ rGuard.unlock();
xComp->dispose();
+ rGuard.lock();
}
}
}
}
// dispose service manager
- try_dispose( m_xSMgr );
+ try_dispose( rGuard, m_xSMgr );
m_xSMgr.clear();
// dispose ac
- try_dispose( xAC );
+ try_dispose( rGuard, xAC );
// dispose tdmgr; revokes callback from cppu runtime
- try_dispose( xTDMgr );
+ try_dispose( rGuard, xTDMgr );
m_map.clear();
@@ -464,8 +463,7 @@ void ComponentContext::disposing()
ComponentContext::ComponentContext(
ContextEntry_Init const * pEntries, sal_Int32 nEntries,
Reference< XComponentContext > const & xDelegate )
- : WeakComponentImplHelper( m_mutex ),
- m_xDelegate( xDelegate )
+ : m_xDelegate( xDelegate )
{
for ( sal_Int32 nPos = 0; nPos < nEntries; ++nPos )
{