[Libreoffice-commits] core.git: 2 commits - connectivity/source oox/source package/source svl/source vcl/win

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Nov 5 12:27:29 UTC 2018


 connectivity/source/drivers/postgresql/pq_statics.cxx |   12 +----
 oox/source/drawingml/presetgeometrynames.cxx          |   30 +++----------
 package/source/xstor/oseekinstream.cxx                |   19 +-------
 svl/source/fsstor/oinputstreamcontainer.cxx           |   39 +++++-------------
 vcl/win/window/salframe.cxx                           |    3 +
 5 files changed, 29 insertions(+), 74 deletions(-)

New commits:
commit e07253e0262a11dc96a98598c55c43da16b9678a
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Sun Nov 4 20:31:58 2018 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Mon Nov 5 13:26:36 2018 +0100

    replace double-checked locking patterns with thread safe local statics
    
    Change-Id: I4ed97cc6d9f733292156d71551d5ce3af6071445
    Reviewed-on: https://gerrit.libreoffice.org/62858
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/connectivity/source/drivers/postgresql/pq_statics.cxx b/connectivity/source/drivers/postgresql/pq_statics.cxx
index 0bec73919687..100c16c070f4 100644
--- a/connectivity/source/drivers/postgresql/pq_statics.cxx
+++ b/connectivity/source/drivers/postgresql/pq_statics.cxx
@@ -108,12 +108,7 @@ static cppu::IPropertyArrayHelper * createPropertyArrayHelper(
 
 Statics & getStatics()
 {
-    static Statics * p;
-    if( ! p )
-    {
-        ::osl::MutexGuard guard( ::osl::Mutex::getGlobalMutex() );
-        if( ! p )
-        {
+    static Statics* p = []() {
             static Statics statics ;
             statics.SYSTEM_TABLE = "SYSTEM TABLE";
             statics.TABLE = "TABLE";
@@ -665,9 +660,8 @@ Statics & getStatics()
                         defTypeInfoMetaData[i].isAutoIncrement ) );
             }
 
-            p = &statics;
-        }
-    }
+            return &statics;
+    }();
     return *p;
 }
 
diff --git a/oox/source/drawingml/presetgeometrynames.cxx b/oox/source/drawingml/presetgeometrynames.cxx
index 4939cfcf0a3f..272094dd7ef6 100644
--- a/oox/source/drawingml/presetgeometrynames.cxx
+++ b/oox/source/drawingml/presetgeometrynames.cxx
@@ -20,13 +20,6 @@ namespace
 typedef std::unordered_map<const char*, const char*, rtl::CStringHash, rtl::CStringEqual>
     PresetGeometryHashMap;
 
