Nix 2.93.3
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
pathlocks.hh File Reference
#include "lix/libutil/error.hh"
#include "lix/libutil/file-descriptor.hh"
#include "lix/libutil/result.hh"
#include "lix/libutil/types.hh"
#include <chrono>
#include <kj/async.h>
#include <kj/common.h>

Go to the source code of this file.

Classes

class  nix::PathLock
class  nix::FdLock
struct  nix::FdLock::DontWait

Typedefs

using nix::PathLocks = std::list<PathLock>

Enumerations

enum  LockType { ltRead , ltWrite }

Functions

AutoCloseFD nix::openLockFile (const Path &path, bool create)
void nix::lockFile (int fd, LockType lockType, NeverAsync)
kj::Promise< Result< void > > nix::lockFileAsync (int fd, LockType lockType)
bool nix::unsafeLockFileSingleThreaded (int fd, LockType lockType, std::chrono::seconds timeout)
bool nix::tryLockFile (int fd, LockType lockType)
void nix::unlockFile (int fd)
kj::Promise< Result< PathLock > > nix::lockPathAsync (const Path &path, std::string_view waitMsg="")
PathLock nix::lockPath (const Path &path, std::string_view waitMsg="", NeverAsync={})
std::optional< PathLocknix::tryLockPath (const Path &path)
PathLocks nix::lockPaths (const PathSet &paths, std::string_view waitMsg, NeverAsync)
std::optional< PathLocks > nix::tryLockPaths (const PathSet &paths)

Function Documentation

◆ openLockFile()

AutoCloseFD nix::openLockFile ( const Path & path,
bool create )

Open (possibly create) a lock file and return the file descriptor. -1 is returned if create is false and the lock could not be opened because it doesn't exist. Any other error throws an exception.

◆ unsafeLockFileSingleThreaded()

bool nix::unsafeLockFileSingleThreaded ( int fd,
LockType lockType,
std::chrono::seconds timeout )

Same as lockFile, but with a timeout. This timeout uses the POSIX alarm facility and a SIGALRM handler. Using this function from multiple threads in the same process is not safe: all SIGALRM handlers set previously will be overwritten while this function is executing and are restored on return.