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

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Sat Jan 30 09:11:20 UTC 2021


 include/osl/mutex.hxx       |    3 +++
 sal/Library_sal.mk          |    1 +
 sal/osl/all/mutexshared.cxx |   20 ++++++++++++++++++++
 sal/osl/unx/mutex.cxx       |   26 --------------------------
 sal/osl/w32/dllentry.cxx    |    6 ------
 sal/osl/w32/gmutex.hxx      |   31 -------------------------------
 sal/osl/w32/mutex.cxx       |    6 ------
 7 files changed, 24 insertions(+), 69 deletions(-)

New commits:
commit c42f60e2b9a521005e1263e781c878e2598b44df
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Fri Jan 29 09:57:41 2021 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sat Jan 30 10:10:41 2021 +0100

    Simplify osl_getGlobalMutex to use function-local static
    
    Change-Id: I36df8be817d0f0cb75efa00b0b523f379f67d1d1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110126
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/include/osl/mutex.hxx b/include/osl/mutex.hxx
index f984f035ca40..84955b681143 100644
--- a/include/osl/mutex.hxx
+++ b/include/osl/mutex.hxx
@@ -89,6 +89,9 @@ namespace osl
     private:
         oslMutex mutex;
 
+        // access to the oslMutex
+        friend oslMutex* SAL_CALL ::osl_getGlobalMutex();
+
         /** The underlying oslMutex has no reference count.
 
         Since the underlying oslMutex is not a reference counted object, copy
diff --git a/sal/Library_sal.mk b/sal/Library_sal.mk
index ddbd13a37392..fbc02f26d6da 100644
--- a/sal/Library_sal.mk
+++ b/sal/Library_sal.mk
@@ -85,6 +85,7 @@ $(eval $(call gb_Library_add_exception_objects,sal,\
 	sal/osl/all/filepath \
 	sal/osl/all/loadmodulerelative \
 	sal/osl/all/log  \
+	sal/osl/all/mutexshared \
 	sal/osl/all/signalshared  \
 	sal/osl/all/utility \
 	sal/rtl/alloc_arena \
diff --git a/sal/osl/all/mutexshared.cxx b/sal/osl/all/mutexshared.cxx
new file mode 100644
index 000000000000..3de7f99303a8
--- /dev/null
+++ b/sal/osl/all/mutexshared.cxx
@@ -0,0 +1,20 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/config.h>
+
+#include <osl/mutex.hxx>
+
+oslMutex* SAL_CALL osl_getGlobalMutex()
+{
+    static osl::Mutex g_Mutex;
+    return &g_Mutex.mutex;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/sal/osl/unx/mutex.cxx b/sal/osl/unx/mutex.cxx
index 8cdc2a071376..1ca4958fd01d 100644
--- a/sal/osl/unx/mutex.cxx
+++ b/sal/osl/unx/mutex.cxx
@@ -160,30 +160,4 @@ sal_Bool SAL_CALL osl_releaseMutex(oslMutex pMutex)
     return false;
 }
 
-static oslMutexImpl globalMutexImpl;
-
-static void globalMutexInitImpl() {
-    pthread_mutexattr_t attr;
-    if (pthread_mutexattr_init(&attr) != 0 ||
-        pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) ||
-        pthread_mutex_init(&globalMutexImpl.mutex, &attr) != 0 ||
-        pthread_mutexattr_destroy(&attr) != 0)
-    {
-        abort();
-    }
-}
-
-oslMutex * SAL_CALL osl_getGlobalMutex()
-{
-    /* necessary to get a "oslMutex *" */
-    static oslMutex globalMutex = &globalMutexImpl;
-
-    static pthread_once_t once = PTHREAD_ONCE_INIT;
-    if (pthread_once(&once, &globalMutexInitImpl) != 0) {
-        abort();
-    }
-
-    return &globalMutex;
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/osl/w32/dllentry.cxx b/sal/osl/w32/dllentry.cxx
index 3dba6d0e0c9f..a36e6cda8840 100644
--- a/sal/osl/w32/dllentry.cxx
+++ b/sal/osl/w32/dllentry.cxx
@@ -32,7 +32,6 @@
 #include <osl/thread.h>
 
 #include "file_url.hxx"
-#include "gmutex.hxx"
 #include <rtllifecycle.h>
 
 #include "thread.hxx"
@@ -85,9 +84,6 @@ static BOOL WINAPI RawDllMain( HINSTANCE, DWORD fdwReason, LPVOID )
                 SetErrorMode( SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS );
 #endif
 
-                /* initialize global mutex */
-                g_Mutex = osl_createMutex();
-
                 g_dwTLSTextEncodingIndex = TlsAlloc();
 
                 //We disable floating point exceptions. This is the usual state at program startup
@@ -101,8 +97,6 @@ static BOOL WINAPI RawDllMain( HINSTANCE, DWORD fdwReason, LPVOID )
 
             TlsFree( g_dwTLSTextEncodingIndex );
 
-            osl_destroyMutex( g_Mutex );
-
             /*
 
             On a product build memory management finalization might
diff --git a/sal/osl/w32/gmutex.hxx b/sal/osl/w32/gmutex.hxx
deleted file mode 100644
index 013b4c178262..000000000000
--- a/sal/osl/w32/gmutex.hxx
+++ /dev/null
@@ -1,31 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#ifndef INCLUDED_SAL_OSL_W32_GMUTEX_HXX
-#define INCLUDED_SAL_OSL_W32_GMUTEX_HXX
-
-#include <sal/config.h>
-
-#include <osl/mutex.h>
-
-extern oslMutex g_Mutex;
-
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/sal/osl/w32/mutex.cxx b/sal/osl/w32/mutex.cxx
index 31a9117a8c68..7de4c41eeaaf 100644
--- a/sal/osl/w32/mutex.cxx
+++ b/sal/osl/w32/mutex.cxx
@@ -19,7 +19,6 @@
 
 #include <sal/config.h>
 
-#include "gmutex.hxx"
 #include "system.h"
 
 #include <osl/mutex.h>
@@ -86,9 +85,4 @@ sal_Bool SAL_CALL osl_releaseMutex(oslMutex Mutex)
     return true;
 }
 
-/* initialized in dllentry.c */
-oslMutex g_Mutex;
-
-oslMutex* SAL_CALL osl_getGlobalMutex(void) { return &g_Mutex; }
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list