diff options
author | Caolán McNamara <caolanm@redhat.com> | 2021-08-06 09:59:52 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2021-08-06 12:14:58 +0200 |
commit | 413b80ed1a9d29f394d0746106f5698e65fe23dc (patch) | |
tree | f48c3794421dcf4be10c152427b716155733cbfc /cppu/source/threadpool/threadident.cxx | |
parent | 6189a79cd3a589a403415d288389780167133797 (diff) |
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>
Diffstat (limited to 'cppu/source/threadpool/threadident.cxx')
-rw-r--r-- | cppu/source/threadpool/threadident.cxx | 61 |
1 files changed, 28 insertions, 33 deletions
diff --git a/cppu/source/threadpool/threadident.cxx b/cppu/source/threadpool/threadident.cxx index 544acc7af520..16b7c0b2700a 100644 --- a/cppu/source/threadpool/threadident.cxx +++ b/cppu/source/threadpool/threadident.cxx @@ -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 { |