pub trait AdvisoryFileLock {
// Required methods
fn lock(&self, file_lock_mode: FileLockMode) -> Result<(), FileLockError>;
fn try_lock(
&self,
file_lock_mode: FileLockMode,
) -> Result<(), FileLockError>;
fn unlock(&self) -> Result<(), FileLockError>;
}
Expand description
An advisory lock for files.
An advisory lock provides a mutual-exclusion mechanism among processes which explicitly acquires and releases the lock. Processes that are not aware of the lock will ignore it.
AdvisoryFileLock
provides following features:
- Blocking or non-blocking operations.
- Shared or exclusive modes.
- All operations are thread-safe.
§Notes
AdvisoryFileLock
has following limitations:
- Locks are allowed only on files, but not directories.
Required Methods§
Sourcefn lock(&self, file_lock_mode: FileLockMode) -> Result<(), FileLockError>
fn lock(&self, file_lock_mode: FileLockMode) -> Result<(), FileLockError>
Acquire the advisory file lock.
lock
is blocking; it will block the current thread until it succeeds or errors.
Sourcefn try_lock(&self, file_lock_mode: FileLockMode) -> Result<(), FileLockError>
fn try_lock(&self, file_lock_mode: FileLockMode) -> Result<(), FileLockError>
Try to acquire the advisory file lock.
try_lock
returns immediately.
Sourcefn unlock(&self) -> Result<(), FileLockError>
fn unlock(&self) -> Result<(), FileLockError>
Unlock this advisory file lock.