52 const std::filesystem::path lockPath;
72 FileLock(
const std::filesystem::path& lockPath,
bool lockNonblocking =
true) : lockPath(lockPath) {
74 fd = open(lockPath.c_str(), O_RDWR | O_CREAT, 0666);
81 if ((locked = flock(fd, LOCK_EX | (lockNonblocking ==
true ? LOCK_NB : 0)) == 0) ==
false) {
92 auto _cppStr = lockPath.string();
93 auto str = _cppStr.c_str();
100 FILE_FLAG_DELETE_ON_CLOSE,
104 if (fd == INVALID_HANDLE_VALUE) {
105 DWORD err = GetLastError();
151 if (std::filesystem::exists(lockPath)) {
152 std::filesystem::remove(lockPath);
155 if (fd != INVALID_HANDLE_VALUE && CloseHandle(fd)) {
156 auto _cppStr = lockPath.string();
157 auto str = _cppStr.c_str();
193#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201907L) || __cplusplus >= 201907L)
194 [[nodiscard(
"Ignoring the return value of dynamicAcquireLock results in the immediate unlock of the returned lock")]]
199 const std::filesystem::path& path,
200 std::function<
bool()> control,
201 unsigned int sleepSeconds = 1
205 std::shared_ptr<FileLock> lock = std::make_shared<FileLock>(path,
true);
206 if (lock->hasLock()) {
209 }
catch (
const Errors& e) {
214 if (sleepSeconds != 0) {
215 std::this_thread::sleep_for(std::chrono::seconds(sleepSeconds));
Definition FileLock.hpp:44
FileLock(const FileLock &)=delete
bool hasLock()
Definition FileLock.hpp:132
~FileLock()
Definition FileLock.hpp:117
FileLock & operator=(const FileLock &)=delete
void unlock()
Definition FileLock.hpp:141
FileLock(const std::filesystem::path &lockPath, bool lockNonblocking=true)
Definition FileLock.hpp:72
Errors
Definition FileLock.hpp:57
static std::shared_ptr< FileLock > dynamicAcquireLock(const std::filesystem::path &path, std::function< bool()> control, unsigned int sleepSeconds=1)
Definition FileLock.hpp:198
Definition CaptureStream.hpp:6