[Libreoffice-commits] core.git: cppu/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Wed Aug 4 14:06:41 UTC 2021


 cppu/source/threadpool/current.cxx |   52 ++++++++++++-------------------------
 cppu/source/threadpool/current.hxx |    5 ++-
 2 files changed, 21 insertions(+), 36 deletions(-)

New commits:
commit 5b6f8991d88e75f11811de502b4285aa23cd0d4e
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Aug 4 14:29:12 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Aug 4 16:06:07 2021 +0200

    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 at collabora.co.uk>

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();


More information about the Libreoffice-commits mailing list