pub struct FileLockManager { /* private fields */ }Expand description
File-based lock manager for cross-process locking.
Locks are represented as files in a directory. File existence indicates allocation state, and flock(2) is used for actual locking.
§Directory Structure
lock_dir/
├── 0 # Lock file for ID 0
├── 1 # Lock file for ID 1
└── ...§Example
ⓘ
let manager = FileLockManager::new("/var/run/boxlite/locks")?;
let lock_id = manager.allocate()?;
let lock = manager.retrieve(lock_id)?;
lock.lock(); // Uses flock(LOCK_EX)
// ... critical section ...
lock.unlock(); // Uses flock(LOCK_UN)Implementations§
Source§impl FileLockManager
impl FileLockManager
Trait Implementations§
Source§impl LockManager for FileLockManager
impl LockManager for FileLockManager
Source§fn allocate(&self) -> BoxliteResult<LockId>
fn allocate(&self) -> BoxliteResult<LockId>
Allocate a new lock and return its unique ID. Read more
Source§fn retrieve(&self, id: LockId) -> BoxliteResult<Arc<dyn Locker>>
fn retrieve(&self, id: LockId) -> BoxliteResult<Arc<dyn Locker>>
Retrieve a lock by its ID. Read more
Source§fn allocate_and_retrieve(&self, id: LockId) -> BoxliteResult<Arc<dyn Locker>>
fn allocate_and_retrieve(&self, id: LockId) -> BoxliteResult<Arc<dyn Locker>>
Mark a lock with the given ID as allocated and return it. Read more
Source§fn free(&self, id: LockId) -> BoxliteResult<()>
fn free(&self, id: LockId) -> BoxliteResult<()>
Free a lock, allowing it to be reallocated. Read more
Source§fn available(&self) -> BoxliteResult<Option<u32>>
fn available(&self) -> BoxliteResult<Option<u32>>
Get the number of available (unallocated) locks. Read more
Source§fn allocated_count(&self) -> BoxliteResult<u32>
fn allocated_count(&self) -> BoxliteResult<u32>
Get the number of currently allocated locks.
Source§fn clear_all_locks(&self) -> BoxliteResult<()>
fn clear_all_locks(&self) -> BoxliteResult<()>
Clear all allocated locks. Read more
Auto Trait Implementations§
impl !Freeze for FileLockManager
impl RefUnwindSafe for FileLockManager
impl Send for FileLockManager
impl Sync for FileLockManager
impl Unpin for FileLockManager
impl UnsafeUnpin for FileLockManager
impl UnwindSafe for FileLockManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request