[Libreoffice-commits] core.git: sfx2/source svtools/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Sun Nov 4 17:03:54 UTC 2018


 sfx2/source/dialog/backingcomp.cxx         |   51 ++++++++++-------------------
 svtools/source/hatchwindow/hatchwindow.cxx |   19 +---------
 2 files changed, 22 insertions(+), 48 deletions(-)

New commits:
commit 41707751a60a8044d49896b0e62d9fe0e997af85
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Sun Nov 4 03:12:18 2018 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sun Nov 4 18:03:09 2018 +0100

    tdf#120703 PVS: V547 Get rid of mutexes to initialize function-local statics
    
    Also fix an infinite recursion when VCLXHatchWindow::getTypes() called
    VCLXHatchWindow::getTypes() when initializing its static.
    
    Change-Id: I19b8b1e1b367ddf636f905fb141c7690e21f67f8
    Reviewed-on: https://gerrit.libreoffice.org/62825
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
    Tested-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/sfx2/source/dialog/backingcomp.cxx b/sfx2/source/dialog/backingcomp.cxx
index d6e36f75476b..015ce31b71a7 100644
--- a/sfx2/source/dialog/backingcomp.cxx
+++ b/sfx2/source/dialog/backingcomp.cxx
@@ -235,38 +235,25 @@ void SAL_CALL BackingComp::release()
 
 css::uno::Sequence< css::uno::Type > SAL_CALL BackingComp::getTypes()
 {
-    static ::cppu::OTypeCollection* pTypeCollection = nullptr;
-    if (!pTypeCollection)
-    {
-        /* GLOBAL SAFE { */
-        ::osl::MutexGuard aGlobalLock(m_aTypeProviderMutex);
-        // Control these pointer again ... it can be, that another instance will be faster then this one!
-        if (!pTypeCollection)
-        {
-            /* LOCAL SAFE { */
-            SolarMutexGuard aGuard;
-            css::uno::Reference< css::lang::XTypeProvider > xProvider(m_xWindow, css::uno::UNO_QUERY);
-
-            css::uno::Sequence< css::uno::Type > lWindowTypes;
-            if (xProvider.is())
-                lWindowTypes = xProvider->getTypes();
-
-            static ::cppu::OTypeCollection aTypeCollection(
-                    cppu::UnoType<css::lang::XInitialization>::get(),
-                    cppu::UnoType<css::lang::XTypeProvider>::get(),
-                    cppu::UnoType<css::lang::XServiceInfo>::get(),
-                    cppu::UnoType<css::frame::XController>::get(),
-                    cppu::UnoType<css::lang::XComponent>::get(),
-                    cppu::UnoType<css::frame::XDispatchProvider>::get(),
-                    cppu::UnoType<css::frame::XDispatch>::get(),
-                    lWindowTypes);
-
-            pTypeCollection = &aTypeCollection;
-            /* } LOCAL SAFE */
-        }
-        /* } GLOBAL SAFE */
-    }
-    return pTypeCollection->getTypes();
+    static cppu::OTypeCollection aTypeCollection = [this]() {
+        SolarMutexGuard aGuard;
+        css::uno::Reference<css::lang::XTypeProvider> xProvider(m_xWindow, css::uno::UNO_QUERY);
+
+        css::uno::Sequence<css::uno::Type> lWindowTypes;
+        if (xProvider.is())
+            lWindowTypes = xProvider->getTypes();
+
+        return cppu::OTypeCollection(
+            cppu::UnoType<css::lang::XInitialization>::get(),
+            cppu::UnoType<css::lang::XTypeProvider>::get(),
+            cppu::UnoType<css::lang::XServiceInfo>::get(),
+            cppu::UnoType<css::frame::XController>::get(),
+            cppu::UnoType<css::lang::XComponent>::get(),
+            cppu::UnoType<css::frame::XDispatchProvider>::get(),
+            cppu::UnoType<css::frame::XDispatch>::get(), lWindowTypes);
+    }();
+
+    return aTypeCollection.getTypes();
 }
 
 
diff --git a/svtools/source/hatchwindow/hatchwindow.cxx b/svtools/source/hatchwindow/hatchwindow.cxx
index 0e8b4b964182..02a0c8a09780 100644
--- a/svtools/source/hatchwindow/hatchwindow.cxx
+++ b/svtools/source/hatchwindow/hatchwindow.cxx
@@ -139,23 +139,10 @@ void SAL_CALL VCLXHatchWindow::release()
 
 uno::Sequence< uno::Type > SAL_CALL VCLXHatchWindow::getTypes()
 {
-    static ::cppu::OTypeCollection* pTypeCollection = nullptr ;
+    static cppu::OTypeCollection aTypeCollection(cppu::UnoType<embed::XHatchWindow>::get(),
+                                                 VCLXWindow::getTypes());
 
-    if ( pTypeCollection == nullptr )
-    {
-        ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ) ;
-
-        if ( pTypeCollection == nullptr )
-        {
-            static ::cppu::OTypeCollection aTypeCollection(
-                    cppu::UnoType<embed::XHatchWindow>::get(),
-                    VCLXHatchWindow::getTypes() );
-
-            pTypeCollection = &aTypeCollection ;
-        }
-    }
-
-    return pTypeCollection->getTypes() ;
+    return aTypeCollection.getTypes();
 }
 
 uno::Sequence< sal_Int8 > SAL_CALL VCLXHatchWindow::getImplementationId()


More information about the Libreoffice-commits mailing list