Skip to main content

HostLock

Struct HostLock 

Source
pub struct HostLock { /* private fields */ }
Expand description

A held lock. Releasing it is dropping it.

There is no release() returning a Result, deliberately: releasing is closing a file descriptor, the kernel does it whether this program asks or not, and an API that suggested release could fail would invite a caller to handle a failure that does not exist.

Implementations§

Source§

impl HostLock

Source

pub fn try_acquire(paths: &AppPaths, kind: LockKind) -> Result<Self, LockError>

Takes the lock, or reports who has it, without waiting.

§Errors

LockError::Held when another process has it, LockError::Io when the lock file cannot be opened, and LockError::Identity when this process cannot describe itself.

Source

pub fn acquire( paths: &AppPaths, kind: LockKind, wait: Duration, ) -> Result<Self, LockError>

Takes the lock, retrying until wait elapses.

e1 takes the allocation lock before each runtime it creates, and brief contention there is expected rather than exceptional, so waiting a little is the right default for that caller. The single-instance lock should normally use HostLock::try_acquire: a second agent is a configuration problem, and waiting for it makes the problem quieter rather than fixing it.

§This blocks the calling thread

The retry loop is std::thread::sleep, not a timer an executor can park. e1 takes the allocation lock from inside async reconciliation, and calling this directly from a tokio task blocks a worker thread for up to wait — starving every other task scheduled on it, and with a current-thread runtime deadlocking against the very task that would release the lock. Async callers must wrap it in tokio::task::spawn_blocking, which is also where the returned HostLock should then live, since dropping it is the release.

HostLock::try_acquire does not block and is safe to call inline.

§Errors

As HostLock::try_acquire, reporting the last holder seen.

Source

pub fn try_acquire_at(path: &Path, kind: LockKind) -> Result<Self, LockError>

HostLock::try_acquire against an explicit path.

§Errors

As HostLock::try_acquire.

Source

pub fn acquire_at( path: &Path, kind: LockKind, wait: Duration, ) -> Result<Self, LockError>

HostLock::acquire against an explicit path.

§Errors

As HostLock::try_acquire.

Source

pub fn holder_of(path: &Path) -> Result<Option<LockHolder>, LockError>

Reads the holder record of a lock without trying to take it.

Answers Ok(None) when the file does not exist or carries no readable record. It deliberately says nothing about whether the lock is held: the record outlives its writer by design, and the only authority on whether a lock is free is trying to take it.

§Errors

LockError::Io when the file exists but cannot be read.

Source

pub fn path(&self) -> &Path

Where the lock file is.

Source

pub const fn kind(&self) -> LockKind

Which lock this is.

Source

pub fn recorded_holder_is_live(path: &Path) -> Result<bool, LockError>

Whether the recorded holder of path is still running.

For diagnostics — host show reporting a lock whose record names a process that no longer exists tells an operator something a bare “locked/unlocked” does not.

§Errors

LockError::Io when the record cannot be read.

Trait Implementations§

Source§

impl Debug for HostLock

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more