From 35e948483452a6f80af95c4787300ad760e162d1 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Tue, 18 Apr 2017 21:03:38 +0200 Subject: [PATCH] Some code refactoring. --- include/MUtils/UpdateChecker.h | 4 ++-- src/UpdateChecker.cpp | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/MUtils/UpdateChecker.h b/include/MUtils/UpdateChecker.h index 8673b05..fe47d77 100644 --- a/include/MUtils/UpdateChecker.h +++ b/include/MUtils/UpdateChecker.h @@ -90,7 +90,7 @@ namespace MUtils const int getCurrentProgress(void) const { return m_progress; }; const UpdateCheckerInfo *getUpdateInfo(void) const { return m_updateInfo.data(); } - void cancel(void) { m_cancelled = true; } + bool cancel(void) { return m_cancelled.ref(); } public slots: void start(Priority = InheritPriority); @@ -121,7 +121,7 @@ namespace MUtils const QString m_binaryKeys; volatile bool m_success; - volatile bool m_cancelled; + QAtomicInt m_cancelled; int m_status; int m_progress; diff --git a/src/UpdateChecker.cpp b/src/UpdateChecker.cpp index c36765b..4644160 100644 --- a/src/UpdateChecker.cpp +++ b/src/UpdateChecker.cpp @@ -222,9 +222,10 @@ static const int DOWNLOAD_TIMEOUT = 30000; static const int VERSION_INFO_EXPIRES_MONTHS = 6; static char *USER_AGENT_STR = "Mozilla/5.0 (X11; Linux i686; rv:10.0) Gecko/20100101 Firefox/10.0"; /*use something innocuous*/ +#define IS_CANCELLED (!(!m_cancelled)) #define CHECK_CANCELLED() do \ { \ - if(m_cancelled) \ + if(IS_CANCELLED) \ { \ m_success = false; \ log("", "Update check has been cancelled by user!"); \ @@ -311,7 +312,7 @@ UpdateChecker::UpdateChecker(const QString &binWGet, const QString &binMCat, con m_testMode(testMode), m_maxProgress(getMaxProgress()) { - m_success = m_cancelled = false; + m_success = false; m_status = UpdateStatus_NotStartedYet; m_progress = 0; @@ -331,7 +332,8 @@ UpdateChecker::~UpdateChecker(void) void UpdateChecker::start(Priority priority) { - m_cancelled = m_success = false; + m_success = false; + m_cancelled.fetchAndStoreOrdered(0); QThread::start(priority); } @@ -692,7 +694,7 @@ bool UpdateChecker::getFile(const QString &url, const QString &outFile, const un { return true; } - if (m_cancelled) + if (IS_CANCELLED) { break; /*cancelled*/ } @@ -757,7 +759,7 @@ bool UpdateChecker::getFile(const QString &url, const bool forceIp4, const QStri const QString line = QString::fromLatin1(process.readLine()).simplified(); log(line); } - if (bTimeOut || m_cancelled) + if (bTimeOut || IS_CANCELLED) { qWarning("WGet process timed out <-- killing!"); process.kill(); @@ -811,7 +813,7 @@ bool UpdateChecker::tryContactHost(const QString &hostname, const int &timeoutMs QString line = QString::fromLatin1(process.readLine()).simplified(); log(line); } - if (bTimeOut || m_cancelled) + if (bTimeOut || IS_CANCELLED) { qWarning("MCat process timed out <-- killing!"); process.kill(); -- 2.11.4.GIT