summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2017-11-29 15:18:12 +0100
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2017-12-01 02:12:43 +0100
commit0c528ae1589e5ce2c8780fcadeecdb4916395c25 (patch)
tree8b8d1b21acb7ac576d8d6b284e51da3212028d79
parent26cd0bb46559c01e1a871098efb385f57ea6de43 (diff)
tdf#114025 framework: avoid deadlock between Desktop init ...
... and SolarMutex: the problem is that rtl::StaticWithArg will first lock the implicit mutex of the C++11 static variable, and then the SolarMutex. So if one thread creates the Desktop singleton with SolarMutex locked and another thread without SolarMutex locked, this can deadlock. If we use rtl_Instance directly with SolarMutex, then there is still a static variable, but the SolarMutex will always be locked first, preventing this deadlock. Change-Id: Ibd37fdfa96a4a2b57f661be3814dd597eb52d338 Reviewed-on: https://gerrit.libreoffice.org/45508 Reviewed-by: Michael Meeks <michael.meeks@collabora.com> Tested-by: Jenkins <ci@libreoffice.org> (cherry picked from commit fa9c083c6071a0a4dc812f3c34731f347ddbabf7) Reviewed-on: https://gerrit.libreoffice.org/45559 Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
-rw-r--r--framework/source/services/desktop.cxx30
1 files changed, 25 insertions, 5 deletions
diff --git a/framework/source/services/desktop.cxx b/framework/source/services/desktop.cxx
index 2f3608f1b894..c0ac034cc801 100644
--- a/framework/source/services/desktop.cxx
+++ b/framework/source/services/desktop.cxx
@@ -1825,10 +1825,30 @@ struct Instance {
rtl::Reference<framework::Desktop> instance;
};
-struct Singleton:
- public rtl::StaticWithArg<
- Instance, css::uno::Reference<css::uno::XComponentContext>, Singleton>
-{};
+struct InstanceInit {
+ Instance * operator() (css::uno::Reference<css::uno::XComponentContext> const& xContext) {
+ static Instance instance(xContext);
+ return &instance;
+ }
+};
+
+struct GetSolarMutex {
+ comphelper::SolarMutex * operator() ()
+ {
+ return &Application::GetSolarMutex();
+ }
+};
+
+Instance & getInstance(css::uno::Reference<css::uno::XComponentContext> const& xContext)
+{
+ // tdf#114025 init with SolarMutex to avoid deadlock
+ return *rtl_Instance<Instance,
+ InstanceInit,
+ osl::Guard<comphelper::SolarMutex>,
+ GetSolarMutex,
+ css::uno::Reference<css::uno::XComponentContext> const>
+ ::create(InstanceInit(), GetSolarMutex(), xContext);
+}
}
@@ -1837,7 +1857,7 @@ com_sun_star_comp_framework_Desktop_get_implementation(
css::uno::XComponentContext *context,
css::uno::Sequence<css::uno::Any> const &)
{
- return cppu::acquire(Singleton::get(context).instance.get());
+ return cppu::acquire(getInstance(context).instance.get());
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */