[−][src]Struct gstuff::FileLock
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: f64The time in seconds after which an outdated lock file can be removed.
file: FileThe owned lock file. Removed upon unlock.
Methods
impl<'a> FileLock<'a>[src]
pub fn lock(
lock_path: &'a dyn AsRef<Path>,
ttl_sec: f64
) -> Result<Option<FileLock<'a>>, String>[src]
lock_path: &'a dyn AsRef<Path>,
ttl_sec: f64
) -> Result<Option<FileLock<'a>>, String>
Tries to obtain a file lock.
Returns None if the file already exists and is recent enough.
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) }
pub fn touch(&self) -> Result<(), String>[src]
Updates the modification time on the lock file. Compile on Linux only as UTIME_NOW and futimens is absent on MacOS.
Trait Implementations
Auto Trait Implementations
impl<'a> !Sync for FileLock<'a>
impl<'a> Unpin for FileLock<'a>
impl<'a> !Send for FileLock<'a>
impl<'a> !UnwindSafe for FileLock<'a>
impl<'a> !RefUnwindSafe for FileLock<'a>
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> From<T> for T[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,