chart2/source/inc/Axis.hxx                   |    3 +++
 chart2/source/inc/DataSeries.hxx             |    3 +++
 chart2/source/inc/FormattedString.hxx        |    3 +++
 chart2/source/inc/Legend.hxx                 |    3 +++
 chart2/source/model/main/Axis.cxx            |    6 ++++++
 chart2/source/model/main/DataSeries.cxx      |    7 +++++--
 chart2/source/model/main/FormattedString.cxx |   15 +++++++++++----
 chart2/source/model/main/Legend.cxx          |    7 +++++++
 chart2/source/view/main/ChartItemPool.cxx    |   17 +++++++++++++++++
 sw/source/uibase/uno/unodoc.cxx              |    2 +-
 vcl/source/font/fontcache.cxx                |    4 ++++
 11 files changed, 63 insertions(+), 7 deletions(-)

New commits:
commit a2e78d06df22e99f2dc82ee3245ddc4c5de56acf
Author:     Noel Grandin <[email protected]>
AuthorDate: Wed Mar 29 11:43:14 2023 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Wed Mar 29 11:35:24 2023 +0000

    fix concurrent access to fontcache
    
    Every now and then I see a crash in fontcache code.
    Add some DBG_SOLARMUTEX calls there, which spots a few issues.
    
    (*) In writer, SwDLL needs to be under the SolarMutex during
    init, and we can just move a method call to fix that.
    
    (*) in chart2, life is more complicated. Various of the static
    defaults we build want to call OutputDevice::getFontInstance.
    We can't just stick a SolarMutex somewhere in the call chain,
    because those maps are built on-demand, and then we end up
    with ABBA deadlocks between the SolarMutex and the mutex
    in the cppu::PropertySetHelper.
    So I picked a spot that is init'ed early on in chart2,
    and force the init of all the troublesome tables there.
    
    Change-Id: I832978bea35fd5fa681d144b8beff1af13ef3341
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149648
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/chart2/source/inc/Axis.hxx b/chart2/source/inc/Axis.hxx
index 8329ac7365f9..902a67487cf5 100644
--- a/chart2/source/inc/Axis.hxx
+++ b/chart2/source/inc/Axis.hxx
@@ -28,6 +28,7 @@
 #include <com/sun/star/util/XCloneable.hpp>
 #include "ModifyListenerHelper.hxx"
 #include "charttoolsdllapi.hxx"
+#include "PropertyHelper.hxx"
 
 namespace chart
 {
@@ -137,6 +138,8 @@ private:
     rtl::Reference< ::chart::Title >          m_xTitle;
 };
 
+OOO_DLLPUBLIC_CHARTTOOLS const ::chart::tPropertyValueMap &  
StaticAxisDefaults();
+
 } //  namespace chart
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/inc/DataSeries.hxx b/chart2/source/inc/DataSeries.hxx
index 86405c19ac8e..03325a463a12 100644
--- a/chart2/source/inc/DataSeries.hxx
+++ b/chart2/source/inc/DataSeries.hxx
@@ -30,6 +30,7 @@
 #include <cppuhelper/implbase.hxx>
 #include <comphelper/uno3.hxx>
 #include "ModifyListenerHelper.hxx"
+#include "PropertyHelper.hxx"
 
 // STL
 #include <vector>
@@ -181,6 +182,8 @@ private:
     rtl::Reference<ModifyEventForwarder> m_xModifyEventForwarder;
 };
 
+OOO_DLLPUBLIC_CHARTTOOLS const tPropertyValueMap & StaticDataSeriesDefaults();
+
 }  // namespace chart
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/inc/FormattedString.hxx 
b/chart2/source/inc/FormattedString.hxx
index d438845c7f06..23c81454facf 100644
--- a/chart2/source/inc/FormattedString.hxx
+++ b/chart2/source/inc/FormattedString.hxx
@@ -25,6 +25,7 @@
 #include <com/sun/star/chart2/XDataPointCustomLabelField.hpp>
 #include <com/sun/star/util/XCloneable.hpp>
 #include "ModifyListenerHelper.hxx"
+#include "PropertyHelper.hxx"
 
 namespace chart
 {
@@ -134,6 +135,8 @@ private:
     rtl::Reference<ModifyEventForwarder> m_xModifyEventForwarder;
 };
 
