From d8a03cd8d8357e0c112ff4a48fe5ec289f593ad3 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 28 Aug 2023 02:08:40 +0800 Subject: [PATCH] Use atomic primitives from standard library QAtomicInteger underlying is using std::atomic structures, so using std::atomic directly should not be a problem for us. PR #19507. --- src/app/application.cpp | 2 +- src/app/application.h | 5 +++-- src/base/bittorrent/torrentcreator.cpp | 4 ++-- src/base/bittorrent/torrentcreator.h | 5 +++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/app/application.cpp b/src/app/application.cpp index 0cc3ef685..56788f5a7 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -1274,7 +1274,7 @@ void Application::adjustThreadPriority() const void Application::cleanup() { // cleanup() can be called multiple times during shutdown. We only need it once. - if (!m_isCleanupRun.testAndSetAcquire(0, 1)) + if (m_isCleanupRun.exchange(true, std::memory_order_acquire)) return; LogMsg(tr("qBittorrent termination initiated")); diff --git a/src/app/application.h b/src/app/application.h index e57348ee3..d267a8d9b 100644 --- a/src/app/application.h +++ b/src/app/application.h @@ -30,8 +30,9 @@ #pragma once +#include + #include -#include #include #include #include @@ -177,7 +178,7 @@ private: #endif ApplicationInstanceManager *m_instanceManager = nullptr; - QAtomicInt m_isCleanupRun; + std::atomic_bool m_isCleanupRun; bool m_isProcessingParamsAllowed = false; ShutdownDialogAction m_shutdownAct = ShutdownDialogAction::Exit; QBtCommandLineParameters m_commandLineArgs; diff --git a/src/base/bittorrent/torrentcreator.cpp b/src/base/bittorrent/torrentcreator.cpp index 7762e63f8..bdc012869 100644 --- a/src/base/bittorrent/torrentcreator.cpp +++ b/src/base/bittorrent/torrentcreator.cpp @@ -93,12 +93,12 @@ void TorrentCreator::checkInterruptionRequested() const void TorrentCreator::requestInterruption() { - m_interruptionRequested.storeRelaxed(1); + m_interruptionRequested.store(true, std::memory_order_relaxed); } bool TorrentCreator::isInterruptionRequested() const { - return m_interruptionRequested.loadRelaxed() != 0; + return m_interruptionRequested.load(std::memory_order_relaxed); } void TorrentCreator::run() diff --git a/src/base/bittorrent/torrentcreator.h b/src/base/bittorrent/torrentcreator.h index b819306b4..79588b07f 100644 --- a/src/base/bittorrent/torrentcreator.h +++ b/src/base/bittorrent/torrentcreator.h @@ -28,7 +28,8 @@ #pragma once -#include +#include + #include #include #include @@ -96,6 +97,6 @@ namespace BitTorrent void checkInterruptionRequested() const; TorrentCreatorParams m_params; - QAtomicInt m_interruptionRequested; + std::atomic_bool m_interruptionRequested; }; }