commit | 7bb89187c5559dadc474598604a96cdd1ee08f6e | [log] [tgz] |
---|---|---|
author | Andrew Walbran <[email protected]> | Mon Nov 20 20:18:58 2023 +0000 |
committer | Automerger Merge Worker <[email protected]> | Mon Nov 20 20:18:58 2023 +0000 |
tree | 7b96be3a97e36557820b6838dcd0ab5c52375c5e | |
parent | 7abde901493660e484533d9b49e20338bb3078b2 [diff] | |
parent | 1bd86ed7938337a7f96e2ce19dfe09b0f173aaad [diff] |
Migrate to cargo_embargo. am: c7430c0513 am: d995cd8de6 am: 1bd86ed793 Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/named-lock/+/2837827 Change-Id: I6648684950c42f49421a65924cb9b25b7ba9eca7 Signed-off-by: Automerger Merge Worker <[email protected]>
This crate provides a simple and cross-platform implementation of named locks. You can use this to lock sections between processes.
use named_lock::NamedLock; use named_lock::Result; fn main() -> Result<()> { let lock = NamedLock::create("foobar")?; let _guard = lock.lock()?; // Do something... Ok(()) }
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
.