[−][src]Struct dir_lock::DirLock
A simple file-system-based mutex.
When constructing a value of this type, a directory is created at the specified path.
If a directory already exists, the constructor waits until it's removed.
Dropping a DirLock
removes the corresponding directory.
Since creating a directory if it does not exist is an atomic operation on most operating systems,
this can be used as a quick-and-dirty cross-process mutex.
To guard against processes exiting without properly removing the lock, a file containing the current process ID is created inside the lock. If no process with that ID exists, another process may claim the lock for itself.
Of course, this is still not completely fail-proof since the user or other processes could mess with the lock directory.
This type is a RAII lock guard, but unlocking a directory lock uses I/O and can error, so it is recommended to call drop_async
.
Implementations
impl DirLock<'_>
[src]
pub async fn new(path: &impl AsRef<Path>) -> Result<DirLock<'_>, Error>
[src]
Acquires a directory lock at the given path, without blocking the thread.
See the type-level docs for details.
pub fn new_sync(path: &impl AsRef<Path>) -> Result<DirLock<'_>, Error>
[src]
Blocks the current thread until the lock can be established.
pub async fn drop_async(self) -> Result<(), Error>
[src]
Unlocks this lock without blocking the thread.
Trait Implementations
impl Drop for DirLock<'_>
[src]
pub fn drop(&mut self)
[src]
Unlocks this lock, blocking the current thread while doing so.
Panics
Unlocking a directory lock involves I/O. If an error occurs, this method will panic.
It is recommended to use drop_async
instead, which returns the error.
Auto Trait Implementations
impl<'a> RefUnwindSafe for DirLock<'a>
[src]
impl<'a> Send for DirLock<'a>
[src]
impl<'a> Sync for DirLock<'a>
[src]
impl<'a> Unpin for DirLock<'a>
[src]
impl<'a> UnwindSafe for DirLock<'a>
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
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.
pub 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>,