SyncEngine: no need to use QAtomicInt

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)
This commit is contained in:
Olivier Goffart 2020-02-05 12:57:09 +01:00 committed by Kevin Ottens
parent f81f96915f
commit 1c10fceacc
No known key found for this signature in database
GPG key ID: 074BBBCB8DECC9E2
12 changed files with 28 additions and 32 deletions

View file

@ -53,8 +53,8 @@ BandwidthManager::BandwidthManager(OwncloudPropagator *p)
, _relativeLimitCurrentMeasuredJob(nullptr) , _relativeLimitCurrentMeasuredJob(nullptr)
, _currentDownloadLimit(0) , _currentDownloadLimit(0)
{ {
_currentUploadLimit = _propagator->_uploadLimit.fetchAndAddAcquire(0); _currentUploadLimit = _propagator->_uploadLimit;
_currentDownloadLimit = _propagator->_downloadLimit.fetchAndAddAcquire(0); _currentDownloadLimit = _propagator->_downloadLimit;
QObject::connect(&_switchingTimer, &QTimer::timeout, this, &BandwidthManager::switchingTimerExpired); QObject::connect(&_switchingTimer, &QTimer::timeout, this, &BandwidthManager::switchingTimerExpired);
_switchingTimer.setInterval(10 * 1000); _switchingTimer.setInterval(10 * 1000);
@ -337,7 +337,7 @@ void BandwidthManager::relativeDownloadDelayTimerExpired()
void BandwidthManager::switchingTimerExpired() void BandwidthManager::switchingTimerExpired()
{ {
qint64 newUploadLimit = _propagator->_uploadLimit.fetchAndAddAcquire(0); qint64 newUploadLimit = _propagator->_uploadLimit;
if (newUploadLimit != _currentUploadLimit) { if (newUploadLimit != _currentUploadLimit) {
qCInfo(lcBandwidthManager) << "Upload Bandwidth limit changed" << _currentUploadLimit << newUploadLimit; qCInfo(lcBandwidthManager) << "Upload Bandwidth limit changed" << _currentUploadLimit << newUploadLimit;
_currentUploadLimit = newUploadLimit; _currentUploadLimit = newUploadLimit;
@ -354,7 +354,7 @@ void BandwidthManager::switchingTimerExpired()
} }
} }
} }
qint64 newDownloadLimit = _propagator->_downloadLimit.fetchAndAddAcquire(0); qint64 newDownloadLimit = _propagator->_downloadLimit;
if (newDownloadLimit != _currentDownloadLimit) { if (newDownloadLimit != _currentDownloadLimit) {
qCInfo(lcBandwidthManager) << "Download Bandwidth limit changed" << _currentDownloadLimit << newDownloadLimit; qCInfo(lcBandwidthManager) << "Download Bandwidth limit changed" << _currentDownloadLimit << newDownloadLimit;
_currentDownloadLimit = newDownloadLimit; _currentDownloadLimit = newDownloadLimit;

View file

@ -79,8 +79,8 @@ OwncloudPropagator::~OwncloudPropagator() = default;
int OwncloudPropagator::maximumActiveTransferJob() int OwncloudPropagator::maximumActiveTransferJob()
{ {
if (_downloadLimit.fetchAndAddAcquire(0) != 0 if (_downloadLimit != 0
|| _uploadLimit.fetchAndAddAcquire(0) != 0 || _uploadLimit != 0
|| !_syncOptions._parallelNetworkJobs) { || !_syncOptions._parallelNetworkJobs) {
// disable parallelism when there is a network limit. // disable parallelism when there is a network limit.
return 1; return 1;
@ -237,7 +237,7 @@ void PropagateItemJob::done(SyncFileItem::Status statusArg, const QString &error
} }
} }
if (propagator()->_abortRequested.fetchAndAddRelaxed(0) && (_item->_status == SyncFileItem::NormalError if (propagator()->_abortRequested && (_item->_status == SyncFileItem::NormalError
|| _item->_status == SyncFileItem::FatalError)) { || _item->_status == SyncFileItem::FatalError)) {
// an abort request is ongoing. Change the status to Soft-Error // an abort request is ongoing. Change the status to Soft-Error
_item->_status = SyncFileItem::SoftError; _item->_status = SyncFileItem::SoftError;

View file

@ -419,11 +419,11 @@ public:
const SyncOptions &syncOptions() const; const SyncOptions &syncOptions() const;
void setSyncOptions(const SyncOptions &syncOptions); void setSyncOptions(const SyncOptions &syncOptions);
QAtomicInt _downloadLimit; int _downloadLimit = 0;
QAtomicInt _uploadLimit; int _uploadLimit = 0;
BandwidthManager _bandwidthManager; BandwidthManager _bandwidthManager;
QAtomicInt _abortRequested; // boolean set by the main thread to abort. bool _abortRequested = false;
/** The list of currently active jobs. /** The list of currently active jobs.
This list contains the jobs that are currently using ressources and is used purely to This list contains the jobs that are currently using ressources and is used purely to
@ -492,8 +492,7 @@ public:
void abort() void abort()
{ {
bool alreadyAborting = _abortRequested.fetchAndStoreOrdered(true); if (_abortRequested)
if (alreadyAborting)
return; return;
if (_rootJob) { if (_rootJob) {
// Connect to abortFinished which signals that abort has been asynchronously finished // Connect to abortFinished which signals that abort has been asynchronously finished

View file

@ -361,7 +361,7 @@ QString GETFileJob::errorString() const
void PropagateDownloadFile::start() void PropagateDownloadFile::start()
{ {
if (propagator()->_abortRequested.fetchAndAddRelaxed(0)) if (propagator()->_abortRequested)
return; return;
_isEncrypted = false; _isEncrypted = false;
@ -503,7 +503,7 @@ void PropagateDownloadFile::conflictChecksumComputed(const QByteArray &checksumT
void PropagateDownloadFile::startDownload() void PropagateDownloadFile::startDownload()
{ {
if (propagator()->_abortRequested.fetchAndAddRelaxed(0)) if (propagator()->_abortRequested)
return; return;
// do a klaas' case clash check. // do a klaas' case clash check.

View file

@ -81,7 +81,7 @@ PropagatorJob::JobParallelism PropagateRemoteDelete::parallelism()
void PropagateRemoteDelete::start() void PropagateRemoteDelete::start()
{ {
if (propagator()->_abortRequested.fetchAndAddRelaxed(0)) if (propagator()->_abortRequested)
return; return;
if (!_item->_encryptedFileName.isEmpty()) { if (!_item->_encryptedFileName.isEmpty()) {

View file

@ -69,7 +69,7 @@ PropagatorJob::JobParallelism PropagateRemoteMkdir::parallelism()
void PropagateRemoteMkdir::start() void PropagateRemoteMkdir::start()
{ {
if (propagator()->_abortRequested.fetchAndAddRelaxed(0)) if (propagator()->_abortRequested)
return; return;
qCDebug(lcPropagateRemoteMkdir) << _item->_file; qCDebug(lcPropagateRemoteMkdir) << _item->_file;
@ -91,7 +91,7 @@ void PropagateRemoteMkdir::start()
void PropagateRemoteMkdir::slotStartMkcolJob() void PropagateRemoteMkdir::slotStartMkcolJob()
{ {
if (propagator()->_abortRequested.fetchAndAddRelaxed(0)) if (propagator()->_abortRequested)
return; return;
qCDebug(lcPropagateRemoteMkdir) << _item->_file; qCDebug(lcPropagateRemoteMkdir) << _item->_file;
@ -108,7 +108,7 @@ void PropagateRemoteMkdir::slotStartEncryptedMkcolJob(const QString &path, const
Q_UNUSED(path) Q_UNUSED(path)
Q_UNUSED(size) Q_UNUSED(size)
if (propagator()->_abortRequested.fetchAndAddRelaxed(0)) if (propagator()->_abortRequested)
return; return;
qDebug() << filename; qDebug() << filename;

View file

@ -75,7 +75,7 @@ bool MoveJob::finished()
void PropagateRemoteMove::start() void PropagateRemoteMove::start()
{ {
if (propagator()->_abortRequested.fetchAndAddRelaxed(0)) if (propagator()->_abortRequested)
return; return;
QString origin = propagator()->adjustRenamedPath(_item->_file); QString origin = propagator()->adjustRenamedPath(_item->_file);

View file

@ -293,7 +293,7 @@ void PropagateUploadFileCommon::setupUnencryptedFile()
} }
void PropagateUploadFileCommon::startUploadFile() { void PropagateUploadFileCommon::startUploadFile() {
if (propagator()->_abortRequested.fetchAndAddRelaxed(0)) { if (propagator()->_abortRequested) {
return; return;
} }
@ -335,7 +335,7 @@ void PropagateUploadFileCommon::slotComputeContentChecksum()
{ {
qDebug() << "Trying to compute the checksum of the file"; qDebug() << "Trying to compute the checksum of the file";
qDebug() << "Still trying to understand if this is the local file or the uploaded one"; qDebug() << "Still trying to understand if this is the local file or the uploaded one";
if (propagator()->_abortRequested.fetchAndAddRelaxed(0)) { if (propagator()->_abortRequested) {
return; return;
} }

View file

@ -275,7 +275,7 @@ void PropagateUploadFileNG::slotMkColFinished(QNetworkReply::NetworkError)
void PropagateUploadFileNG::startNextChunk() void PropagateUploadFileNG::startNextChunk()
{ {
if (propagator()->_abortRequested.fetchAndAddRelaxed(0)) if (propagator()->_abortRequested)
return; return;
qint64 fileSize = _fileToUpload._size; qint64 fileSize = _fileToUpload._size;

View file

@ -72,7 +72,7 @@ void PropagateUploadFileV1::doStartUpload()
void PropagateUploadFileV1::startNextChunk() void PropagateUploadFileV1::startNextChunk()
{ {
if (propagator()->_abortRequested.fetchAndAddRelaxed(0)) if (propagator()->_abortRequested)
return; return;
if (!_jobs.isEmpty() && _currentChunk + _startChunk >= _chunkCount - 1) { if (!_jobs.isEmpty() && _currentChunk + _startChunk >= _chunkCount - 1) {

View file

@ -92,7 +92,7 @@ void PropagateLocalRemove::start()
{ {
_moveToTrash = propagator()->syncOptions()._moveFilesToTrash; _moveToTrash = propagator()->syncOptions()._moveFilesToTrash;
if (propagator()->_abortRequested.fetchAndAddRelaxed(0)) if (propagator()->_abortRequested)
return; return;
QString filename = propagator()->_localDir + _item->_file; QString filename = propagator()->_localDir + _item->_file;
@ -132,7 +132,7 @@ void PropagateLocalRemove::start()
void PropagateLocalMkdir::start() void PropagateLocalMkdir::start()
{ {
if (propagator()->_abortRequested.fetchAndAddRelaxed(0)) if (propagator()->_abortRequested)
return; return;
const auto rootPath = [=]() { const auto rootPath = [=]() {
@ -244,7 +244,7 @@ void PropagateLocalMkdir::startDemanglingName(const QString &parentPath)
void PropagateLocalRename::start() void PropagateLocalRename::start()
{ {
if (propagator()->_abortRequested.fetchAndAddRelaxed(0)) if (propagator()->_abortRequested)
return; return;
QString existingFile = propagator()->getFilePath(propagator()->adjustRenamedPath(_item->_file)); QString existingFile = propagator()->getFilePath(propagator()->adjustRenamedPath(_item->_file));

View file

@ -822,11 +822,8 @@ void SyncEngine::setNetworkLimits(int upload, int download)
_propagator->_uploadLimit = upload; _propagator->_uploadLimit = upload;
_propagator->_downloadLimit = download; _propagator->_downloadLimit = download;
int propDownloadLimit = _propagator->_downloadLimit.load(); if (upload != 0 || download != 0) {
int propUploadLimit = _propagator->_uploadLimit.load(); qCInfo(lcEngine) << "Network Limits (down/up) " << upload << download;
if (propDownloadLimit != 0 || propUploadLimit != 0) {
qCInfo(lcEngine) << "Network Limits (down/up) " << propDownloadLimit << propUploadLimit;
} }
} }