diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-08-04 14:29:12 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-08-04 16:06:07 +0200 |
commit | 5b6f8991d88e75f11811de502b4285aa23cd0d4e (patch) | |
tree | 8d2b8f1f8c48adc94d1cff4b7a54b300af3416b5 | |
parent | f234fe77a0070927b8ae2ba3309f63aa718624f5 (diff) |
osl_createThreadKey->thread_local in IdContainer
Change-Id: I5989610bd49597259d387b81dd7e8c63738255a6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120000
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | cppu/source/threadpool/current.cxx | 52 | ||||
-rw-r--r-- | cppu/source/threadpool/current.hxx | 5 |
2 files changed, 21 insertions, 36 deletions
diff --git a/cppu/source/threadpool/current.cxx b/cppu/source/threadpool/current.cxx index 6acad514cac7..64b9923286c2 100644 --- a/cppu/source/threadpool/current.cxx +++ b/cppu/source/threadpool/current.cxx @@ -20,7 +20,6 @@ #include <sal/config.h> #include <rtl/byteseq.h> -#include <osl/thread.h> #include <osl/mutex.hxx> #include <uno/current_context.h> @@ -81,50 +80,33 @@ static typelib_InterfaceTypeDescription * get_type_XCurrentContext() return s_type_XCurrentContext; } -extern "C" { - -static void delete_IdContainer( void * p ) +IdContainer::IdContainer() { - if (!p) - return; + pCurrentContext = nullptr; + pCurrentContextEnv = nullptr; + bInit = false; +} - IdContainer * pId = static_cast< IdContainer * >( p ); - if (pId->pCurrentContext) +IdContainer::~IdContainer() +{ + if (pCurrentContext) { - (*pId->pCurrentContextEnv->releaseInterface)( - pId->pCurrentContextEnv, pId->pCurrentContext ); - (*pId->pCurrentContextEnv->aBase.release)( - &pId->pCurrentContextEnv->aBase ); + (*pCurrentContextEnv->releaseInterface)( + pCurrentContextEnv, pCurrentContext ); + (*pCurrentContextEnv->aBase.release)( + &pCurrentContextEnv->aBase ); } - if (pId->bInit) + if (bInit) { - ::rtl_byte_sequence_release( pId->pLocalThreadId ); - ::rtl_byte_sequence_release( pId->pCurrentId ); + ::rtl_byte_sequence_release( pLocalThreadId ); + ::rtl_byte_sequence_release( pCurrentId ); } - delete pId; -} - } IdContainer * getIdContainer() { - struct ThreadKey - { - oslThreadKey _hThreadKey; - ~ThreadKey() { osl_destroyThreadKey(_hThreadKey); } - } static const s_key{ osl_createThreadKey(delete_IdContainer) }; - oslThreadKey aKey = s_key._hThreadKey; - - IdContainer * pId = static_cast< IdContainer * >( ::osl_getThreadKeyData( aKey ) ); - if (! pId) - { - pId = new IdContainer; - pId->pCurrentContext = nullptr; - pId->pCurrentContextEnv = nullptr; - pId->bInit = false; - ::osl_setThreadKeyData( aKey, pId ); - } - return pId; + static thread_local IdContainer aId; + return &aId; } } diff --git a/cppu/source/threadpool/current.hxx b/cppu/source/threadpool/current.hxx index 43eb809f9bff..8ab4e3acf43a 100644 --- a/cppu/source/threadpool/current.hxx +++ b/cppu/source/threadpool/current.hxx @@ -32,10 +32,13 @@ struct IdContainer void * pCurrentContext; _uno_ExtEnvironment * pCurrentContextEnv; - bool bInit; + bool bInit; sal_Sequence * pLocalThreadId; sal_Int32 nRefCountOfCurrentId; sal_Sequence * pCurrentId; + + IdContainer(); + ~IdContainer(); }; IdContainer * getIdContainer(); |