21enum LockType { ltRead, ltWrite };
23void lockFile(
int fd, LockType lockType,
NeverAsync = {});
24kj::Promise<Result<void>> lockFileAsync(
int fd, LockType lockType);
31bool unsafeLockFileSingleThreaded(
int fd, LockType lockType, std::chrono::seconds timeout);
32bool tryLockFile(
int fd, LockType lockType);
33void unlockFile(
int fd);
37 friend kj::Promise<Result<PathLock>> lockPathAsync(
const Path & path, std::string_view waitMsg);
38 friend PathLock lockPath(
const Path & path, std::string_view waitMsg,
NeverAsync);
39 friend std::optional<PathLock> tryLockPath(
const Path & path);
44 PathLock(
AutoCloseFD fd,
const Path & path): fd(std::move(fd)), path(path) {}
46 static std::optional<PathLock>
47 lockImpl(
const Path & path, std::string_view waitMsg,
bool wait,
NeverAsync = {});
50 PathLock(PathLock &&) =
default;
51 PathLock & operator=(PathLock &&) =
default;
57kj::Promise<Result<PathLock>> lockPathAsync(
const Path & path, std::string_view waitMsg =
"");
59std::optional<PathLock> tryLockPath(
const Path & path);
61using PathLocks = std::list<PathLock>;
63PathLocks lockPaths(
const PathSet & paths, std::string_view waitMsg =
"", NeverAsync = {});
64std::optional<PathLocks> tryLockPaths(
const PathSet & paths);
73 unlockFile(fd->get());
75 ignoreExceptionInDestructor();
80 std::unique_ptr<AutoCloseFD, Unlocker> fd;
85 static constexpr struct DontWait {
explicit DontWait() =
default; } dont_wait;
87 FdLock(
AutoCloseFD & fd, LockType lockType, DontWait);
90 static kj::Promise<Result<FdLock>>
91 lockAsync(
AutoCloseFD & fd, LockType lockType, std::string_view waitMsg);
93 bool valid()
const {
return bool(fd); }
Definition file-descriptor.hh:51
Definition pathlocks.hh:36
This file defines two main structs/classes used in nix error handling.
std::string Path
Definition types.hh:28