safer approach for detecting duplicate sync runs

This commit is contained in:
Daniel Molkentin 2013-04-15 15:55:54 +02:00
parent 3cae8e7124
commit acdb624713
2 changed files with 8 additions and 0 deletions

View File

@ -50,6 +50,7 @@ QNetworkProxy CSyncThread::_proxy;
QString CSyncThread::_csyncConfigDir; // to be able to remove the lock file.
QMutex CSyncThread::_mutex;
QMutex CSyncThread::_syncMutex;
void csyncLogCatcher(CSYNC *ctx,
int verbosity,
@ -303,6 +304,7 @@ struct CSyncRunScopeHelper {
qDebug() << "CSync run took " << t.elapsed() << " Milliseconds";
emit(parent->finished());
parent->_syncMutex.unlock();
}
CSYNC *ctx;
QTime t;
@ -326,6 +328,11 @@ void CSyncThread::handleSyncError(CSYNC *ctx, const char *state) {
void CSyncThread::startSync()
{
if (!_syncMutex.tryLock()) {
qDebug() << Q_FUNC_INFO << "WARNING: Another sync seems to be running. Not starting a new one.";
return;
}
qDebug() << Q_FUNC_INFO << "Sync started";
qDebug() << "starting to sync " << qApp->thread() << QThread::currentThread();

View File

@ -83,6 +83,7 @@ private:
);
static QMutex _mutex;
static QMutex _syncMutex;
static QString _user;
static QString _passwd;
static QNetworkProxy _proxy;