diff options
author | Joel Rosdahl <joel@rosdahl.net> | 2022-12-30 22:00:17 +0100 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2023-01-11 19:42:32 +0100 |
commit | 958cbfee8f4f8da6cc3af0787120f5a2713560f4 (patch) | |
tree | 6d142ce09a38d2513b6aa2596364c4d5a4adfa8d | |
parent | 52f0cfce011289ce49ee67db7cd0f70637aba59c (diff) | |
download | ccache-958cbfee8f4f8da6cc3af0787120f5a2713560f4.tar.gz |
enhance: Make util::LockFile movable
-rw-r--r-- | src/util/LockFile.cpp | 37 | ||||
-rw-r--r-- | src/util/LockFile.hpp | 3 |
2 files changed, 40 insertions, 0 deletions
diff --git a/src/util/LockFile.cpp b/src/util/LockFile.cpp index 26b38e6b..2e5bef32 100644 --- a/src/util/LockFile.cpp +++ b/src/util/LockFile.cpp @@ -82,6 +82,43 @@ LockFile::LockFile(const std::string& path) { } +LockFile::LockFile(LockFile&& other) noexcept + : m_lock_file(std::move(other.m_lock_file)), +#ifndef _WIN32 + m_lock_manager(other.m_lock_manager), + m_alive_file(std::move(other.m_alive_file)), + m_acquired(other.m_acquired) +#else + m_handle(other.m_handle) +#endif +{ +#ifndef _WIN32 + other.m_lock_manager = nullptr; + other.m_acquired = false; +#else + other.m_handle = INVALID_HANDLE_VALUE; +#endif +} + +LockFile& +LockFile::operator=(LockFile&& other) noexcept +{ + if (&other != this) { + m_lock_file = std::move(other.m_lock_file); +#ifndef _WIN32 + m_lock_manager = other.m_lock_manager; + other.m_lock_manager = nullptr; + m_alive_file = std::move(other.m_alive_file); + m_acquired = other.m_acquired; + other.m_acquired = false; +#else + m_handle = other.m_handle; + other.m_handle = INVALID_HANDLE_VALUE; +#endif + } + return *this; +} + void LockFile::make_long_lived( [[maybe_unused]] LongLivedLockFileManager& lock_manager) diff --git a/src/util/LockFile.hpp b/src/util/LockFile.hpp index bdb3f8cb..67d1cb04 100644 --- a/src/util/LockFile.hpp +++ b/src/util/LockFile.hpp @@ -34,6 +34,9 @@ class LockFile : NonCopyable { public: explicit LockFile(const std::string& path); + LockFile(LockFile&& other) noexcept; + + LockFile& operator=(LockFile&& other) noexcept; // Release the lock if previously acquired. ~LockFile(); |