namespace util {
LockFile::LockFile(const std::string& path)
- : m_lock_file(path + ".lock"),
+ :
+#ifndef _WIN32
+ m_alive_file(path + ".alive"),
+#endif
+ m_lock_file(path + ".lock"),
#ifndef _WIN32
m_acquired(false)
#else
}
}
+std::optional<util::TimePoint>
+LockFile::get_last_lock_update()
+{
+ if (const auto stat = Stat::stat(m_alive_file); stat) {
+ return stat.mtime();
+ } else {
+ return std::nullopt;
+ }
+}
+
#else // !_WIN32
void*
{
}
-LongLivedLockFile::LongLivedLockFile(const std::string& path)
- : LockFile(path)
-#ifndef _WIN32
- ,
- m_alive_file(path + ".alive")
-#endif
+LongLivedLockFile::LongLivedLockFile(const std::string& path) : LockFile(path)
{
}
return Util::unlink_tmp(m_alive_file);
}
-std::optional<util::TimePoint>
-LongLivedLockFile::get_last_lock_update()
-{
- if (const auto stat = Stat::stat(m_alive_file); stat) {
- return stat.mtime();
- } else {
- return std::nullopt;
- }
-}
-
#endif
LockFileGuard::LockFileGuard(LockFile& lock_file, Mode mode)
protected:
LockFile(const std::string& path);
+#ifndef _WIN32
+ std::string m_alive_file;
+#endif
private:
std::string m_lock_file;
virtual void on_before_release();
#ifndef _WIN32
bool do_acquire(bool blocking);
+ std::optional<util::TimePoint> get_last_lock_update();
virtual bool on_before_break();
- virtual std::optional<util::TimePoint> get_last_lock_update();
#else
void* do_acquire(bool blocking);
#endif
private:
#ifndef _WIN32
- std::string m_alive_file;
std::thread m_keep_alive_thread;
std::mutex m_stop_keep_alive_mutex;
bool m_stop_keep_alive = false;
void on_after_acquire() override;
void on_before_release() override;
bool on_before_break() override;
- std::optional<util::TimePoint> get_last_lock_update() override;
#endif
};
return true;
}
-inline std::optional<util::TimePoint>
-LockFile::get_last_lock_update()
-{
- return std::nullopt;
-}
-
#endif
} // namespace util