[Libreoffice-commits] core.git: sal/osl

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Sat Jan 30 06:34:29 UTC 2021


 sal/osl/w32/dllentry.cxx |    2 --
 sal/osl/w32/thread.cxx   |   19 ++++++++++---------
 sal/osl/w32/thread.hxx   |    2 --
 3 files changed, 10 insertions(+), 13 deletions(-)

New commits:
commit ab91f93cfb0e16462a7979b12e3e3de843527548
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Fri Jan 29 13:47:35 2021 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sat Jan 30 07:33:45 2021 +0100

    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 at collabora.com>

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: */


More information about the Libreoffice-commits mailing list