return a reference instead of a pointer
and remove redundant nullptr OSL_ENSURE check Change-Id: I19e202c3786386ed6f094504a0e1eb6928aa423a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120105 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
This commit is contained in:
@@ -106,33 +106,31 @@ IdContainer::~IdContainer()
|
||||
}
|
||||
}
|
||||
|
||||
IdContainer * getIdContainer()
|
||||
IdContainer& getIdContainer()
|
||||
{
|
||||
static thread_local IdContainer aId;
|
||||
return &aId;
|
||||
return aId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
extern "C" sal_Bool SAL_CALL uno_setCurrentContext(
|
||||
void * pCurrentContext,
|
||||
rtl_uString * pEnvTypeName, void * pEnvContext )
|
||||
SAL_THROW_EXTERN_C()
|
||||
{
|
||||
IdContainer * pId = getIdContainer();
|
||||
OSL_ASSERT( pId );
|
||||
IdContainer& id = getIdContainer();
|
||||
|
||||
// free old one
|
||||
if (pId->pCurrentContext)
|
||||
if (id.pCurrentContext)
|
||||
{
|
||||
(*pId->pCurrentContextEnv->releaseInterface)(
|
||||
pId->pCurrentContextEnv, pId->pCurrentContext );
|
||||
(*pId->pCurrentContextEnv->aBase.release)(
|
||||
&pId->pCurrentContextEnv->aBase );
|
||||
pId->pCurrentContextEnv = nullptr;
|
||||
(*id.pCurrentContextEnv->releaseInterface)(
|
||||
id.pCurrentContextEnv, id.pCurrentContext );
|
||||
(*id.pCurrentContextEnv->aBase.release)(
|
||||
&id.pCurrentContextEnv->aBase );
|
||||
id.pCurrentContextEnv = nullptr;
|
||||
|
||||
pId->pCurrentContext = nullptr;
|
||||
id.pCurrentContext = nullptr;
|
||||
}
|
||||
|
||||
if (pCurrentContext)
|
||||
@@ -144,10 +142,10 @@ extern "C" sal_Bool SAL_CALL uno_setCurrentContext(
|
||||
{
|
||||
if (pEnv->pExtEnv)
|
||||
{
|
||||
pId->pCurrentContextEnv = pEnv->pExtEnv;
|
||||
(*pId->pCurrentContextEnv->acquireInterface)(
|
||||
pId->pCurrentContextEnv, pCurrentContext );
|
||||
pId->pCurrentContext = pCurrentContext;
|
||||
id.pCurrentContextEnv = pEnv->pExtEnv;
|
||||
(*id.pCurrentContextEnv->acquireInterface)(
|
||||
id.pCurrentContextEnv, pCurrentContext );
|
||||
id.pCurrentContext = pCurrentContext;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -167,8 +165,7 @@ extern "C" sal_Bool SAL_CALL uno_getCurrentContext(
|
||||
void ** ppCurrentContext, rtl_uString * pEnvTypeName, void * pEnvContext )
|
||||
SAL_THROW_EXTERN_C()
|
||||
{
|
||||
IdContainer * pId = getIdContainer();
|
||||
OSL_ASSERT( pId );
|
||||
IdContainer& id = getIdContainer();
|
||||
|
||||
Environment target_env;
|
||||
|
||||
@@ -189,7 +186,7 @@ extern "C" sal_Bool SAL_CALL uno_getCurrentContext(
|
||||
}
|
||||
|
||||
// case: null-ref
|
||||
if (nullptr == pId->pCurrentContext)
|
||||
if (nullptr == id.pCurrentContext)
|
||||
return true;
|
||||
|
||||
if (! target_env.is())
|
||||
@@ -200,12 +197,12 @@ extern "C" sal_Bool SAL_CALL uno_getCurrentContext(
|
||||
return false;
|
||||
}
|
||||
|
||||
Mapping mapping(&pId->pCurrentContextEnv->aBase, target_env.get());
|
||||
Mapping mapping(&id.pCurrentContextEnv->aBase, target_env.get());
|
||||
OSL_ASSERT( mapping.is() );
|
||||
if (! mapping.is())
|
||||
return false;
|
||||
|
||||
mapping.mapInterface(ppCurrentContext, pId->pCurrentContext, ::cppu::get_type_XCurrentContext() );
|
||||
mapping.mapInterface(ppCurrentContext, id.pCurrentContext, ::cppu::get_type_XCurrentContext());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -41,7 +41,7 @@ struct IdContainer
|
||||
~IdContainer();
|
||||
};
|
||||
|
||||
IdContainer * getIdContainer();
|
||||
IdContainer& getIdContainer();
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
@@ -27,12 +27,10 @@
|
||||
|
||||
#include "current.hxx"
|
||||
|
||||
|
||||
using namespace ::std;
|
||||
using namespace ::osl;
|
||||
using namespace ::cppu;
|
||||
|
||||
|
||||
static void createLocalId( sal_Sequence **ppThreadId )
|
||||
{
|
||||
rtl_byte_sequence_constructNoDefault( ppThreadId , 4 + 16 );
|
||||
@@ -44,74 +42,71 @@ static void createLocalId( sal_Sequence **ppThreadId )
|
||||
rtl_getGlobalProcessId( reinterpret_cast<sal_uInt8 *>(&(*ppThreadId)->elements[4]) );
|
||||
}
|
||||
|
||||
|
||||
extern "C" void SAL_CALL
|
||||
uno_getIdOfCurrentThread( sal_Sequence **ppThreadId )
|
||||
SAL_THROW_EXTERN_C()
|
||||
{
|
||||
IdContainer * p = getIdContainer();
|
||||
if( ! p->bInit )
|
||||
IdContainer& id = getIdContainer();
|
||||
if (!id.bInit)
|
||||
{
|
||||
// first time, that the thread enters the bridge
|
||||
createLocalId( ppThreadId );
|
||||
|
||||
// TODO
|
||||
// note : this is a leak !
|
||||
p->pLocalThreadId = *ppThreadId;
|
||||
p->pCurrentId = *ppThreadId;
|
||||
p->nRefCountOfCurrentId = 1;
|
||||
rtl_byte_sequence_acquire( p->pLocalThreadId );
|
||||
rtl_byte_sequence_acquire( p->pCurrentId );
|
||||
p->bInit = true;
|
||||
id.pLocalThreadId = *ppThreadId;
|
||||
id.pCurrentId = *ppThreadId;
|
||||
id.nRefCountOfCurrentId = 1;
|
||||
rtl_byte_sequence_acquire( id.pLocalThreadId );
|
||||
rtl_byte_sequence_acquire( id.pCurrentId );
|
||||
id.bInit = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
p->nRefCountOfCurrentId ++;
|
||||
id.nRefCountOfCurrentId ++;
|
||||
if( *ppThreadId )
|
||||
{
|
||||
rtl_byte_sequence_release( *ppThreadId );
|
||||
}
|
||||
*ppThreadId = p->pCurrentId;
|
||||
*ppThreadId = id.pCurrentId;
|
||||
rtl_byte_sequence_acquire( *ppThreadId );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extern "C" void SAL_CALL uno_releaseIdFromCurrentThread()
|
||||
SAL_THROW_EXTERN_C()
|
||||
{
|
||||
IdContainer *p = getIdContainer();
|
||||
OSL_ASSERT( p );
|
||||
OSL_ASSERT( p->bInit );
|
||||
OSL_ASSERT( p->nRefCountOfCurrentId );
|
||||
IdContainer& id = getIdContainer();
|
||||
OSL_ASSERT( id.bInit );
|
||||
OSL_ASSERT( id.nRefCountOfCurrentId );
|
||||
|
||||
p->nRefCountOfCurrentId --;
|
||||
if( ! p->nRefCountOfCurrentId && (p->pLocalThreadId != p->pCurrentId) )
|
||||
id.nRefCountOfCurrentId --;
|
||||
if( ! id.nRefCountOfCurrentId && (id.pLocalThreadId != id.pCurrentId) )
|
||||
{
|
||||
rtl_byte_sequence_assign( &(p->pCurrentId) , p->pLocalThreadId );
|
||||
rtl_byte_sequence_assign( &(id.pCurrentId) , id.pLocalThreadId );
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" sal_Bool SAL_CALL uno_bindIdToCurrentThread( sal_Sequence *pThreadId )
|
||||
SAL_THROW_EXTERN_C()
|
||||
{
|
||||
IdContainer *p = getIdContainer();
|
||||
if( ! p->bInit )
|
||||
IdContainer& id = getIdContainer();
|
||||
if (!id.bInit)
|
||||
{
|
||||
p->pLocalThreadId = nullptr;
|
||||
createLocalId( &(p->pLocalThreadId) );
|
||||
p->nRefCountOfCurrentId = 1;
|
||||
p->pCurrentId = pThreadId;
|
||||
rtl_byte_sequence_acquire( p->pCurrentId );
|
||||
p->bInit = true;
|
||||
id.pLocalThreadId = nullptr;
|
||||
createLocalId( &(id.pLocalThreadId) );
|
||||
id.nRefCountOfCurrentId = 1;
|
||||
id.pCurrentId = pThreadId;
|
||||
rtl_byte_sequence_acquire(id.pCurrentId);
|
||||
id.bInit = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
OSL_ASSERT( 0 == p->nRefCountOfCurrentId );
|
||||
if( 0 == p->nRefCountOfCurrentId )
|
||||
OSL_ASSERT( 0 == id.nRefCountOfCurrentId );
|
||||
if( 0 == id.nRefCountOfCurrentId )
|
||||
{
|
||||
rtl_byte_sequence_assign(&( p->pCurrentId ), pThreadId );
|
||||
p->nRefCountOfCurrentId ++;
|
||||
rtl_byte_sequence_assign(&( id.pCurrentId ), pThreadId );
|
||||
id.nRefCountOfCurrentId ++;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user