QLockFile: Use QDeadlineTimer in tryLock
This simplifies the code a bit. Change-Id: Ifc295639c8cf4ddcaa69fffd146f7535d646cb15 Reviewed-by: David Faure <david.faure@kdab.com>bb10
parent
1a09c599b3
commit
eebdb16c63
|
|
@ -42,7 +42,7 @@
|
|||
#include "qlockfile_p.h"
|
||||
|
||||
#include <QtCore/qthread.h>
|
||||
#include <QtCore/qelapsedtimer.h>
|
||||
#include <QtCore/qdeadlinetimer.h>
|
||||
#include <QtCore/qdatetime.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
|
@ -210,9 +210,7 @@ bool QLockFile::lock()
|
|||
bool QLockFile::tryLock(int timeout)
|
||||
{
|
||||
Q_D(QLockFile);
|
||||
QElapsedTimer timer;
|
||||
if (timeout > 0)
|
||||
timer.start();
|
||||
QDeadlineTimer timer(qMax(timeout, -1)); // QDT only takes -1 as "forever"
|
||||
int sleepTime = 100;
|
||||
forever {
|
||||
d->lockError = d->tryLock_sys();
|
||||
|
|
@ -235,7 +233,7 @@ bool QLockFile::tryLock(int timeout)
|
|||
}
|
||||
break;
|
||||
}
|
||||
if (timeout == 0 || (timeout > 0 && timer.hasExpired(timeout)))
|
||||
if (timer.hasExpired())
|
||||
return false;
|
||||
QThread::msleep(sleepTime);
|
||||
if (sleepTime < 5 * 1000)
|
||||
|
|
|
|||
Loading…
Reference in New Issue