summaryrefslogtreecommitdiff
path: root/cui
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2018-06-04 16:28:22 +0200
committerAndras Timar <andras.timar@collabora.com>2018-07-02 10:52:30 +0200
commit2503484a87a6f7e8ca2df25511eb046cd682166c (patch)
tree243bb19848bf1cd41e36ad9f0f5c566534ba105f /cui
parent9974b9b11bbd702cba25b73096ea2cead2c8ce0e (diff)
tdf#117866 cui: avoid deadlock in personalization dialog
The deadlock happened as the main thread wanted to join SearchAndParseThread (while owning the solar mutex), but SearchAndParseThread wanted to take the solar mutex to import a graphic. Fix the deadlock by checking for the termination flag earlier, so we don't take any new mutexes if termination was requested already. (cherry picked from commit 766c85a4f67f5d50645340e31cebd5956998c6fc) Related: tdf#117866 cui: use std::atomic for thread termination flag (cherry picked from commit f4ac7b5a084a7cf483bb89a2fa411f9df70df4d0) tdf#117866 cui personalization: fix a possible race The case when the thread is re-scheduled exactly after checking for m_bExecute but before taking the solar mutex. (cherry picked from commit f4c73f90da2a2c31f0d29572180aa97e10c3dbad) Change-Id: Idddaadadc693610d9f31a14300b22aff8d452756 Reviewed-on: https://gerrit.libreoffice.org/55347 Reviewed-by: Luboš Luňák <l.lunak@collabora.com> Tested-by: Jenkins (cherry picked from commit ec8e973f7e681b0ae25e4b781918dd98ea0e8176)
Diffstat (limited to 'cui')
-rw-r--r--cui/source/options/personalization.cxx14
-rw-r--r--cui/source/options/personalization.hxx4
2 files changed, 14 insertions, 4 deletions
diff --git a/cui/source/options/personalization.cxx b/cui/source/options/personalization.cxx
index a9ff29edf078..dab788d8b824 100644
--- a/cui/source/options/personalization.cxx
+++ b/cui/source/options/personalization.cxx
@@ -99,7 +99,13 @@ SelectPersonaDialog::~SelectPersonaDialog()
void SelectPersonaDialog::dispose()
{
if (m_pSearchThread.is())
+ {
+ // Release the solar mutex, so the thread is not affected by the race
+ // when it's after the m_bExecute check but before taking the solar
+ // mutex.
+ SolarMutexReleaser aReleaser;
m_pSearchThread->join();
+ }
m_pEdit.clear();
m_pSearchButton.clear();
@@ -772,14 +778,16 @@ void SearchAndParseThread::execute()
continue;
}
INetURLObject aURLObj( sPreviewFile );
+
+ // Stop the thread if requested -- before taking the solar mutex.
+ if( !m_bExecute )
+ return;
+
// for VCL to be able to create bitmaps / do visual changes in the thread
SolarMutexGuard aGuard;
aFilter.ImportGraphic( aGraphic, aURLObj );
Bitmap aBmp = aGraphic.GetBitmap();
- if( !m_bExecute )
- return;
-
m_pPersonaDialog->SetImages( Image( aBmp ), nIndex++ );
m_pPersonaDialog->setOptimalLayoutSize();
m_pPersonaDialog->AddPersonaSetting( aPersonaSetting );
diff --git a/cui/source/options/personalization.hxx b/cui/source/options/personalization.hxx
index 9d5e057c8c34..5153fc98b1b5 100644
--- a/cui/source/options/personalization.hxx
+++ b/cui/source/options/personalization.hxx
@@ -16,6 +16,7 @@
#include <vcl/prgsbar.hxx>
#include <vector>
#include <array>
+#include <atomic>
#define CATEGORYCOUNT 6 // Number of persona categories
@@ -119,7 +120,8 @@ private:
VclPtr<SelectPersonaDialog> m_pPersonaDialog;
OUString m_aURL;
- bool m_bExecute, m_bDirectURL;
+ std::atomic<bool> m_bExecute;
+ bool m_bDirectURL;
virtual ~SearchAndParseThread() override;
virtual void execute() override;