+OOO_DLLPUBLIC_CHARTTOOLS const ::chart::tPropertyValueMap & 
StaticFormattedStringDefaults();
+
 } //  namespace chart
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/inc/Legend.hxx b/chart2/source/inc/Legend.hxx
index c0aa9326dd22..9caa0c7b06bb 100644
--- a/chart2/source/inc/Legend.hxx
+++ b/chart2/source/inc/Legend.hxx
@@ -26,6 +26,7 @@
 #include <com/sun/star/util/XCloneable.hpp>
 #include "ModifyListenerHelper.hxx"
 #include "charttoolsdllapi.hxx"
+#include "PropertyHelper.hxx"
 
 namespace chart
 {
@@ -98,6 +99,8 @@ private:
     rtl::Reference<ModifyEventForwarder> m_xModifyEventForwarder;
 };
 
+OOO_DLLPUBLIC_CHARTTOOLS const ::chart::tPropertyValueMap& 
StaticLegendDefaults();
+
 } //  namespace chart
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/model/main/Axis.cxx 
b/chart2/source/model/main/Axis.cxx
index 6ee948968369..99e20fbc86fb 100644
--- a/chart2/source/model/main/Axis.cxx
+++ b/chart2/source/model/main/Axis.cxx
@@ -205,7 +205,10 @@ void lcl_AddPropertiesToVector(
                   | beans::PropertyAttribute::MAYBEVOID );
 
 }
+} // namespace
 
+namespace chart
+{
 const ::chart::tPropertyValueMap &  StaticAxisDefaults()
 {
     static ::chart::tPropertyValueMap aStaticDefaults = []()
@@ -239,7 +242,10 @@ const ::chart::tPropertyValueMap &  StaticAxisDefaults()
         }();
     return aStaticDefaults;
 };
+} // namespace chart
 
