1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #include "cmFileLock.h"
8 #include "cmFileLockResult.h"
10 // Common implementation
12 cmFileLock::cmFileLock(cmFileLock
&& other
) noexcept
14 this->File
= other
.File
;
15 other
.File
= (decltype(other
.File
))-1;
16 this->Filename
= std::move(other
.Filename
);
19 cmFileLock::~cmFileLock()
21 if (!this->Filename
.empty()) {
22 const cmFileLockResult result
= this->Release();
23 static_cast<void>(result
);
24 assert(result
.IsOk());
28 cmFileLock
& cmFileLock::operator=(cmFileLock
&& other
) noexcept
30 this->File
= other
.File
;
31 other
.File
= (decltype(other
.File
))-1;
32 this->Filename
= std::move(other
.Filename
);
37 cmFileLockResult
cmFileLock::Lock(const std::string
& filename
,
38 unsigned long timeout
)
40 if (filename
.empty()) {
41 // Error is internal since all the directories and file must be created
42 // before actual lock called.
43 return cmFileLockResult::MakeInternal();
46 if (!this->Filename
.empty()) {
47 // Error is internal since double-lock must be checked in class
48 // cmFileLockPool by the cmFileLock::IsLocked method.
49 return cmFileLockResult::MakeInternal();
52 this->Filename
= filename
;
53 cmFileLockResult result
= this->OpenFile();
55 if (timeout
== static_cast<unsigned long>(-1)) {
56 result
= this->LockWithoutTimeout();
58 result
= this->LockWithTimeout(timeout
);
63 this->Filename
.clear();
69 bool cmFileLock::IsLocked(const std::string
& filename
) const
71 return filename
== this->Filename
;
75 // NOLINTNEXTLINE(bugprone-suspicious-include)
76 # include "cmFileLockWin32.cxx"
78 // NOLINTNEXTLINE(bugprone-suspicious-include)
79 # include "cmFileLockUnix.cxx"