SyncEngine: no need to use QAtomicInt
authorOlivier Goffart <ogoffart@woboq.com>
Wed, 5 Feb 2020 11:57:09 +0000 (12:57 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:59:05 +0000 (10:59 +0100)
This was done because the propagator jobs where running in a thread a long
time ago, but this is no longer the case.

(Also QAtomicInt::load is marked as deprecated now)

12 files changed:
src/libsync/bandwidthmanager.cpp
src/libsync/owncloudpropagator.cpp
src/libsync/owncloudpropagator.h
src/libsync/propagatedownload.cpp
src/libsync/propagateremotedelete.cpp
src/libsync/propagateremotemkdir.cpp
src/libsync/propagateremotemove.cpp
src/libsync/propagateupload.cpp
src/libsync/propagateuploadng.cpp
src/libsync/propagateuploadv1.cpp
src/libsync/propagatorjobs.cpp
src/libsync/syncengine.cpp

index 4455514f87c5d8cf070b338cc049cc31cc1062b2..a8dd2a6b11c5e3ab50deee4c37ed46328b76bda9 100644 (file)
@@ -53,8 +53,8 @@ BandwidthManager::BandwidthManager(OwncloudPropagator *p)
     , _relativeLimitCurrentMeasuredJob(nullptr)
     , _currentDownloadLimit(0)
 {
-    _currentUploadLimit = _propagator->_uploadLimit.fetchAndAddAcquire(0);
-    _currentDownloadLimit = _propagator->_downloadLimit.fetchAndAddAcquire(0);
+    _currentUploadLimit = _propagator->_uploadLimit;
+    _currentDownloadLimit = _propagator->_downloadLimit;
 
     QObject::connect(&_switchingTimer, &QTimer::timeout, this, &BandwidthManager::switchingTimerExpired);
     _switchingTimer.setInterval(10 * 1000);
@@ -337,7 +337,7 @@ void BandwidthManager::relativeDownloadDelayTimerExpired()
 
 void BandwidthManager::switchingTimerExpired()
 {
-    qint64 newUploadLimit = _propagator->_uploadLimit.fetchAndAddAcquire(0);
+    qint64 newUploadLimit = _propagator->_uploadLimit;
     if (newUploadLimit != _currentUploadLimit) {
         qCInfo(lcBandwidthManager) << "Upload Bandwidth limit changed" << _currentUploadLimit << newUploadLimit;
         _currentUploadLimit = newUploadLimit;
@@ -354,7 +354,7 @@ void BandwidthManager::switchingTimerExpired()
             }
         }
     }
-    qint64 newDownloadLimit = _propagator->_downloadLimit.fetchAndAddAcquire(0);
+    qint64 newDownloadLimit = _propagator->_downloadLimit;
     if (newDownloadLimit != _currentDownloadLimit) {
         qCInfo(lcBandwidthManager) << "Download Bandwidth limit changed" << _currentDownloadLimit << newDownloadLimit;
         _currentDownloadLimit = newDownloadLimit;
index ed9eeea4113c6a9d585e92cccc663d52b27cba2c..b895da128b2fd7a070dda5d9dc9a6768b51c7b6f 100644 (file)
@@ -79,8 +79,8 @@ OwncloudPropagator::~OwncloudPropagator() = default;
 
 int OwncloudPropagator::maximumActiveTransferJob()
 {
-    if (_downloadLimit.fetchAndAddAcquire(0) != 0
-        || _uploadLimit.fetchAndAddAcquire(0) != 0
+    if (_downloadLimit != 0
+        || _uploadLimit != 0
         || !_syncOptions._parallelNetworkJobs) {
         // disable parallelism when there is a network limit.
         return 1;
@@ -237,8 +237,8 @@ void PropagateItemJob::done(SyncFileItem::Status statusArg, const QString &error
         }
     }
 
-    if (propagator()->_abortRequested.fetchAndAddRelaxed(0) && (_item->_status == SyncFileItem::NormalError
-                                                                   || _item->_status == SyncFileItem::FatalError)) {
+    if (propagator()->_abortRequested && (_item->_status == SyncFileItem::NormalError
+                                          || _item->_status == SyncFileItem::FatalError)) {
         // an abort request is ongoing. Change the status to Soft-Error
         _item->_status = SyncFileItem::SoftError;
     }
index 2cc537d5b7d861178ace7226e726566ed5738529..4524e893c83dba2f24ab8a525dd797df65393d10 100644 (file)
@@ -419,11 +419,11 @@ public:
     const SyncOptions &syncOptions() const;
     void setSyncOptions(const SyncOptions &syncOptions);
 
-    QAtomicInt _downloadLimit;
-    QAtomicInt _uploadLimit;
+    int _downloadLimit = 0;
+    int _uploadLimit = 0;
     BandwidthManager _bandwidthManager;
 
-    QAtomicInt _abortRequested; // boolean set by the main thread to abort.
+    bool _abortRequested = false;
 
     /** The list of currently active jobs.
         This list contains the jobs that are currently using ressources and is used purely to
@@ -492,8 +492,7 @@ public:
 
     void abort()
     {
-        bool alreadyAborting = _abortRequested.fetchAndStoreOrdered(true);
-        if (alreadyAborting)
+        if (_abortRequested)
             return;
         if (_rootJob) {
             // Connect to abortFinished  which signals that abort has been asynchronously finished
index bdd250cee03da8c1467a2de4a42f29944c514d03..b630778c8d156648a0052dde8be145d6da776f9e 100644 (file)
@@ -361,7 +361,7 @@ QString GETFileJob::errorString() const
 
 void PropagateDownloadFile::start()
 {
-    if (propagator()->_abortRequested.fetchAndAddRelaxed(0))
+    if (propagator()->_abortRequested)
         return;
     _isEncrypted = false;
 
@@ -503,7 +503,7 @@ void PropagateDownloadFile::conflictChecksumComputed(const QByteArray &checksumT
 
 void PropagateDownloadFile::startDownload()
 {
-    if (propagator()->_abortRequested.fetchAndAddRelaxed(0))
+    if (propagator()->_abortRequested)
         return;
 
     // do a klaas' case clash check.
index 848d943280e00a9e16941a9e0e78e0c58e6ba39d..6b8776cd0f98a667a22df448bf19c85a8813135f 100644 (file)
@@ -81,7 +81,7 @@ PropagatorJob::JobParallelism PropagateRemoteDelete::parallelism()
 
 void PropagateRemoteDelete::start()
 {
-    if (propagator()->_abortRequested.fetchAndAddRelaxed(0))
+    if (propagator()->_abortRequested)
         return;
 
     if (!_item->_encryptedFileName.isEmpty()) {
index 945d7d393120480aad962bf83a2340bf36bb4c72..006f1cdc888d0579ff56bcff7853b51a37107756 100644 (file)
@@ -69,7 +69,7 @@ PropagatorJob::JobParallelism PropagateRemoteMkdir::parallelism()
 
 void PropagateRemoteMkdir::start()
 {
-    if (propagator()->_abortRequested.fetchAndAddRelaxed(0))
+    if (propagator()->_abortRequested)
         return;
 
     qCDebug(lcPropagateRemoteMkdir) << _item->_file;
@@ -91,7 +91,7 @@ void PropagateRemoteMkdir::start()
 
 void PropagateRemoteMkdir::slotStartMkcolJob()
 {
-    if (propagator()->_abortRequested.fetchAndAddRelaxed(0))
+    if (propagator()->_abortRequested)
         return;
 
     qCDebug(lcPropagateRemoteMkdir) << _item->_file;
@@ -108,7 +108,7 @@ void PropagateRemoteMkdir::slotStartEncryptedMkcolJob(const QString &path, const
     Q_UNUSED(path)
     Q_UNUSED(size)
 
-    if (propagator()->_abortRequested.fetchAndAddRelaxed(0))
+    if (propagator()->_abortRequested)
         return;
 
     qDebug() << filename;
index 889fb7b1db0d9eb3a602f623d035222947625847..0d7f57ce3e51791687d34cf86891b0ab71c0fa7c 100644 (file)
@@ -75,7 +75,7 @@ bool MoveJob::finished()
 
 void PropagateRemoteMove::start()
 {
-    if (propagator()->_abortRequested.fetchAndAddRelaxed(0))
+    if (propagator()->_abortRequested)
         return;
 
     QString origin = propagator()->adjustRenamedPath(_item->_file);
index f17fc536770483ec39c429dfe3607bc2792728fb..519fb36c9353ff5b8ba3d407d27e30fb39525c9d 100644 (file)
@@ -293,7 +293,7 @@ void PropagateUploadFileCommon::setupUnencryptedFile()
 }
 
 void PropagateUploadFileCommon::startUploadFile() {
-    if (propagator()->_abortRequested.fetchAndAddRelaxed(0)) {
+    if (propagator()->_abortRequested) {
         return;
     }
 
@@ -335,7 +335,7 @@ void PropagateUploadFileCommon::slotComputeContentChecksum()
 {
     qDebug() << "Trying to compute the checksum of the file";
     qDebug() << "Still trying to understand if this is the local file or the uploaded one";
-    if (propagator()->_abortRequested.fetchAndAddRelaxed(0)) {
+    if (propagator()->_abortRequested) {
         return;
     }
 
index fa79633d1bfdbeadfe7e9c273023b64813b55276..29c549ea02a1791c29a79a985c4c6b26f963a51d 100644 (file)
@@ -275,7 +275,7 @@ void PropagateUploadFileNG::slotMkColFinished(QNetworkReply::NetworkError)
 
 void PropagateUploadFileNG::startNextChunk()
 {
-    if (propagator()->_abortRequested.fetchAndAddRelaxed(0))
+    if (propagator()->_abortRequested)
         return;
 
     qint64 fileSize = _fileToUpload._size;
index e1ae8b5faa7a7dfdb05b447b4725cf45e0c3fa54..93950c313e5e191f8ec5d30839af9c77cadc9ccd 100644 (file)
@@ -72,7 +72,7 @@ void PropagateUploadFileV1::doStartUpload()
 
 void PropagateUploadFileV1::startNextChunk()
 {
-    if (propagator()->_abortRequested.fetchAndAddRelaxed(0))
+    if (propagator()->_abortRequested)
         return;
 
     if (!_jobs.isEmpty() && _currentChunk + _startChunk >= _chunkCount - 1) {
index 8324e6f3a17ef7d5d7ce5e0160e996ef851ea437..730694c0a6ae71de323cc35681cdb1e543e81676 100644 (file)
@@ -92,7 +92,7 @@ void PropagateLocalRemove::start()
 {
     _moveToTrash = propagator()->syncOptions()._moveFilesToTrash;
 
-    if (propagator()->_abortRequested.fetchAndAddRelaxed(0))
+    if (propagator()->_abortRequested)
         return;
 
     QString filename = propagator()->_localDir + _item->_file;
@@ -132,7 +132,7 @@ void PropagateLocalRemove::start()
 
 void PropagateLocalMkdir::start()
 {
-    if (propagator()->_abortRequested.fetchAndAddRelaxed(0))
+    if (propagator()->_abortRequested)
         return;
 
     const auto rootPath = [=]() {
@@ -244,7 +244,7 @@ void PropagateLocalMkdir::startDemanglingName(const QString &parentPath)
 
 void PropagateLocalRename::start()
 {
-    if (propagator()->_abortRequested.fetchAndAddRelaxed(0))
+    if (propagator()->_abortRequested)
         return;
 
     QString existingFile = propagator()->getFilePath(propagator()->adjustRenamedPath(_item->_file));
index 48bc8ac5ae5f0a84d7ea558a610676170cbb08f3..3cc77c52e3b9ed24dc32a2da89e28fbf7cf4f70e 100644 (file)
@@ -822,11 +822,8 @@ void SyncEngine::setNetworkLimits(int upload, int download)
     _propagator->_uploadLimit = upload;
     _propagator->_downloadLimit = download;
 
-    int propDownloadLimit = _propagator->_downloadLimit.load();
-    int propUploadLimit = _propagator->_uploadLimit.load();
-
-    if (propDownloadLimit != 0 || propUploadLimit != 0) {
-        qCInfo(lcEngine) << "Network Limits (down/up) " << propDownloadLimit << propUploadLimit;
+    if (upload != 0 || download != 0) {
+        qCInfo(lcEngine) << "Network Limits (down/up) " << upload << download;
     }
 }