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

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Sat Jan 30 21:15:23 UTC 2021


 cppu/source/threadpool/current.cxx |   49 ++++---------------------------------
 1 file changed, 6 insertions(+), 43 deletions(-)

New commits:
commit ef6a57ed4e8984bed06e2911b07436498710d80d
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Fri Jan 29 14:58:02 2021 +0100
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sat Jan 30 22:14:36 2021 +0100

    Don't use global mutex here for static initialization
    
    Change-Id: I3fa0cd7e31a8c89b5fb1eba7b36636e02a785df8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110140
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/cppu/source/threadpool/current.cxx b/cppu/source/threadpool/current.cxx
index 7dbfc9050488..6acad514cac7 100644
--- a/cppu/source/threadpool/current.cxx
+++ b/cppu/source/threadpool/current.cxx
@@ -81,47 +81,6 @@ static typelib_InterfaceTypeDescription * get_type_XCurrentContext()
     return s_type_XCurrentContext;
 }
 
-namespace {
-
-class ThreadKey
-{
-    bool     _bInit;
-    oslThreadKey _hThreadKey;
-    oslThreadKeyCallbackFunction _pCallback;
-
-public:
-    oslThreadKey getThreadKey()
-    {
-        if (! _bInit)
-        {
-            MutexGuard aGuard( Mutex::getGlobalMutex() );
-            if (! _bInit)
-            {
-                _hThreadKey = ::osl_createThreadKey( _pCallback );
-                _bInit = true;
-            }
-        }
-        return _hThreadKey;
-    }
-
-    explicit ThreadKey( oslThreadKeyCallbackFunction pCallback )
-        : _bInit(false)
-        , _hThreadKey(nullptr)
-        , _pCallback(pCallback)
-    {
-    }
-
-    ~ThreadKey()
-    {
-        if (_bInit)
-        {
-            ::osl_destroyThreadKey( _hThreadKey );
-        }
-    }
-};
-
-}
-
 extern "C" {
 
 static void delete_IdContainer( void * p )
@@ -149,8 +108,12 @@ static void delete_IdContainer( void * p )
 
 IdContainer * getIdContainer()
 {
-    static ThreadKey s_key( delete_IdContainer );
-    oslThreadKey aKey = s_key.getThreadKey();
+    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)


More information about the Libreoffice-commits mailing list