summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-01-29 13:47:35 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2021-01-30 07:33:45 +0100
commitab91f93cfb0e16462a7979b12e3e3de843527548 (patch)
tree2510b1dd44533b90e4a291aed04e1f9254fc79ba /sal
parent6e0fa7d4c7b45c98418c289d1d4715eb9eb133f7 (diff)
Use function-local static Mutex here instead of global CRITICAL_SECTION
Our Mutes uses sritical sections on Windows anyway Change-Id: Ieb4a8431700215758aaf84dc7a8c2db4b4030804 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110158 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/w32/dllentry.cxx2
-rw-r--r--sal/osl/w32/thread.cxx19
-rw-r--r--sal/osl/w32/thread.hxx2
3 files changed, 10 insertions, 13 deletions
diff --git a/sal/osl/w32/dllentry.cxx b/sal/osl/w32/dllentry.cxx
index 06857df6bbc5..3dba6d0e0c9f 100644
--- a/sal/osl/w32/dllentry.cxx
+++ b/sal/osl/w32/dllentry.cxx
@@ -89,7 +89,6 @@ static BOOL WINAPI RawDllMain( HINSTANCE, DWORD fdwReason, LPVOID )
g_Mutex = osl_createMutex();
g_dwTLSTextEncodingIndex = TlsAlloc();
- InitializeCriticalSection( &g_ThreadKeyListCS );
//We disable floating point exceptions. This is the usual state at program startup
//but on Windows 98 and ME this is not always the case.
@@ -101,7 +100,6 @@ static BOOL WINAPI RawDllMain( HINSTANCE, DWORD fdwReason, LPVOID )
WSACleanup( );
TlsFree( g_dwTLSTextEncodingIndex );
- DeleteCriticalSection( &g_ThreadKeyListCS );
osl_destroyMutex( g_Mutex );
diff --git a/sal/osl/w32/thread.cxx b/sal/osl/w32/thread.cxx
index 19479de033cd..f11c17668371 100644
--- a/sal/osl/w32/thread.cxx
+++ b/sal/osl/w32/thread.cxx
@@ -21,6 +21,7 @@
#include "thread.hxx"
#include <osl/diagnose.h>
+#include <osl/mutex.hxx>
#include <osl/thread.h>
#include <rtl/alloc.h>
#include <osl/time.h>
@@ -391,16 +392,20 @@ typedef struct TLS_
struct TLS_ *pNext, *pPrev;
} TLS, *PTLS;
+PTLS g_pThreadKeyList = nullptr;
+osl::Mutex& getThreadKeyListMutex()
+{
+ static osl::Mutex g_ThreadKeyListMutex;
+ return g_ThreadKeyListMutex;
}
-static PTLS g_pThreadKeyList = nullptr;
-CRITICAL_SECTION g_ThreadKeyListCS;
+}
static void AddKeyToList( PTLS pTls )
{
if ( pTls )
{
- EnterCriticalSection( &g_ThreadKeyListCS );
+ osl::MutexGuard aGuard(getThreadKeyListMutex());
pTls->pNext = g_pThreadKeyList;
pTls->pPrev = nullptr;
@@ -409,8 +414,6 @@ static void AddKeyToList( PTLS pTls )
g_pThreadKeyList->pPrev = pTls;
g_pThreadKeyList = pTls;
-
- LeaveCriticalSection( &g_ThreadKeyListCS );
}
}
@@ -418,7 +421,7 @@ static void RemoveKeyFromList( PTLS pTls )
{
if ( pTls )
{
- EnterCriticalSection( &g_ThreadKeyListCS );
+ osl::MutexGuard aGuard(getThreadKeyListMutex());
if ( pTls->pPrev )
pTls->pPrev->pNext = pTls->pNext;
else
@@ -429,7 +432,6 @@ static void RemoveKeyFromList( PTLS pTls )
if ( pTls->pNext )
pTls->pNext->pPrev = pTls->pPrev;
- LeaveCriticalSection( &g_ThreadKeyListCS );
}
}
@@ -437,7 +439,7 @@ void osl_callThreadKeyCallbackOnThreadDetach(void)
{
PTLS pTls;
- EnterCriticalSection( &g_ThreadKeyListCS );
+ osl::MutexGuard aGuard(getThreadKeyListMutex());
pTls = g_pThreadKeyList;
while ( pTls )
{
@@ -451,7 +453,6 @@ void osl_callThreadKeyCallbackOnThreadDetach(void)
pTls = pTls->pNext;
}
- LeaveCriticalSection( &g_ThreadKeyListCS );
}
oslThreadKey SAL_CALL osl_createThreadKey(oslThreadKeyCallbackFunction pCallback)
diff --git a/sal/osl/w32/thread.hxx b/sal/osl/w32/thread.hxx
index c7455aab8b0c..03491a8341c1 100644
--- a/sal/osl/w32/thread.hxx
+++ b/sal/osl/w32/thread.hxx
@@ -18,8 +18,6 @@ void osl_callThreadKeyCallbackOnThreadDetach(void);
extern DWORD g_dwTLSTextEncodingIndex;
-extern CRITICAL_SECTION g_ThreadKeyListCS;
-
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */