9#include <QtCore/qthread.h>
10#include <QtCore/qcoreapplication.h>
11#include <QtCore/qdeadlinetimer.h>
12#include <QtCore/qdatetime.h>
13#include <QtCore/qfileinfo.h>
200 return d->staleLockTime;
232 return tryLock(std::chrono::milliseconds::max());
280 using namespace std::chrono_literals;
281 using Msec = std::chrono::milliseconds;
287 Msec sleepTime = 100ms;
289 d->lockError =
d->tryLock_sys();
290 switch (
d->lockError) {
298 if (!
d->isLocked &&
d->isApparentlyStale()) {
300 qInfo(
"QLockFile: Lock file '%ls' has a modification time in the future",
qUtf16Printable(
d->fileName));
304 if (rmlock.tryLock()) {
305 if (
d->isApparentlyStale() &&
d->removeStaleLock())
313 if (remainingTime == 0ms)
316 if (sleepTime > remainingTime)
317 sleepTime = remainingTime;
370 *hostname =
info.hostname;
372 *appname =
info.appname;
394 if (pidLine.isEmpty())
399 hostNameLine.chop(1);
410 info->hostid = hostId;
411 info->bootid = bootId;
412 info->pid = pidLine.toLongLong(&
ok);
413 return ok &&
info->pid > 0;
421 if (!
info.hostid.isEmpty()) {
424 if (!ourHostId.isEmpty())
425 sameHost = (ourHostId ==
info.hostid);
429 if (!
info.bootid.isEmpty()) {
440 using namespace std::chrono;
462 qWarning(
"removeStaleLockFile can only be called when not holding the lock");
465 return d->removeStaleLock();
static QByteArray number(int, int base=10)
Returns a byte-array representing the whole number n as text.
static qint64 applicationPid() Q_DECL_CONST_FUNCTION
\inmodule QtCore\reentrant
qint64 msecsTo(const QDateTime &) const
Returns the number of milliseconds from this datetime to the other datetime.
static QDateTime currentDateTimeUtc()
QDateTime lastModified() const
Returns the date and time when the file was last modified.
bool isApparentlyStale() const
static bool isProcessRunning(qint64 pid, const QString &appname)
std::chrono::milliseconds staleLockTime
static Q_CORE_EXPORT QString processNameByPid(qint64 pid)
QByteArray lockFileContents() const
void setStaleLockTime(int)
Sets staleLockTime to be the time in milliseconds after which a lock file is considered stale.
QScopedPointer< QLockFilePrivate > d_ptr
~QLockFile()
Destroys the lock file object.
bool tryLock(int timeout)
Attempts to create the lock file.
QLockFile(const QString &fileName)
Constructs a new lock file object.
bool isLocked() const
Returns true if the lock was acquired by this QLockFile instance, otherwise returns false.
std::chrono::milliseconds staleLockTimeAsDuration() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
int staleLockTime() const
Returns the time in milliseconds after which a lock file is considered stale.
LockError
This enum describes the result of the last call to lock() or tryLock().
bool removeStaleLockFile()
Attempts to forcefully remove an existing lock file.
LockError error() const
Returns the lock file error status.
bool getLockInfo(qint64 *pid, QString *hostname, QString *appname) const
Retrieves information about the current owner of the lock file.
void unlock()
Releases the lock, by deleting the lock file.
bool lock()
Creates the lock file.
QString fileName() const
Returns the file name of the lock file.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QByteArray bootUniqueId()
static QByteArray machineUniqueId()
static QString machineHostName()
static void sleep(unsigned long)
std::chrono::milliseconds remainingTimeAsDuration() const
Combined button and popup list for selecting options.
static QString machineName()
static bool getLockInfo_helper(const QString &fileName, LockFileInfo *info)
GLenum GLenum GLsizei count
GLbitfield GLuint64 timeout
[4]
#define qUtf16Printable(string)
QString qEnvironmentVariable(const char *varName, const QString &defaultValue)