60 #include "../vmisc/diagnostic.h"
75 template <
typename Guarded>
79 explicit VLockGuard(
const QString& lockName,
int stale = 0,
int timeout = 0);
81 template <
typename Alloc>
82 VLockGuard(
const QString& lockName, Alloc a,
int stale = 0,
int timeout=0);
84 template <
typename Alloc,
typename Delete>
85 VLockGuard(
const QString& lockName, Alloc a, Delete d,
int stale = 0,
int timeout=0);
98 std::shared_ptr<QLockFile>
lock;
101 bool TryLock(const QString &lockName,
int stale,
int timeout);
105 template <typename Guarded>
109 if (
TryLock(lockName, stale, timeout))
111 holder.reset(
new Guarded());
118 template <
typename Guarded>
template <
typename Alloc>
122 if (
TryLock(lockName, stale, timeout))
129 template <
typename Guarded>
template <
typename Alloc,
typename Delete>
131 : holder(nullptr), lockError(0), lockFile(), lock(nullptr)
133 if (
TryLock(lockName, stale, timeout))
140 template <
typename Guarded>
147 template <
typename Guarded>
154 template <
typename Guarded>
157 return holder !=
nullptr;
161 template <
typename Guarded>
168 template <
typename Guarded>
173 lockFile = lockName + QLatin1String(
".lock");
174 #if defined(Q_OS_UNIX)
175 QFileInfo info(lockFile);
176 lockFile = info.absolutePath() + QLatin1String(
"/.") + info.fileName();
178 lock.reset(
new QLockFile(lockFile));
180 lock->setStaleLockTime(stale);
181 lock->tryLock(timeout);
183 if (QLockFile::LockFailedError == lock->error())
189 lock->removeStaleLockFile();
190 lock->tryLock(timeout);
197 #if defined(Q_OS_WIN)
200 SetFileAttributesW(lockFile.toStdWString().c_str(), FILE_ATTRIBUTE_HIDDEN);
210 QT_WARNING_DISABLE_INTEL(1418)
212 template <typename Guarded>
218 template <
typename Guarded,
typename Alloc>
225 template <
typename Guarded,
typename Alloc,
typename Del>
VLockGuard(const QString &lockName, int stale=0, int timeout=0)
const std::shared_ptr< Guarded > & GetProtected() const
QString GetLockFile() const
bool TryLock(const QString &lockName, int stale, int timeout)
std::shared_ptr< Guarded > holder
std::shared_ptr< QLockFile > lock
QT_WARNING_PUSH void VlpCreateLock(std::shared_ptr< VLockGuard< Guarded >> &r, const QString &lockName, int stale=0, int timeout=0)