diff options
Diffstat (limited to 'cppu')
-rw-r--r-- | cppu/source/typelib/typelib.cxx | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/cppu/source/typelib/typelib.cxx b/cppu/source/typelib/typelib.cxx index b5f960aa345a..85a393534f07 100644 --- a/cppu/source/typelib/typelib.cxx +++ b/cppu/source/typelib/typelib.cxx @@ -175,6 +175,10 @@ 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 ); @@ -197,6 +201,17 @@ 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 ) { @@ -280,13 +295,7 @@ TypeDescriptor_Init_Impl::~TypeDescriptor_Init_Impl() pCallbacks.reset(); }; -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 > {}; -} +namespace { struct Init : public rtl::Static< TypeDescriptor_Init_Impl, Init > {}; } extern "C" void SAL_CALL typelib_typedescription_registerCallback( void * pContext, typelib_typedescription_Callback pCallback ) @@ -294,7 +303,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( s_Mutex ); +// OslGuard aGuard( rInit.getMutex() ); if( !rInit.pCallbacks ) rInit.pCallbacks.reset(new CallbackSet_Impl); rInit.pCallbacks->push_back( CallbackEntry( pContext, pCallback ) ); @@ -309,7 +318,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( s_Mutex ); +// OslGuard aGuard( rInit.getMutex() ); CallbackEntry aEntry( pContext, pCallback ); rInit.pCallbacks->erase(std::remove(rInit.pCallbacks->begin(), rInit.pCallbacks->end(), aEntry), rInit.pCallbacks->end()); @@ -342,7 +351,7 @@ static void typelib_typedescription_initTables( } } - MutexGuard aGuard(s_Mutex); + MutexGuard aGuard( Init::get().getMutex() ); if( pTD->bComplete ) return; @@ -456,7 +465,7 @@ bool complete(typelib_TypeDescription ** ppTypeDescr, bool initTables) { OSL_ASSERT( pTD == *ppTypeDescr ); // has to merge into existing one // insert into the cache - MutexGuard aGuard(s_Mutex); + MutexGuard aGuard( rInit.getMutex() ); if( !rInit.pCache ) rInit.pCache.reset( new TypeDescriptionList_Impl ); if( static_cast<sal_Int32>(rInit.pCache->size()) >= nCacheSize ) @@ -1355,7 +1364,7 @@ extern "C" void SAL_CALL typelib_typedescription_release( if( pTD->pWeakRef ) { { - MutexGuard aGuard(s_Mutex); + MutexGuard aGuard( rInit.getMutex() ); // remove this description from the weak reference pTD->pWeakRef->pType = nullptr; } @@ -1367,7 +1376,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(s_Mutex); + MutexGuard aGuard( rInit.getMutex() ); WeakMap_Impl::iterator aIt = rInit.pWeakMap->find( pTD->pTypeName->buffer ); if( aIt != rInit.pWeakMap->end() && static_cast<void *>((*aIt).second) == static_cast<void *>(pTD) ) { @@ -1417,7 +1426,7 @@ extern "C" void SAL_CALL typelib_typedescription_register( { // connect the description with the weak reference TypeDescriptor_Init_Impl &rInit = Init::get(); - ClearableMutexGuard aGuard(s_Mutex); + ClearableMutexGuard aGuard( rInit.getMutex() ); typelib_TypeDescriptionReference * pTDR = nullptr; typelib_typedescriptionreference_getByName( &pTDR, (*ppNewDescription)->pTypeName ); @@ -1901,7 +1910,7 @@ extern "C" void SAL_CALL typelib_typedescription_getByName( if( !bInited ) { // guard against multi thread access - MutexGuard aGuard(s_Mutex); + MutexGuard aGuard( rInit.getMutex() ); if( !bInited ) { // avoid recursion during the next ...new calls @@ -1948,7 +1957,7 @@ extern "C" void SAL_CALL typelib_typedescription_getByName( { { // guard against multi thread access - MutexGuard aGuard(s_Mutex); + MutexGuard aGuard( rInit.getMutex() ); // pTDR->pType->pWeakRef == 0 means that the description is empty if( pTDR->pType && pTDR->pType->pWeakRef ) { @@ -2045,7 +2054,7 @@ extern "C" void SAL_CALL typelib_typedescription_getByName( typelib_typedescription_register( ppRet ); // insert into the cache - MutexGuard aGuard(s_Mutex); + MutexGuard aGuard( rInit.getMutex() ); if( !rInit.pCache ) rInit.pCache.reset( new TypeDescriptionList_Impl ); if( static_cast<sal_Int32>(rInit.pCache->size()) >= nCacheSize ) @@ -2101,7 +2110,7 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_new( typelib_typedescription_register( &pRet ); // insert into the cache - MutexGuard aGuard(s_Mutex); + MutexGuard aGuard( rInit.getMutex() ); if( !rInit.pCache ) rInit.pCache.reset( new TypeDescriptionList_Impl ); if( static_cast<sal_Int32>(rInit.pCache->size()) >= nCacheSize ) @@ -2127,7 +2136,7 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_new( return; } - MutexGuard aGuard(s_Mutex); + MutexGuard aGuard( rInit.getMutex() ); typelib_typedescriptionreference_getByName( ppTDR, pTypeName ); if( *ppTDR ) return; @@ -2184,7 +2193,7 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_release( TypeDescriptor_Init_Impl &rInit = Init::get(); if( rInit.pWeakMap ) { - MutexGuard aGuard(s_Mutex); + MutexGuard aGuard( rInit.getMutex() ); WeakMap_Impl::iterator aIt = rInit.pWeakMap->find( pRef->pTypeName->buffer ); if( aIt != rInit.pWeakMap->end() && (*aIt).second == pRef ) { @@ -2227,7 +2236,7 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_getDescription( } { - MutexGuard aGuard(s_Mutex); + MutexGuard aGuard( Init::get().getMutex() ); // pRef->pType->pWeakRef == 0 means that the description is empty if( pRef->pType && pRef->pType->pWeakRef ) { @@ -2267,7 +2276,7 @@ extern "C" void typelib_typedescriptionreference_getByName( if( !rInit.pWeakMap ) return; - MutexGuard aGuard(s_Mutex); + MutexGuard aGuard( rInit.getMutex() ); WeakMap_Impl::const_iterator aIt = rInit.pWeakMap->find( pName->buffer ); if( aIt == rInit.pWeakMap->end() ) return; @@ -2322,7 +2331,7 @@ extern "C" void SAL_CALL typelib_setCacheSize( sal_Int32 nNewSize ) return; TypeDescriptor_Init_Impl &rInit = Init::get(); - MutexGuard aGuard(s_Mutex); + MutexGuard aGuard( rInit.getMutex() ); if ((nNewSize < nCacheSize) && rInit.pCache) { while (static_cast<sal_Int32>(rInit.pCache->size()) != nNewSize) |