From fb94c8f64a15ff4bf45f1d2adfab9cb50a696d71 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Mon, 25 Mar 2024 09:05:00 +0500 Subject: Relax SolarMutexReleaser precondition to not require SolarMutex lock As discussed on https://gerrit.libreoffice.org/c/core/+/164843/2#message-8873d3d119de7206b33bc824f5809b8b1d3d97da, it is impossible at times to know in advance, if a specific code, that must not be guarded by SolarMutex (e.g., calling to other threads, which might need to grab the mutex), will itself be guarded by SolarMutex. Before this change, a required pre-requisite for SolarMutexReleaser use was existing lock of SolarMutex; otherwise, an attempt to release it would call abort(). Thus, in some places we had to grab the mutex prior to releasing it, and that itself introduced more potential for deadlock. Now the SolarMutexReleaser is safe to use without the lock, in which case, it will do nothing. Change-Id: I8759c2f6ed448598b3be4d6c5109804b5e7523ed Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165262 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- include/vcl/svapp.hxx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/vcl/svapp.hxx b/include/vcl/svapp.hxx index dcd1374fa3f5..d5f1739be1ae 100644 --- a/include/vcl/svapp.hxx +++ b/include/vcl/svapp.hxx @@ -1414,8 +1414,16 @@ class SolarMutexReleaser { const sal_uInt32 mnReleased; public: - SolarMutexReleaser(): mnReleased(Application::ReleaseSolarMutex()) {} - ~SolarMutexReleaser() { Application::AcquireSolarMutex( mnReleased ); } + SolarMutexReleaser() + : mnReleased( + Application::GetSolarMutex().IsCurrentThread() ? Application::ReleaseSolarMutex() : 0) + { + } + ~SolarMutexReleaser() + { + if (mnReleased) + Application::AcquireSolarMutex(mnReleased); + } }; VCL_DLLPUBLIC Application* GetpApp(); -- cgit