[][src]Struct gstuff::FileLock

pub struct FileLock<'a> {
    pub lock_path: &'a dyn AsRef<Path>,
    pub ttl_sec: f64,
    pub file: File,
}

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

impl<'a> FileLock<'a>[src]

pub fn lock(
    lock_path: &'a dyn AsRef<Path>,
    ttl_sec: f64
) -> Result<Option<FileLock<'a>>, String>
[src]

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)
}

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

impl<'a> Debug for FileLock<'a>[src]

impl<'a> Drop for FileLock<'a>[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.