From 87f7d2c6b076a4c275d4d14a1e099844c9eb4766 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 17 Dec 2023 11:28:27 +0100 Subject: [PATCH] QPA/Windows: misc cleanup of QShGetFileInfoThread Misc cleanup of QShGetFileInfoThread: - use QThread's interruption abilities instead custom one - use QMutexLocker instead manual lock/unlock Task-number: QTBUG-90876 Change-Id: If0566e56ab765fb95e837cdfa09639c1622b6d4e Reviewed-by: Friedemann Kleint Reviewed-by: Oliver Wolff --- src/plugins/platforms/windows/qwindowstheme.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp index aeb8d4ad1b..9022fe1406 100644 --- a/src/plugins/platforms/windows/qwindowstheme.cpp +++ b/src/plugins/platforms/windows/qwindowstheme.cpp @@ -180,8 +180,8 @@ public: QComHelper comHelper(COINIT_MULTITHREADED); QMutexLocker readyLocker(&m_readyMutex); - while (!m_cancelled.loadRelaxed()) { - if (!m_params && !m_cancelled.loadRelaxed() + while (!isInterruptionRequested()) { + if (!m_params && !isInterruptionRequested() && !m_readyCondition.wait(&m_readyMutex, QDeadlineTimer(1000ll))) continue; @@ -191,15 +191,14 @@ public: const bool result = SHGetFileInfo(reinterpret_cast(fileName.utf16()), m_params->attributes, &info, sizeof(SHFILEINFO), m_params->flags); - m_doneMutex.lock(); - if (!m_cancelled.loadRelaxed()) { + QMutexLocker doneLocker(&m_doneMutex); + if (!isInterruptionRequested()) { *m_params->result = result; memcpy(m_params->info, &info, sizeof(SHFILEINFO)); } m_params = nullptr; m_doneCondition.wakeAll(); - m_doneMutex.unlock(); } } } @@ -219,13 +218,12 @@ public: void cancel() { QMutexLocker doneLocker(&m_doneMutex); - m_cancelled.storeRelaxed(1); + requestInterruption(); m_readyCondition.wakeAll(); } private: QShGetFileInfoParams *m_params; - QAtomicInt m_cancelled; QWaitCondition m_readyCondition; QWaitCondition m_doneCondition; QMutex m_readyMutex;