+namespace
+{
 ::cppu::OPropertyArrayHelper& StaticAxisInfoHelper()
 {
     static ::cppu::OPropertyArrayHelper aPropHelper = []()
diff --git a/chart2/source/model/main/DataSeries.cxx 
b/chart2/source/model/main/DataSeries.cxx
index 6d224d6a39de..9f863f888dd0 100644
--- a/chart2/source/model/main/DataSeries.cxx
+++ b/chart2/source/model/main/DataSeries.cxx
@@ -46,9 +46,8 @@ using ::com::sun::star::uno::Sequence;
 using ::com::sun::star::uno::Reference;
 using ::osl::MutexGuard;
 
-namespace
+namespace chart
 {
-
 const ::chart::tPropertyValueMap & StaticDataSeriesDefaults()
 {
     static const ::chart::tPropertyValueMap aStaticDefaults = []()
@@ -64,6 +63,10 @@ const ::chart::tPropertyValueMap & StaticDataSeriesDefaults()
         }();
     return aStaticDefaults;
 };
+} // namespace chart
+
+namespace
+{
 
 ::cppu::OPropertyArrayHelper& StaticDataSeriesInfoHelper()
 {
diff --git a/chart2/source/model/main/FormattedString.cxx 
b/chart2/source/model/main/FormattedString.cxx
index 5da70943ded5..dbd5876b978a 100644
--- a/chart2/source/model/main/FormattedString.cxx
+++ b/chart2/source/model/main/FormattedString.cxx
@@ -32,15 +32,22 @@ using ::com::sun::star::beans::Property;
 using ::com::sun::star::uno::Sequence;
 using ::osl::MutexGuard;
 
-namespace
+namespace chart
 {
-
 const ::chart::tPropertyValueMap & StaticFormattedStringDefaults()
 {
-    static ::chart::tPropertyValueMap aStaticDefaults;
-    ::chart::CharacterProperties::AddDefaultsToMap( aStaticDefaults );
+    static ::chart::tPropertyValueMap aStaticDefaults = []
+        {
+            ::chart::tPropertyValueMap aMap;
+            ::chart::CharacterProperties::AddDefaultsToMap( aMap );
+            return aMap;
+        }();
     return aStaticDefaults;
 };
+} // namespace chart
+
+namespace
+{
 
 ::cppu::OPropertyArrayHelper& StaticFormattedStringInfoHelper()
 {
diff --git a/chart2/source/model/main/Legend.cxx 
b/chart2/source/model/main/Legend.cxx
index 9fc7cebd99ff..f72868b58cb5 100644
--- a/chart2/source/model/main/Legend.cxx
+++ b/chart2/source/model/main/Legend.cxx
@@ -105,6 +105,10 @@ void lcl_AddPropertiesToVector(
 
 }
 
+} // namespace
+
+namespace chart
+{
 const ::chart::tPropertyValueMap& StaticLegendDefaults()
 {
     static ::chart::tPropertyValueMap aStaticDefaults = []()
@@ -127,7 +131,10 @@ const ::chart::tPropertyValueMap& StaticLegendDefaults()
         }();
     return aStaticDefaults;
 };
+} // namespace chart
 
+namespace
+{
 ::cppu::OPropertyArrayHelper& StaticLegendInfoHelper()
 {
     static ::cppu::OPropertyArrayHelper aPropHelper = []()
diff --git a/chart2/source/view/main/ChartItemPool.cxx 
b/chart2/source/view/main/ChartItemPool.cxx
index 9f4637b21e1f..ed62e57c1a53 100644
--- a/chart2/source/view/main/ChartItemPool.cxx
+++ b/chart2/source/view/main/ChartItemPool.cxx
@@ -19,6 +19,10 @@
 
 #include "ChartItemPool.hxx"
 #include <chartview/ChartSfxItemIds.hxx>
+#include <DataSeries.hxx>
+#include <FormattedString.hxx>
+#include <Legend.hxx>
+#include <Axis.hxx>
 #include <svx/chrtitem.hxx>
 #include <svx/sdangitm.hxx>
 #include <svx/svdpool.hxx>
@@ -223,6 +227,19 @@ MapUnit ChartItemPool::GetMetric(sal_uInt16 /* nWhich */) 
const
 
 rtl::Reference<SfxItemPool> ChartItemPool::CreateChartItemPool()
 {
+    // There are various default values which want to call
+    // OutputDevice::GetDefaultFont. Unfortunately, when processing
+    // UNO methods which may get called from out of process, this
+    // happens on a thread that does not take the SolarMutex, which
+    // causes trouble in ImplFontCache.
+    // Trying to take the SolarMutex when initialising these default
+    // leads to ABBA deadlocks.
+    // So rather just trigger the initialisation of these things here.
+    StaticDataSeriesDefaults();
+    StaticAxisDefaults();
+    StaticLegendDefaults();
+    StaticFormattedStringDefaults();
+
     return new ChartItemPool();
 }
 
diff --git a/sw/source/uibase/uno/unodoc.cxx b/sw/source/uibase/uno/unodoc.cxx
index 40d34dc64676..b525d2e366d3 100644
--- a/sw/source/uibase/uno/unodoc.cxx
+++ b/sw/source/uibase/uno/unodoc.cxx
@@ -37,8 +37,8 @@ extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
 Writer_SwTextDocument_get_implementation(
     css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const& 
args)
 {
-    SwGlobals::ensure();
     SolarMutexGuard aGuard;
+    SwGlobals::ensure();
     css::uno::Reference<css::uno::XInterface> xInterface = 
sfx2::createSfxModelInstance(args,
         [](SfxModelFlags _nCreationFlags)
         {
diff --git a/vcl/source/font/fontcache.cxx b/vcl/source/font/fontcache.cxx
index 9fde6e5407a0..3fcf7ee1a7a8 100644
--- a/vcl/source/font/fontcache.cxx
+++ b/vcl/source/font/fontcache.cxx
@@ -25,6 +25,7 @@
 #include <font/PhysicalFontFace.hxx>
 #include <font/PhysicalFontFamily.hxx>
 #include <font/LogicalFontInstance.hxx>
+#include <tools/debug.hxx>
 #include <impfontcache.hxx>
 
 using namespace vcl::font;
@@ -95,6 +96,7 @@ ImplFontCache::ImplFontCache()
 
 ImplFontCache::~ImplFontCache()
 {
+    DBG_TESTSOLARMUTEX();
     for (const auto & rLFI : maFontInstanceList)
     {
         rLFI.second->mpFontCache = nullptr;
@@ -112,6 +114,7 @@ rtl::Reference<LogicalFontInstance> 
ImplFontCache::GetFontInstance( PhysicalFont
 rtl::Reference<LogicalFontInstance> ImplFontCache::GetFontInstance( 
PhysicalFontCollection const * pFontList,
     vcl::font::FontSelectPattern& aFontSelData )
 {
+    DBG_TESTSOLARMUTEX();
     rtl::Reference<LogicalFontInstance> pFontInstance;
     PhysicalFontFamily* pFontFamily = nullptr;
 
@@ -240,6 +243,7 @@ rtl::Reference<LogicalFontInstance> 
ImplFontCache::GetGlyphFallbackFont( Physica
 
 void ImplFontCache::Invalidate()
 {
+    DBG_TESTSOLARMUTEX();
     // #112304# make sure the font cache is really clean
     mpLastHitCacheEntry = nullptr;
     for (auto const & pair : maFontInstanceList)

Reply via email to