1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
5 #include "cmConfigure.h" // IWYU pragma: keep
10 # include <windows.h> // HANDLE
13 class cmFileLockResult;
16 * @brief Cross-platform file locking.
17 * @details Under the hood this class use 'fcntl' for Unix-like platforms and
18 * 'LockFileEx'/'UnlockFileEx' for Win32 platform. Locks are exclusive and
27 cmFileLock(cmFileLock const&) = delete;
28 cmFileLock(cmFileLock&&) noexcept;
29 cmFileLock& operator=(cmFileLock const&) = delete;
30 cmFileLock& operator=(cmFileLock&&) noexcept;
33 * @brief Lock the file.
34 * @param timeoutSec Lock timeout. If -1 try until success or fatal error.
36 cmFileLockResult Lock(const std::string& filename, unsigned long timeoutSec);
39 * @brief Unlock the file.
41 cmFileLockResult Release();
44 * @brief Check file is locked by this class.
45 * @details This function helps to find double locks (deadlocks) and to do
48 bool IsLocked(const std::string& filename) const;
51 cmFileLockResult OpenFile();
52 cmFileLockResult LockWithoutTimeout();
53 cmFileLockResult LockWithTimeout(unsigned long timeoutSec);
56 HANDLE File = INVALID_HANDLE_VALUE;
57 BOOL LockFile(DWORD flags);
60 int LockFile(int cmd, int type) const;