diff options
author | Joel Rosdahl <joel@rosdahl.net> | 2022-11-10 16:37:08 +0100 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2022-12-13 20:36:55 +0100 |
commit | 4c8873296434e00015d956e55508b37372ba842e (patch) | |
tree | 5329904ec3573f3bcab271ba330ebce78dbdbc21 /src | |
parent | 84609c1038313eebcf91802aa9c049f1fe9dac76 (diff) | |
download | ccache-4c8873296434e00015d956e55508b37372ba842e.tar.gz |
enhance: Allow short-lived lock file to wait for long-lived
Diffstat (limited to 'src')
-rw-r--r-- | src/util/LockFile.cpp | 33 | ||||
-rw-r--r-- | src/util/LockFile.hpp | 13 |
2 files changed, 20 insertions, 26 deletions
diff --git a/src/util/LockFile.cpp b/src/util/LockFile.cpp index f90b7626..4848eb64 100644 --- a/src/util/LockFile.cpp +++ b/src/util/LockFile.cpp @@ -73,7 +73,11 @@ private: 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 @@ -274,6 +278,16 @@ LockFile::do_acquire(const bool blocking) } } +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* @@ -337,12 +351,7 @@ ShortLivedLockFile::ShortLivedLockFile(const std::string& path) : LockFile(path) { } -LongLivedLockFile::LongLivedLockFile(const std::string& path) - : LockFile(path) -#ifndef _WIN32 - , - m_alive_file(path + ".alive") -#endif +LongLivedLockFile::LongLivedLockFile(const std::string& path) : LockFile(path) { } @@ -395,16 +404,6 @@ LongLivedLockFile::on_before_break() 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) diff --git a/src/util/LockFile.hpp b/src/util/LockFile.hpp index 705dd7b8..d5e2f85a 100644 --- a/src/util/LockFile.hpp +++ b/src/util/LockFile.hpp @@ -48,6 +48,9 @@ public: protected: LockFile(const std::string& path); +#ifndef _WIN32 + std::string m_alive_file; +#endif private: std::string m_lock_file; @@ -62,8 +65,8 @@ private: 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 @@ -90,7 +93,6 @@ public: 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; @@ -99,7 +101,6 @@ private: 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 }; @@ -135,12 +136,6 @@ LockFile::on_before_break() return true; } -inline std::optional<util::TimePoint> -LockFile::get_last_lock_update() -{ - return std::nullopt; -} - #endif } // namespace util |