Expand description

PLEASE NOTE: THIS CRATE HAS BEEN RENAMED

It used to be proclock, but it’s been renamed to proc-lock.

Please update your dependencies to receive newer versions.


A simple cross-process locking API.

Implementation

This crate uses fs2 to exclusively lock files, and provides a convenient API to use this mechanism for synchronizing between multiple processes.

Quick Start

Installation

In your Cargo.toml file, add:

[dependencies]
proclock = "*"

Using the API directly

use proclock::{lock, LockPath};

let lock_path = LockPath::Tmp("my_lock.lock");
let guard = lock(&lock_path).unwrap();
// Until `guard` is dropped, this code section is atomic across multiple processes.
// ...
drop(guard);

Using macros

use proclock::proclock;

fn main() {
    // A lock will be acquired at the beginning of this function, and will be released at the end.
    a_sensitive_function();
}

#[proclock(name = "my_lock.lock")]
fn a_sensitive_function() {}

Structs

This struct releases the lock on Drop, similar to MutexGuard’s behaviour

Enums

Represents the path in which the lock should be created.

Functions

Locks the file in a blocking manner.

Locks the file in a non-blocking manner, i.e return an error if the file is locked.

Type Definitions

Attribute Macros

Wraps the annotated function with a lock that is released when the function is returned.