summaryrefslogtreecommitdiff
path: root/cppu
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-01-30 19:20:32 +0100
committerMike Kaganski <mike.kaganski@collabora.com>2021-01-31 08:43:21 +0100
commit0752de6850e4396a0138428d7ced2287a4902874 (patch)
tree70a5fe8f6575a7daa2b3a01adfba96102502f686 /cppu
parent367b22e793aa94e7263c041c8e60a90250c780a4 (diff)
Don't use global mutex here for local mutex initialization
Change-Id: I06b0856ac5559aca472daf241771a2ef57b44912 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110147 Tested-by: Mike Kaganski <mike.kaganski@collabora.com> Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'cppu')
-rw-r--r--cppu/source/typelib/typelib.cxx55
1 files changed, 23 insertions, 32 deletions
diff --git a/cppu/source/typelib/typelib.cxx b/cppu/source/typelib/typelib.cxx
index 85a393534f07..b5f960aa345a 100644
--- a/cppu/source/typelib/typelib.cxx
+++ b/cppu/source/typelib/typelib.cxx
@@ -175,10 +175,6 @@ struct TypeDescriptor_Init_Impl
std::unique_ptr<CallbackSet_Impl> pCallbacks;
// A cache to hold descriptions
std::unique_ptr<TypeDescriptionList_Impl> pCache;
- // The mutex to guard all type library accesses
- std::unique_ptr<Mutex> pMutex;
-
- inline Mutex & getMutex();
inline void callChain( typelib_TypeDescription ** ppRet, rtl_uString * pName );
@@ -201,17 +197,6 @@ struct TypeDescriptor_Init_Impl
}
-inline Mutex & TypeDescriptor_Init_Impl::getMutex()
-{
- if( !pMutex )
- {
- MutexGuard aGuard( Mutex::getGlobalMutex() );
- if( !pMutex )
- pMutex.reset(new Mutex());
- }
- return * pMutex;
-}
-
inline void TypeDescriptor_Init_Impl::callChain(
typelib_TypeDescription ** ppRet, rtl_uString * pName )
{
@@ -295,7 +280,13 @@ TypeDescriptor_Init_Impl::~TypeDescriptor_Init_Impl()
pCallbacks.reset();
};
-namespace { struct Init : public rtl::Static< TypeDescriptor_Init_Impl, Init > {}; }
+namespace
+{
+// The mutex to guard all type library accesses, goes before Init to be available in its dtor
+osl::Mutex s_Mutex;
+
+struct Init : public rtl::Static< TypeDescriptor_Init_Impl, Init > {};
+}
extern "C" void SAL_CALL typelib_typedescription_registerCallback(
void * pContext, typelib_typedescription_Callback pCallback )
@@ -303,7 +294,7 @@ extern "C" void SAL_CALL typelib_typedescription_registerCallback(
{
// todo mt safe: guard is no solution, can not acquire while calling callback!
TypeDescriptor_Init_Impl &rInit = Init::get();
-// OslGuard aGuard( rInit.getMutex() );
+// OslGuard aGuard( s_Mutex );
if( !rInit.pCallbacks )
rInit.pCallbacks.reset(new CallbackSet_Impl);
rInit.pCallbacks->push_back( CallbackEntry( pContext, pCallback ) );
@@ -318,7 +309,7 @@ extern "C" void SAL_CALL typelib_typedescription_revokeCallback(
if( rInit.pCallbacks )
{
// todo mt safe: guard is no solution, can not acquire while calling callback!
-// OslGuard aGuard( rInit.getMutex() );
+// OslGuard aGuard( s_Mutex );
CallbackEntry aEntry( pContext, pCallback );
rInit.pCallbacks->erase(std::remove(rInit.pCallbacks->begin(), rInit.pCallbacks->end(), aEntry),
rInit.pCallbacks->end());
@@ -351,7 +342,7 @@ static void typelib_typedescription_initTables(
}
}
- MutexGuard aGuard( Init::get().getMutex() );
+ MutexGuard aGuard(s_Mutex);
if( pTD->bComplete )
return;
@@ -465,7 +456,7 @@ bool complete(typelib_TypeDescription ** ppTypeDescr, bool initTables) {
OSL_ASSERT( pTD == *ppTypeDescr ); // has to merge into existing one
// insert into the cache
- MutexGuard aGuard( rInit.getMutex() );
+ MutexGuard aGuard(s_Mutex);
if( !rInit.pCache )
rInit.pCache.reset( new TypeDescriptionList_Impl );
if( static_cast<sal_Int32>(rInit.pCache->size()) >= nCacheSize )
@@ -1364,7 +1355,7 @@ extern "C" void SAL_CALL typelib_typedescription_release(
if( pTD->pWeakRef )
{
{
- MutexGuard aGuard( rInit.getMutex() );
+ MutexGuard aGuard(s_Mutex);
// remove this description from the weak reference
pTD->pWeakRef->pType = nullptr;
}
@@ -1376,7 +1367,7 @@ extern "C" void SAL_CALL typelib_typedescription_release(
// this description is a reference too, so remove it from the hash table
if( rInit.pWeakMap )
{
- MutexGuard aGuard( rInit.getMutex() );
+ MutexGuard aGuard(s_Mutex);
WeakMap_Impl::iterator aIt = rInit.pWeakMap->find( pTD->pTypeName->buffer );
if( aIt != rInit.pWeakMap->end() && static_cast<void *>((*aIt).second) == static_cast<void *>(pTD) )
{
@@ -1426,7 +1417,7 @@ extern "C" void SAL_CALL typelib_typedescription_register(
{
// connect the description with the weak reference
TypeDescriptor_Init_Impl &rInit = Init::get();
- ClearableMutexGuard aGuard( rInit.getMutex() );
+ ClearableMutexGuard aGuard(s_Mutex);
typelib_TypeDescriptionReference * pTDR = nullptr;
typelib_typedescriptionreference_getByName( &pTDR, (*ppNewDescription)->pTypeName );
@@ -1910,7 +1901,7 @@ extern "C" void SAL_CALL typelib_typedescription_getByName(
if( !bInited )
{
// guard against multi thread access
- MutexGuard aGuard( rInit.getMutex() );
+ MutexGuard aGuard(s_Mutex);
if( !bInited )
{
// avoid recursion during the next ...new calls
@@ -1957,7 +1948,7 @@ extern "C" void SAL_CALL typelib_typedescription_getByName(
{
{
// guard against multi thread access
- MutexGuard aGuard( rInit.getMutex() );
+ MutexGuard aGuard(s_Mutex);
// pTDR->pType->pWeakRef == 0 means that the description is empty
if( pTDR->pType && pTDR->pType->pWeakRef )
{
@@ -2054,7 +2045,7 @@ extern "C" void SAL_CALL typelib_typedescription_getByName(
typelib_typedescription_register( ppRet );
// insert into the cache
- MutexGuard aGuard( rInit.getMutex() );
+ MutexGuard aGuard(s_Mutex);
if( !rInit.pCache )
rInit.pCache.reset( new TypeDescriptionList_Impl );
if( static_cast<sal_Int32>(rInit.pCache->size()) >= nCacheSize )
@@ -2110,7 +2101,7 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_new(
typelib_typedescription_register( &pRet );
// insert into the cache
- MutexGuard aGuard( rInit.getMutex() );
+ MutexGuard aGuard(s_Mutex);
if( !rInit.pCache )
rInit.pCache.reset( new TypeDescriptionList_Impl );
if( static_cast<sal_Int32>(rInit.pCache->size()) >= nCacheSize )
@@ -2136,7 +2127,7 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_new(
return;
}
- MutexGuard aGuard( rInit.getMutex() );
+ MutexGuard aGuard(s_Mutex);
typelib_typedescriptionreference_getByName( ppTDR, pTypeName );
if( *ppTDR )
return;
@@ -2193,7 +2184,7 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_release(
TypeDescriptor_Init_Impl &rInit = Init::get();
if( rInit.pWeakMap )
{
- MutexGuard aGuard( rInit.getMutex() );
+ MutexGuard aGuard(s_Mutex);
WeakMap_Impl::iterator aIt = rInit.pWeakMap->find( pRef->pTypeName->buffer );
if( aIt != rInit.pWeakMap->end() && (*aIt).second == pRef )
{
@@ -2236,7 +2227,7 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_getDescription(
}
{
- MutexGuard aGuard( Init::get().getMutex() );
+ MutexGuard aGuard(s_Mutex);
// pRef->pType->pWeakRef == 0 means that the description is empty
if( pRef->pType && pRef->pType->pWeakRef )
{
@@ -2276,7 +2267,7 @@ extern "C" void typelib_typedescriptionreference_getByName(
if( !rInit.pWeakMap )
return;
- MutexGuard aGuard( rInit.getMutex() );
+ MutexGuard aGuard(s_Mutex);
WeakMap_Impl::const_iterator aIt = rInit.pWeakMap->find( pName->buffer );
if( aIt == rInit.pWeakMap->end() )
return;
@@ -2331,7 +2322,7 @@ extern "C" void SAL_CALL typelib_setCacheSize( sal_Int32 nNewSize )
return;
TypeDescriptor_Init_Impl &rInit = Init::get();
- MutexGuard aGuard( rInit.getMutex() );
+ MutexGuard aGuard(s_Mutex);
if ((nNewSize < nCacheSize) && rInit.pCache)
{
while (static_cast<sal_Int32>(rInit.pCache->size()) != nNewSize)