tree: 644bc5769d5ee2b00d96ec593ce626ae13039ec6 [path history] [tgz]
  1. src/
  2. .android-checksum.json
  3. .cargo-checksum.json
  4. Android.bp
  5. Cargo.toml
  6. cargo_embargo.json
  7. CHANGELOG.md
  8. LICENSE
  9. METADATA
  10. MODULE_LICENSE_MIT
  11. README.md
  12. rustfmt.toml
crates/named-lock/README.md

named-lock

license crates.io docs

This crate provides a simple and cross-platform implementation of named locks. You can use this to lock sections between processes.

Example

use named_lock::NamedLock;
use named_lock::Result;

fn main() -> Result<()> {
    let lock = NamedLock::create("foobar")?;
    let _guard = lock.lock()?;

    // Do something...

    Ok(())
}

Implementation

On UNIX this is implemented by using files and flock. The path of the created lock file will be $TMPDIR/<name>.lock, or /tmp/<name>.lock if TMPDIR environment variable is not set.

On Windows this is implemented by creating named mutex with CreateMutexW.