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)
, _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;

View 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;
}

View 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

View 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.

View 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()) {

View 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;

View 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);

View 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;
}

View 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;

View 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) {

View 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));

View 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;
}
}