From: Joel Rosdahl Date: Sun, 17 Mar 2024 11:37:55 +0000 (+0100) Subject: fix: Use Windows lockfile implementation on MSYS2 X-Git-Tag: v4.10~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c6a6e6accefe9e79601e56be5f7438cb593ff016;p=thirdparty%2Fccache.git fix: Use Windows lockfile implementation on MSYS2 Likely fixes #1415. --- diff --git a/src/ccache/util/LockFile.cpp b/src/ccache/util/LockFile.cpp index 43b62cd1..4a917928 100644 --- a/src/ccache/util/LockFile.cpp +++ b/src/ccache/util/LockFile.cpp @@ -40,7 +40,7 @@ const uint32_t k_min_sleep_time_ms = 10; const uint32_t k_max_sleep_time_ms = 50; -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(__CYGWIN__) const util::Duration k_staleness_limit(2); #endif @@ -77,7 +77,7 @@ namespace util { LockFile::LockFile(const fs::path& path) : m_lock_file(pstr(path).str() + ".lock"), -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(__CYGWIN__) m_alive_file(pstr(path).str() + ".alive"), m_acquired(false) #else @@ -88,7 +88,7 @@ LockFile::LockFile(const fs::path& path) LockFile::LockFile(LockFile&& other) noexcept : m_lock_file(std::move(other.m_lock_file)), -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(__CYGWIN__) m_lock_manager(other.m_lock_manager), m_alive_file(std::move(other.m_alive_file)), m_acquired(other.m_acquired) @@ -96,7 +96,7 @@ LockFile::LockFile(LockFile&& other) noexcept m_handle(other.m_handle) #endif { -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(__CYGWIN__) other.m_lock_manager = nullptr; other.m_acquired = false; #else @@ -109,7 +109,7 @@ LockFile::operator=(LockFile&& other) noexcept { if (&other != this) { m_lock_file = std::move(other.m_lock_file); -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(__CYGWIN__) m_lock_manager = other.m_lock_manager; other.m_lock_manager = nullptr; m_alive_file = std::move(other.m_alive_file); @@ -127,7 +127,7 @@ void LockFile::make_long_lived( [[maybe_unused]] LongLivedLockFileManager& lock_manager) { -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(__CYGWIN__) m_lock_manager = &lock_manager; if (acquired()) { m_lock_manager->register_alive_file(m_alive_file); @@ -157,7 +157,7 @@ LockFile::release() } LOG("Releasing {}", m_lock_file); -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(__CYGWIN__) if (m_lock_manager) { m_lock_manager->deregister_alive_file(m_alive_file); } @@ -167,7 +167,7 @@ LockFile::release() CloseHandle(m_handle); #endif LOG("Released {}", m_lock_file); -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(__CYGWIN__) m_acquired = false; #else m_handle = INVALID_HANDLE_VALUE; @@ -177,7 +177,7 @@ LockFile::release() bool LockFile::acquired() const { -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(__CYGWIN__) return m_acquired; #else return m_handle != INVALID_HANDLE_VALUE; @@ -189,7 +189,7 @@ LockFile::acquire(const bool blocking) { ASSERT(!acquired()); -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(__CYGWIN__) m_acquired = do_acquire(blocking); #else m_handle = do_acquire(blocking); @@ -197,7 +197,7 @@ LockFile::acquire(const bool blocking) if (acquired()) { LOG("Acquired {}", m_lock_file); -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(__CYGWIN__) LOG("Creating {}", m_alive_file); const auto result = write_file(m_alive_file, ""); if (!result) { @@ -214,7 +214,7 @@ LockFile::acquire(const bool blocking) return acquired(); } -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(__CYGWIN__) bool LockFile::do_acquire(const bool blocking) @@ -351,7 +351,7 @@ LockFile::get_last_lock_update() } } -#else // !_WIN32 +#else // !defined(_WIN32) && !defined(__CYGWIN__) void* LockFile::do_acquire(const bool blocking) @@ -408,6 +408,6 @@ LockFile::do_acquire(const bool blocking) return handle; } -#endif // !_WIN32 +#endif // !defined(_WIN32) && !defined(__CYGWIN__) } // namespace util diff --git a/src/ccache/util/LockFile.hpp b/src/ccache/util/LockFile.hpp index 95b98405..6ad73c2b 100644 --- a/src/ccache/util/LockFile.hpp +++ b/src/ccache/util/LockFile.hpp @@ -59,7 +59,7 @@ public: private: std::filesystem::path m_lock_file; -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(__CYGWIN__) LongLivedLockFileManager* m_lock_manager = nullptr; std::filesystem::path m_alive_file; bool m_acquired; @@ -68,7 +68,7 @@ private: #endif bool acquire(bool blocking); -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(__CYGWIN__) bool do_acquire(bool blocking); std::optional get_last_lock_update(); #else diff --git a/src/ccache/util/wincompat.hpp b/src/ccache/util/wincompat.hpp index f2f2a798..1af4cdf7 100644 --- a/src/ccache/util/wincompat.hpp +++ b/src/ccache/util/wincompat.hpp @@ -18,7 +18,7 @@ #pragma once -#ifdef _WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) # include # define NOMINMAX 1 @@ -101,4 +101,4 @@ const mode_t S_IWUSR = mode_t{_S_IWRITE}; #else # define DLLIMPORT -#endif // _WIN32 +#endif // defined(_WIN32) || defined(__CYGWIN__)