Expand description
Allows several threads or processes to compete for a shared resource by tracking resource ownership with a file.
If the lock file is older than ttl_sec
then it is removed, allowing us to recover from a thread or process dying while holding the lock.
Fields
lock_path: &'a dyn AsRef<Path>
Filesystem path of the lock file.
ttl_sec: f64
The time in seconds after which an outdated lock file can be removed.
file: File
The owned lock file. Removed upon unlock.
Implementations
sourceimpl<'a> FileLock<'a>
impl<'a> FileLock<'a>
sourcepub fn lock(
lock_path: &'a dyn AsRef<Path>,
ttl_sec: f64
) -> Result<Option<FileLock<'a>>, String>
pub fn lock(
lock_path: &'a dyn AsRef<Path>,
ttl_sec: f64
) -> Result<Option<FileLock<'a>>, String>
Tries to obtain a file lock.
No blocking. Returns None
if the file already exists and is recent enough (= locked).
The returned structure will automatically remove the lock file when dropped.
if let Some (lock) = try_s! (FileLock::lock (&"something.lock", 600.)) {
// ... Your code here ...
drop (lock)
}
Trait Implementations
Auto Trait Implementations
impl<'a> !RefUnwindSafe for FileLock<'a>
impl<'a> !Send for FileLock<'a>
impl<'a> !Sync for FileLock<'a>
impl<'a> Unpin for FileLock<'a>
impl<'a> !UnwindSafe for FileLock<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more