no need to init this on-demand
we ~always need it Change-Id: I94ea47ed75478ecc7c78e89c0209a22d21be2b1b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117133 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
@@ -281,31 +281,29 @@ TypeDescriptor_Init_Impl::~TypeDescriptor_Init_Impl()
|
|||||||
SAL_INFO_IF( !maCallbacks.empty(), "cppu.typelib", "pCallbacks is not NULL or empty" );
|
SAL_INFO_IF( !maCallbacks.empty(), "cppu.typelib", "pCallbacks is not NULL or empty" );
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace { struct Init : public rtl::Static< TypeDescriptor_Init_Impl, Init > {}; }
|
namespace {
|
||||||
|
TypeDescriptor_Init_Impl gInit;
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" void SAL_CALL typelib_typedescription_registerCallback(
|
extern "C" void SAL_CALL typelib_typedescription_registerCallback(
|
||||||
void * pContext, typelib_typedescription_Callback pCallback )
|
void * pContext, typelib_typedescription_Callback pCallback )
|
||||||
SAL_THROW_EXTERN_C()
|
SAL_THROW_EXTERN_C()
|
||||||
{
|
{
|
||||||
// todo mt safe: guard is no solution, can not acquire while calling callback!
|
// 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( rInit.getMutex() );
|
||||||
rInit.maCallbacks.push_back( CallbackEntry( pContext, pCallback ) );
|
gInit.maCallbacks.push_back( CallbackEntry( pContext, pCallback ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern "C" void SAL_CALL typelib_typedescription_revokeCallback(
|
extern "C" void SAL_CALL typelib_typedescription_revokeCallback(
|
||||||
void * pContext, typelib_typedescription_Callback pCallback )
|
void * pContext, typelib_typedescription_Callback pCallback )
|
||||||
SAL_THROW_EXTERN_C()
|
SAL_THROW_EXTERN_C()
|
||||||
{
|
|
||||||
TypeDescriptor_Init_Impl &rInit = Init::get();
|
|
||||||
{
|
{
|
||||||
// todo mt safe: guard is no solution, can not acquire while calling callback!
|
// todo mt safe: guard is no solution, can not acquire while calling callback!
|
||||||
// OslGuard aGuard( rInit.getMutex() );
|
// OslGuard aGuard( rInit.getMutex() );
|
||||||
CallbackEntry aEntry( pContext, pCallback );
|
CallbackEntry aEntry( pContext, pCallback );
|
||||||
rInit.maCallbacks.erase(std::remove(rInit.maCallbacks.begin(), rInit.maCallbacks.end(), aEntry),
|
gInit.maCallbacks.erase(std::remove(gInit.maCallbacks.begin(), gInit.maCallbacks.end(), aEntry),
|
||||||
rInit.maCallbacks.end());
|
gInit.maCallbacks.end());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void typelib_typedescription_initTables(
|
static void typelib_typedescription_initTables(
|
||||||
@@ -334,7 +332,7 @@ static void typelib_typedescription_initTables(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MutexGuard aGuard( Init::get().getMutex() );
|
MutexGuard aGuard( gInit.getMutex() );
|
||||||
if( pTD->bComplete )
|
if( pTD->bComplete )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -414,8 +412,7 @@ bool complete(typelib_TypeDescription ** ppTypeDescr, bool initTables) {
|
|||||||
|
|
||||||
typelib_TypeDescription * pTD = nullptr;
|
typelib_TypeDescription * pTD = nullptr;
|
||||||
// on demand access of complete td
|
// on demand access of complete td
|
||||||
TypeDescriptor_Init_Impl &rInit = Init::get();
|
gInit.callChain( &pTD, (*ppTypeDescr)->pTypeName );
|
||||||
rInit.callChain( &pTD, (*ppTypeDescr)->pTypeName );
|
|
||||||
if (pTD)
|
if (pTD)
|
||||||
{
|
{
|
||||||
if (typelib_TypeClass_TYPEDEF == pTD->eTypeClass)
|
if (typelib_TypeClass_TYPEDEF == pTD->eTypeClass)
|
||||||
@@ -448,15 +445,15 @@ bool complete(typelib_TypeDescription ** ppTypeDescr, bool initTables) {
|
|||||||
OSL_ASSERT( pTD == *ppTypeDescr ); // has to merge into existing one
|
OSL_ASSERT( pTD == *ppTypeDescr ); // has to merge into existing one
|
||||||
|
|
||||||
// insert into the cache
|
// insert into the cache
|
||||||
MutexGuard aGuard( rInit.getMutex() );
|
MutexGuard aGuard( gInit.getMutex() );
|
||||||
if( static_cast<sal_Int32>(rInit.maCache.size()) >= nCacheSize )
|
if( static_cast<sal_Int32>(gInit.maCache.size()) >= nCacheSize )
|
||||||
{
|
{
|
||||||
typelib_typedescription_release( rInit.maCache.front() );
|
typelib_typedescription_release( gInit.maCache.front() );
|
||||||
rInit.maCache.pop_front();
|
gInit.maCache.pop_front();
|
||||||
}
|
}
|
||||||
// descriptions in the cache must be acquired!
|
// descriptions in the cache must be acquired!
|
||||||
typelib_typedescription_acquire( pTD );
|
typelib_typedescription_acquire( pTD );
|
||||||
rInit.maCache.push_back( pTD );
|
gInit.maCache.push_back( pTD );
|
||||||
|
|
||||||
OSL_ASSERT(
|
OSL_ASSERT(
|
||||||
pTD->bComplete
|
pTD->bComplete
|
||||||
@@ -501,7 +498,7 @@ extern "C" void typelib_typedescription_newEmpty(
|
|||||||
auto pTmp = allocTypeDescription<typelib_IndirectTypeDescription>();
|
auto pTmp = allocTypeDescription<typelib_IndirectTypeDescription>();
|
||||||
pRet = &pTmp->aBase;
|
pRet = &pTmp->aBase;
|
||||||
#if OSL_DEBUG_LEVEL > 0
|
#if OSL_DEBUG_LEVEL > 0
|
||||||
osl_atomic_increment( &Init::get().nIndirectTypeDescriptionCount );
|
osl_atomic_increment( &gInit.nIndirectTypeDescriptionCount );
|
||||||
#endif
|
#endif
|
||||||
pTmp->pType = nullptr;
|
pTmp->pType = nullptr;
|
||||||
// coverity[leaked_storage] - this is on purpose
|
// coverity[leaked_storage] - this is on purpose
|
||||||
@@ -514,7 +511,7 @@ extern "C" void typelib_typedescription_newEmpty(
|
|||||||
auto pTmp = allocTypeDescription<typelib_StructTypeDescription>();
|
auto pTmp = allocTypeDescription<typelib_StructTypeDescription>();
|
||||||
pRet = &pTmp->aBase.aBase;
|
pRet = &pTmp->aBase.aBase;
|
||||||
#if OSL_DEBUG_LEVEL > 0
|
#if OSL_DEBUG_LEVEL > 0
|
||||||
osl_atomic_increment( &Init::get().nCompoundTypeDescriptionCount );
|
osl_atomic_increment( &gInit.nCompoundTypeDescriptionCount );
|
||||||
#endif
|
#endif
|
||||||
pTmp->aBase.pBaseTypeDescription = nullptr;
|
pTmp->aBase.pBaseTypeDescription = nullptr;
|
||||||
pTmp->aBase.nMembers = 0;
|
pTmp->aBase.nMembers = 0;
|
||||||
@@ -532,7 +529,7 @@ extern "C" void typelib_typedescription_newEmpty(
|
|||||||
auto pTmp = allocTypeDescription<typelib_CompoundTypeDescription>();
|
auto pTmp = allocTypeDescription<typelib_CompoundTypeDescription>();
|
||||||
pRet = &pTmp->aBase;
|
pRet = &pTmp->aBase;
|
||||||
#if OSL_DEBUG_LEVEL > 0
|
#if OSL_DEBUG_LEVEL > 0
|
||||||
osl_atomic_increment( &Init::get().nCompoundTypeDescriptionCount );
|
osl_atomic_increment( &gInit.nCompoundTypeDescriptionCount );
|
||||||
#endif
|
#endif
|
||||||
pTmp->pBaseTypeDescription = nullptr;
|
pTmp->pBaseTypeDescription = nullptr;
|
||||||
pTmp->nMembers = 0;
|
pTmp->nMembers = 0;
|
||||||
@@ -548,7 +545,7 @@ extern "C" void typelib_typedescription_newEmpty(
|
|||||||
auto pTmp = allocTypeDescription<typelib_EnumTypeDescription>();
|
auto pTmp = allocTypeDescription<typelib_EnumTypeDescription>();
|
||||||
pRet = &pTmp->aBase;
|
pRet = &pTmp->aBase;
|
||||||
#if OSL_DEBUG_LEVEL > 0
|
#if OSL_DEBUG_LEVEL > 0
|
||||||
osl_atomic_increment( &Init::get().nEnumTypeDescriptionCount );
|
osl_atomic_increment( &gInit.nEnumTypeDescriptionCount );
|
||||||
#endif
|
#endif
|
||||||
pTmp->nDefaultEnumValue = 0;
|
pTmp->nDefaultEnumValue = 0;
|
||||||
pTmp->nEnumValues = 0;
|
pTmp->nEnumValues = 0;
|
||||||
@@ -564,7 +561,7 @@ extern "C" void typelib_typedescription_newEmpty(
|
|||||||
typelib_InterfaceTypeDescription>();
|
typelib_InterfaceTypeDescription>();
|
||||||
pRet = &pTmp->aBase;
|
pRet = &pTmp->aBase;
|
||||||
#if OSL_DEBUG_LEVEL > 0
|
#if OSL_DEBUG_LEVEL > 0
|
||||||
osl_atomic_increment( &Init::get().nInterfaceTypeDescriptionCount );
|
osl_atomic_increment( &gInit.nInterfaceTypeDescriptionCount );
|
||||||
#endif
|
#endif
|
||||||
pTmp->pBaseTypeDescription = nullptr;
|
pTmp->pBaseTypeDescription = nullptr;
|
||||||
pTmp->nMembers = 0;
|
pTmp->nMembers = 0;
|
||||||
@@ -586,7 +583,7 @@ extern "C" void typelib_typedescription_newEmpty(
|
|||||||
typelib_InterfaceMethodTypeDescription>();
|
typelib_InterfaceMethodTypeDescription>();
|
||||||
pRet = &pTmp->aBase.aBase;
|
pRet = &pTmp->aBase.aBase;
|
||||||
#if OSL_DEBUG_LEVEL > 0
|
#if OSL_DEBUG_LEVEL > 0
|
||||||
osl_atomic_increment( &Init::get().nInterfaceMethodTypeDescriptionCount );
|
osl_atomic_increment( &gInit.nInterfaceMethodTypeDescriptionCount );
|
||||||
#endif
|
#endif
|
||||||
pTmp->aBase.pMemberName = nullptr;
|
pTmp->aBase.pMemberName = nullptr;
|
||||||
pTmp->pReturnTypeRef = nullptr;
|
pTmp->pReturnTypeRef = nullptr;
|
||||||
@@ -607,7 +604,7 @@ extern "C" void typelib_typedescription_newEmpty(
|
|||||||
typelib_InterfaceAttributeTypeDescription>();
|
typelib_InterfaceAttributeTypeDescription>();
|
||||||
pRet = &pTmp->aBase.aBase;
|
pRet = &pTmp->aBase.aBase;
|
||||||
#if OSL_DEBUG_LEVEL > 0
|
#if OSL_DEBUG_LEVEL > 0
|
||||||
osl_atomic_increment( &Init::get().nInterfaceAttributeTypeDescriptionCount );
|
osl_atomic_increment( &gInit.nInterfaceAttributeTypeDescriptionCount );
|
||||||
#endif
|
#endif
|
||||||
pTmp->aBase.pMemberName = nullptr;
|
pTmp->aBase.pMemberName = nullptr;
|
||||||
pTmp->pAttributeTypeRef = nullptr;
|
pTmp->pAttributeTypeRef = nullptr;
|
||||||
@@ -626,7 +623,7 @@ extern "C" void typelib_typedescription_newEmpty(
|
|||||||
{
|
{
|
||||||
pRet = allocTypeDescription<typelib_TypeDescription>();
|
pRet = allocTypeDescription<typelib_TypeDescription>();
|
||||||
#if OSL_DEBUG_LEVEL > 0
|
#if OSL_DEBUG_LEVEL > 0
|
||||||
osl_atomic_increment( &Init::get().nTypeDescriptionCount );
|
osl_atomic_increment( &gInit.nTypeDescriptionCount );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1339,13 +1336,12 @@ extern "C" void SAL_CALL typelib_typedescription_release(
|
|||||||
if (0 != ref)
|
if (0 != ref)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
TypeDescriptor_Init_Impl &rInit = Init::get();
|
|
||||||
if( TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK( pTD->eTypeClass ) )
|
if( TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK( pTD->eTypeClass ) )
|
||||||
{
|
{
|
||||||
if( pTD->pWeakRef )
|
if( pTD->pWeakRef )
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
MutexGuard aGuard( rInit.getMutex() );
|
MutexGuard aGuard( gInit.getMutex() );
|
||||||
// remove this description from the weak reference
|
// remove this description from the weak reference
|
||||||
pTD->pWeakRef->pType = nullptr;
|
pTD->pWeakRef->pType = nullptr;
|
||||||
}
|
}
|
||||||
@@ -1355,12 +1351,12 @@ extern "C" void SAL_CALL typelib_typedescription_release(
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// this description is a reference too, so remove it from the hash table
|
// this description is a reference too, so remove it from the hash table
|
||||||
MutexGuard aGuard( rInit.getMutex() );
|
MutexGuard aGuard( gInit.getMutex() );
|
||||||
WeakMap_Impl::iterator aIt = rInit.maWeakMap.find( pTD->pTypeName->buffer );
|
WeakMap_Impl::iterator aIt = gInit.maWeakMap.find( pTD->pTypeName->buffer );
|
||||||
if( aIt != rInit.maWeakMap.end() && static_cast<void *>((*aIt).second) == static_cast<void *>(pTD) )
|
if( aIt != gInit.maWeakMap.end() && static_cast<void *>((*aIt).second) == static_cast<void *>(pTD) )
|
||||||
{
|
{
|
||||||
// remove only if it contains the same object
|
// remove only if it contains the same object
|
||||||
rInit.maWeakMap.erase( aIt );
|
gInit.maWeakMap.erase( aIt );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1371,26 +1367,26 @@ extern "C" void SAL_CALL typelib_typedescription_release(
|
|||||||
switch( pTD->eTypeClass )
|
switch( pTD->eTypeClass )
|
||||||
{
|
{
|
||||||
case typelib_TypeClass_SEQUENCE:
|
case typelib_TypeClass_SEQUENCE:
|
||||||
osl_atomic_decrement( &rInit.nIndirectTypeDescriptionCount );
|
osl_atomic_decrement( &gInit.nIndirectTypeDescriptionCount );
|
||||||
break;
|
break;
|
||||||
case typelib_TypeClass_STRUCT:
|
case typelib_TypeClass_STRUCT:
|
||||||
case typelib_TypeClass_EXCEPTION:
|
case typelib_TypeClass_EXCEPTION:
|
||||||
osl_atomic_decrement( &rInit.nCompoundTypeDescriptionCount );
|
osl_atomic_decrement( &gInit.nCompoundTypeDescriptionCount );
|
||||||
break;
|
break;
|
||||||
case typelib_TypeClass_INTERFACE:
|
case typelib_TypeClass_INTERFACE:
|
||||||
osl_atomic_decrement( &rInit.nInterfaceTypeDescriptionCount );
|
osl_atomic_decrement( &gInit.nInterfaceTypeDescriptionCount );
|
||||||
break;
|
break;
|
||||||
case typelib_TypeClass_INTERFACE_METHOD:
|
case typelib_TypeClass_INTERFACE_METHOD:
|
||||||
osl_atomic_decrement( &rInit.nInterfaceMethodTypeDescriptionCount );
|
osl_atomic_decrement( &gInit.nInterfaceMethodTypeDescriptionCount );
|
||||||
break;
|
break;
|
||||||
case typelib_TypeClass_INTERFACE_ATTRIBUTE:
|
case typelib_TypeClass_INTERFACE_ATTRIBUTE:
|
||||||
osl_atomic_decrement( &rInit.nInterfaceAttributeTypeDescriptionCount );
|
osl_atomic_decrement( &gInit.nInterfaceAttributeTypeDescriptionCount );
|
||||||
break;
|
break;
|
||||||
case typelib_TypeClass_ENUM:
|
case typelib_TypeClass_ENUM:
|
||||||
osl_atomic_decrement( &rInit.nEnumTypeDescriptionCount );
|
osl_atomic_decrement( &gInit.nEnumTypeDescriptionCount );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
osl_atomic_decrement( &rInit.nTypeDescriptionCount );
|
osl_atomic_decrement( &gInit.nTypeDescriptionCount );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1403,8 +1399,7 @@ extern "C" void SAL_CALL typelib_typedescription_register(
|
|||||||
SAL_THROW_EXTERN_C()
|
SAL_THROW_EXTERN_C()
|
||||||
{
|
{
|
||||||
// connect the description with the weak reference
|
// connect the description with the weak reference
|
||||||
TypeDescriptor_Init_Impl &rInit = Init::get();
|
ClearableMutexGuard aGuard( gInit.getMutex() );
|
||||||
ClearableMutexGuard aGuard( rInit.getMutex() );
|
|
||||||
|
|
||||||
typelib_TypeDescriptionReference * pTDR = nullptr;
|
typelib_TypeDescriptionReference * pTDR = nullptr;
|
||||||
typelib_typedescriptionreference_getByName( &pTDR, (*ppNewDescription)->pTypeName );
|
typelib_typedescriptionreference_getByName( &pTDR, (*ppNewDescription)->pTypeName );
|
||||||
@@ -1587,7 +1582,7 @@ extern "C" void SAL_CALL typelib_typedescription_register(
|
|||||||
pTDR = reinterpret_cast<typelib_TypeDescriptionReference *>(*ppNewDescription);
|
pTDR = reinterpret_cast<typelib_TypeDescriptionReference *>(*ppNewDescription);
|
||||||
|
|
||||||
// description is the weak itself, so register it
|
// description is the weak itself, so register it
|
||||||
rInit.maWeakMap[pTDR->pTypeName->buffer] = pTDR;
|
gInit.maWeakMap[pTDR->pTypeName->buffer] = pTDR;
|
||||||
OSL_ASSERT( static_cast<void *>(*ppNewDescription) == static_cast<void *>(pTDR) );
|
OSL_ASSERT( static_cast<void *>(*ppNewDescription) == static_cast<void *>(pTDR) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1881,12 +1876,11 @@ extern "C" void SAL_CALL typelib_typedescription_getByName(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool bInited = false;
|
static bool bInited = false;
|
||||||
TypeDescriptor_Init_Impl &rInit = Init::get();
|
|
||||||
|
|
||||||
if( !bInited )
|
if( !bInited )
|
||||||
{
|
{
|
||||||
// guard against multi thread access
|
// guard against multi thread access
|
||||||
MutexGuard aGuard( rInit.getMutex() );
|
MutexGuard aGuard( gInit.getMutex() );
|
||||||
if( !bInited )
|
if( !bInited )
|
||||||
{
|
{
|
||||||
// avoid recursion during the next ...new calls
|
// avoid recursion during the next ...new calls
|
||||||
@@ -1933,7 +1927,7 @@ extern "C" void SAL_CALL typelib_typedescription_getByName(
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
// guard against multi thread access
|
// guard against multi thread access
|
||||||
MutexGuard aGuard( rInit.getMutex() );
|
MutexGuard aGuard( gInit.getMutex() );
|
||||||
// pTDR->pType->pWeakRef == 0 means that the description is empty
|
// pTDR->pType->pWeakRef == 0 means that the description is empty
|
||||||
if( pTDR->pType && pTDR->pType->pWeakRef )
|
if( pTDR->pType && pTDR->pType->pWeakRef )
|
||||||
{
|
{
|
||||||
@@ -2006,7 +2000,7 @@ extern "C" void SAL_CALL typelib_typedescription_getByName(
|
|||||||
if (nullptr == *ppRet)
|
if (nullptr == *ppRet)
|
||||||
{
|
{
|
||||||
// on demand access
|
// on demand access
|
||||||
rInit.callChain( ppRet, pName );
|
gInit.callChain( ppRet, pName );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !(*ppRet) )
|
if( !(*ppRet) )
|
||||||
@@ -2030,15 +2024,15 @@ extern "C" void SAL_CALL typelib_typedescription_getByName(
|
|||||||
typelib_typedescription_register( ppRet );
|
typelib_typedescription_register( ppRet );
|
||||||
|
|
||||||
// insert into the cache
|
// insert into the cache
|
||||||
MutexGuard aGuard( rInit.getMutex() );
|
MutexGuard aGuard( gInit.getMutex() );
|
||||||
if( static_cast<sal_Int32>(rInit.maCache.size()) >= nCacheSize )
|
if( static_cast<sal_Int32>(gInit.maCache.size()) >= nCacheSize )
|
||||||
{
|
{
|
||||||
typelib_typedescription_release( rInit.maCache.front() );
|
typelib_typedescription_release( gInit.maCache.front() );
|
||||||
rInit.maCache.pop_front();
|
gInit.maCache.pop_front();
|
||||||
}
|
}
|
||||||
// descriptions in the cache must be acquired!
|
// descriptions in the cache must be acquired!
|
||||||
typelib_typedescription_acquire( *ppRet );
|
typelib_typedescription_acquire( *ppRet );
|
||||||
rInit.maCache.push_back( *ppRet );
|
gInit.maCache.push_back( *ppRet );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2057,12 +2051,11 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_new(
|
|||||||
typelib_TypeClass eTypeClass, rtl_uString * pTypeName )
|
typelib_TypeClass eTypeClass, rtl_uString * pTypeName )
|
||||||
SAL_THROW_EXTERN_C()
|
SAL_THROW_EXTERN_C()
|
||||||
{
|
{
|
||||||
TypeDescriptor_Init_Impl &rInit = Init::get();
|
|
||||||
if( eTypeClass == typelib_TypeClass_TYPEDEF )
|
if( eTypeClass == typelib_TypeClass_TYPEDEF )
|
||||||
{
|
{
|
||||||
// on demand access
|
// on demand access
|
||||||
typelib_TypeDescription * pRet = nullptr;
|
typelib_TypeDescription * pRet = nullptr;
|
||||||
rInit.callChain( &pRet, pTypeName );
|
gInit.callChain( &pRet, pTypeName );
|
||||||
if( pRet )
|
if( pRet )
|
||||||
{
|
{
|
||||||
// typedescription found
|
// typedescription found
|
||||||
@@ -2084,13 +2077,13 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_new(
|
|||||||
typelib_typedescription_register( &pRet );
|
typelib_typedescription_register( &pRet );
|
||||||
|
|
||||||
// insert into the cache
|
// insert into the cache
|
||||||
MutexGuard aGuard( rInit.getMutex() );
|
MutexGuard aGuard( gInit.getMutex() );
|
||||||
if( static_cast<sal_Int32>(rInit.maCache.size()) >= nCacheSize )
|
if( static_cast<sal_Int32>(gInit.maCache.size()) >= nCacheSize )
|
||||||
{
|
{
|
||||||
typelib_typedescription_release( rInit.maCache.front() );
|
typelib_typedescription_release( gInit.maCache.front() );
|
||||||
rInit.maCache.pop_front();
|
gInit.maCache.pop_front();
|
||||||
}
|
}
|
||||||
rInit.maCache.push_back( pRet );
|
gInit.maCache.push_back( pRet );
|
||||||
// pRet kept acquired for cache
|
// pRet kept acquired for cache
|
||||||
|
|
||||||
typelib_typedescriptionreference_acquire( pRet->pWeakRef );
|
typelib_typedescriptionreference_acquire( pRet->pWeakRef );
|
||||||
@@ -2108,7 +2101,7 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_new(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MutexGuard aGuard( rInit.getMutex() );
|
MutexGuard aGuard( gInit.getMutex() );
|
||||||
typelib_typedescriptionreference_getByName( ppTDR, pTypeName );
|
typelib_typedescriptionreference_getByName( ppTDR, pTypeName );
|
||||||
if( *ppTDR )
|
if( *ppTDR )
|
||||||
return;
|
return;
|
||||||
@@ -2117,7 +2110,7 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_new(
|
|||||||
{
|
{
|
||||||
typelib_TypeDescriptionReference * pTDR = new typelib_TypeDescriptionReference;
|
typelib_TypeDescriptionReference * pTDR = new typelib_TypeDescriptionReference;
|
||||||
#if OSL_DEBUG_LEVEL > 0
|
#if OSL_DEBUG_LEVEL > 0
|
||||||
osl_atomic_increment( &rInit.nTypeDescriptionReferenceCount );
|
osl_atomic_increment( &gInit.nTypeDescriptionReferenceCount );
|
||||||
#endif
|
#endif
|
||||||
pTDR->nRefCount = 1;
|
pTDR->nRefCount = 1;
|
||||||
pTDR->nStaticRefCount = 0;
|
pTDR->nStaticRefCount = 0;
|
||||||
@@ -2139,7 +2132,7 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_new(
|
|||||||
|
|
||||||
// Heavy hack, the const sal_Unicode * is hold by the typedescription reference
|
// Heavy hack, the const sal_Unicode * is hold by the typedescription reference
|
||||||
// not registered
|
// not registered
|
||||||
rInit.maWeakMap[ (*ppTDR)->pTypeName->buffer ] = *ppTDR;
|
gInit.maWeakMap[ (*ppTDR)->pTypeName->buffer ] = *ppTDR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2160,19 +2153,18 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_release(
|
|||||||
{
|
{
|
||||||
if( ! osl_atomic_decrement( &pRef->nRefCount ) )
|
if( ! osl_atomic_decrement( &pRef->nRefCount ) )
|
||||||
{
|
{
|
||||||
TypeDescriptor_Init_Impl &rInit = Init::get();
|
MutexGuard aGuard( gInit.getMutex() );
|
||||||
MutexGuard aGuard( rInit.getMutex() );
|
WeakMap_Impl::iterator aIt = gInit.maWeakMap.find( pRef->pTypeName->buffer );
|
||||||
WeakMap_Impl::iterator aIt = rInit.maWeakMap.find( pRef->pTypeName->buffer );
|
if( aIt != gInit.maWeakMap.end() && (*aIt).second == pRef )
|
||||||
if( aIt != rInit.maWeakMap.end() && (*aIt).second == pRef )
|
|
||||||
{
|
{
|
||||||
// remove only if it contains the same object
|
// remove only if it contains the same object
|
||||||
rInit.maWeakMap.erase( aIt );
|
gInit.maWeakMap.erase( aIt );
|
||||||
}
|
}
|
||||||
|
|
||||||
rtl_uString_release( pRef->pTypeName );
|
rtl_uString_release( pRef->pTypeName );
|
||||||
OSL_ASSERT( pRef->pType == nullptr );
|
OSL_ASSERT( pRef->pType == nullptr );
|
||||||
#if OSL_DEBUG_LEVEL > 0
|
#if OSL_DEBUG_LEVEL > 0
|
||||||
osl_atomic_decrement( &rInit.nTypeDescriptionReferenceCount );
|
osl_atomic_decrement( &gInit.nTypeDescriptionReferenceCount );
|
||||||
#endif
|
#endif
|
||||||
delete pRef;
|
delete pRef;
|
||||||
}
|
}
|
||||||
@@ -2203,7 +2195,7 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_getDescription(
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
MutexGuard aGuard( Init::get().getMutex() );
|
MutexGuard aGuard( gInit.getMutex() );
|
||||||
// pRef->pType->pWeakRef == 0 means that the description is empty
|
// pRef->pType->pWeakRef == 0 means that the description is empty
|
||||||
if( pRef->pType && pRef->pType->pWeakRef )
|
if( pRef->pType && pRef->pType->pWeakRef )
|
||||||
{
|
{
|
||||||
@@ -2239,11 +2231,10 @@ extern "C" void typelib_typedescriptionreference_getByName(
|
|||||||
typelib_typedescriptionreference_release( *ppRet );
|
typelib_typedescriptionreference_release( *ppRet );
|
||||||
*ppRet = nullptr;
|
*ppRet = nullptr;
|
||||||
}
|
}
|
||||||
TypeDescriptor_Init_Impl &rInit = Init::get();
|
|
||||||
|
|
||||||
MutexGuard aGuard( rInit.getMutex() );
|
MutexGuard aGuard( gInit.getMutex() );
|
||||||
WeakMap_Impl::const_iterator aIt = rInit.maWeakMap.find( pName->buffer );
|
WeakMap_Impl::const_iterator aIt = gInit.maWeakMap.find( pName->buffer );
|
||||||
if( aIt == rInit.maWeakMap.end() )
|
if( aIt == gInit.maWeakMap.end() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sal_Int32 n = osl_atomic_increment( &(*aIt).second->nRefCount );
|
sal_Int32 n = osl_atomic_increment( &(*aIt).second->nRefCount );
|
||||||
@@ -2295,14 +2286,13 @@ extern "C" void SAL_CALL typelib_setCacheSize( sal_Int32 nNewSize )
|
|||||||
if (nNewSize < 0)
|
if (nNewSize < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
TypeDescriptor_Init_Impl &rInit = Init::get();
|
MutexGuard aGuard( gInit.getMutex() );
|
||||||
MutexGuard aGuard( rInit.getMutex() );
|
|
||||||
if (nNewSize < nCacheSize)
|
if (nNewSize < nCacheSize)
|
||||||
{
|
{
|
||||||
while (static_cast<sal_Int32>(rInit.maCache.size()) != nNewSize)
|
while (static_cast<sal_Int32>(gInit.maCache.size()) != nNewSize)
|
||||||
{
|
{
|
||||||
typelib_typedescription_release( rInit.maCache.front() );
|
typelib_typedescription_release( gInit.maCache.front() );
|
||||||
rInit.maCache.pop_front();
|
gInit.maCache.pop_front();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nCacheSize = nNewSize;
|
nCacheSize = nNewSize;
|
||||||
|
Reference in New Issue
Block a user