14 #include <sys/types.h>
20 : path_(path), acquired_(false) {}
24 throw std::runtime_error(
"FileLock \"" +
path_.native() +
25 "\" was already acquired.");
30 open(
path_.native().c_str(), O_EXCL | O_CREAT, S_IRUSR | S_IWUSR);
36 throw std::runtime_error(
"Could not close file lock.");
43 std::filesystem::remove(
path_);
bool acquired_
Whether the lock has been acquired.
bool acquire()
Try to acquire the file lock.
~FileLock()
Delete the lock file when the guard is destroyed.
FileLock(const std::filesystem::path &path)
Construct a file lock guard with a lock file at the given path.
std::filesystem::path path_
Path to the file lock.