diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-01-29 14:58:02 +0100 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-01-30 22:14:36 +0100 |
commit | ef6a57ed4e8984bed06e2911b07436498710d80d (patch) | |
tree | 256e9b9bbac0a8585271029b5e329cbdb5412de0 /cppu | |
parent | d77a644a1a4af8b2c7eb3b524ba6ac24d58b67fb (diff) |
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@collabora.com>
Diffstat (limited to 'cppu')
-rw-r--r-- | cppu/source/threadpool/current.cxx | 49 |
1 files changed, 6 insertions, 43 deletions
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) |