-static PresetGeometryHashMap* pHashMap = nullptr;
-::osl::Mutex& getHashMapMutex()
-{
-    static osl::Mutex s_aHashMapProtection;
-    return s_aHashMapProtection;
-}
-
 struct PresetGeometryName
 {
     const char* pMsoName;
@@ -79,27 +72,20 @@ static const PresetGeometryName pPresetGeometryNameArray[]
 
 OUString PresetGeometryTypeNames::GetFontworkType(const OUString& rMsoType)
 {
-    if (!pHashMap)
-    { // init hash map
-        ::osl::MutexGuard aGuard(getHashMapMutex());
-        if (!pHashMap)
-        {
-            PresetGeometryHashMap* pH = new PresetGeometryHashMap;
-            const PresetGeometryName* pPtr = pPresetGeometryNameArray;
-            const PresetGeometryName* pEnd = pPtr + SAL_N_ELEMENTS(pPresetGeometryNameArray);
-            for (; pPtr < pEnd; pPtr++)
-                (*pH)[pPtr->pMsoName] = pPtr->pFontworkType;
-            pHashMap = pH;
-        }
-    }
+    static const PresetGeometryHashMap s_HashMap = []() {
+        PresetGeometryHashMap aH;
+        for (const auto& item : pPresetGeometryNameArray)
+            aH[item.pMsoName] = item.pFontworkType;
+        return aH;
+    }();
     const char* pRetValue = "";
     int i, nLen = rMsoType.getLength();
     std::unique_ptr<char[]> pBuf(new char[nLen + 1]);
     for (i = 0; i < nLen; i++)
         pBuf[i] = static_cast<char>(rMsoType[i]);
     pBuf[i] = 0;
-    PresetGeometryHashMap::const_iterator aHashIter(pHashMap->find(pBuf.get()));
-    if (aHashIter != pHashMap->end())
+    PresetGeometryHashMap::const_iterator aHashIter(s_HashMap.find(pBuf.get()));
+    if (aHashIter != s_HashMap.end())
         pRetValue = (*aHashIter).second;
 
     return OUString(pRetValue, strlen(pRetValue), RTL_TEXTENCODING_ASCII_US);
diff --git a/package/source/xstor/oseekinstream.cxx b/package/source/xstor/oseekinstream.cxx
index 34d6a5d8f480..d19d6a745ab1 100644
--- a/package/source/xstor/oseekinstream.cxx
+++ b/package/source/xstor/oseekinstream.cxx
@@ -53,23 +53,10 @@ OInputSeekStream::~OInputSeekStream()
 
 uno::Sequence< uno::Type > SAL_CALL OInputSeekStream::getTypes()
 {
-    static ::cppu::OTypeCollection* pTypeCollection = nullptr ;
+    static cppu::OTypeCollection aTypeCollection(cppu::UnoType<io::XSeekable>::get(),
+                                                   OInputCompStream::getTypes());
 
-    if ( pTypeCollection == nullptr )
-    {
-        ::osl::MutexGuard aGuard( m_xMutex->GetMutex() ) ;
-
-        if ( pTypeCollection == nullptr )
-        {
-            static ::cppu::OTypeCollection aTypeCollection(
-                    cppu::UnoType<io::XSeekable>::get(),
-                    OInputCompStream::getTypes() );
-
-            pTypeCollection = &aTypeCollection ;
-        }
-    }
-
-    return pTypeCollection->getTypes() ;
+    return aTypeCollection.getTypes();
 }
 
 uno::Any SAL_CALL OInputSeekStream::queryInterface( const uno::Type& rType )
diff --git a/svl/source/fsstor/oinputstreamcontainer.cxx b/svl/source/fsstor/oinputstreamcontainer.cxx
index 9b9899992119..b62aca14c9b2 100644
--- a/svl/source/fsstor/oinputstreamcontainer.cxx
+++ b/svl/source/fsstor/oinputstreamcontainer.cxx
@@ -39,36 +39,21 @@ OFSInputStreamContainer::~OFSInputStreamContainer()
 
 uno::Sequence< uno::Type > SAL_CALL OFSInputStreamContainer::getTypes()
 {
-    static ::cppu::OTypeCollection* pTypeCollection = nullptr ;
-
-    if ( pTypeCollection == nullptr )
+    if (m_bSeekable)
     {
-        ::osl::MutexGuard aGuard( m_aMutex ) ;
-
-        if ( pTypeCollection == nullptr )
-        {
-            if ( m_bSeekable )
-            {
-                static ::cppu::OTypeCollection aTypeCollection(
-                        cppu::UnoType<io::XStream>::get(),
-                        cppu::UnoType<io::XInputStream>::get(),
-                        cppu::UnoType<io::XSeekable>::get());
-
-                pTypeCollection = &aTypeCollection ;
-            }
-            else
-            {
-                static ::cppu::OTypeCollection aTypeCollection(
-                        cppu::UnoType<io::XStream>::get(),
-                        cppu::UnoType<io::XInputStream>::get());
-
-                pTypeCollection = &aTypeCollection ;
-            }
-        }
-    }
+        static cppu::OTypeCollection aTypeCollection(cppu::UnoType<io::XStream>::get(),
+                                                     cppu::UnoType<io::XInputStream>::get(),
+                                                     cppu::UnoType<io::XSeekable>::get());
 
-    return pTypeCollection->getTypes() ;
+        return aTypeCollection.getTypes();
+    }
+    else
+    {
+        static cppu::OTypeCollection aTypeCollection(cppu::UnoType<io::XStream>::get(),
+                                                     cppu::UnoType<io::XInputStream>::get());
 
+        return aTypeCollection.getTypes();
+    }
 }
 
 uno::Any SAL_CALL OFSInputStreamContainer::queryInterface( const uno::Type& rType )
commit 212ea275f21251903e449ba5a6b7c4fc2dc57642
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Mon Nov 5 09:02:56 2018 +0100
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Mon Nov 5 13:26:03 2018 +0100

    tdf#118573: Acquire solar mutex when calling Application::Reschedule
    
    Change-Id: I252973ad5902738c2bb684f6bb70bc4c46500bae
    Reviewed-on: https://gerrit.libreoffice.org/62873
    Reviewed-by: Jan-Marek Glogowski <glogow at fbihome.de>
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/vcl/win/window/salframe.cxx b/vcl/win/window/salframe.cxx
index 9829896763c7..068e1a3a19d7 100644
--- a/vcl/win/window/salframe.cxx
+++ b/vcl/win/window/salframe.cxx
@@ -5686,7 +5686,10 @@ static LRESULT CALLBACK SalFrameWndProc( HWND hWnd, UINT nMsg, WPARAM wParam, LP
                 // messages in the message queue and dispatch them before we return control to the system.
 
                 if ( nRet )
+                {
+                    SolarMutexGuard aGuard;
                     while ( Application::Reschedule( true ) );
+                }
             }
             else
             {


More information about the Libreoffice-commits mailing list