Qubit Lock
Lock-focused utilities for the Qubit Rust libraries. The crate provides synchronous and asynchronous lock wrappers plus monitor-style coordination.
Features
ArcMutex,ArcRwLock: parking_lot-based synchronous lock wrappers withArcbuilt in.ArcStdMutex,ArcStdRwLock: standard-library lock wrappers for callers that need poison semantics.ArcAsyncMutex,ArcAsyncRwLock: Tokio-based asynchronous lock wrappers enabled by the defaultasyncfeature.Monitor,ArcMonitor,MonitorGuard: parking_lot-based condition coordination.StdMonitor,ArcStdMonitor,StdMonitorGuard: std-based condition coordination.- Closure-based APIs that keep lock acquisition and release scoped to one call.
Arc*wrappers implementDerefandAsRef, so the native guard-based APIs of the wrapped primitive remain available when needed.
Installation
[]
= "0.7"
The async wrappers use Tokio synchronization primitives and are enabled by default. For sync-only users that want to avoid Tokio in the dependency graph:
[]
= { = "0.7", = false }
If your application creates a Tokio runtime, enable the appropriate Tokio
runtime features in your own Cargo.toml, such as rt or rt-multi-thread.
AsyncLock returns Send futures: ArcAsyncMutex<T> implements it for
T: Send, while ArcAsyncRwLock<T> implements it for T: Send + Sync.
Migration from 0.6
Version 0.7 contains intentional breaking API cleanup:
ArcRwLocknow wrapsparking_lot::RwLockand no longer uses poisoning. After a panic while holding the lock, future acquisitions continue normally andtry_read/try_writedo not returnTryLockError::Poisoned.- Use
ArcStdRwLockwhen standard-librarystd::sync::RwLockpoisoning semantics are required. qubit_lock::lockandqubit_lock::monitorare no longer public modules. Import public types directly from the crate root.- Wrapper types now implement convenient
From<T>andDefaultconstructors where applicable.
Quick Start
Synchronous lock
use ;
Native lock APIs
Arc* wrappers can still use the native lock APIs of their wrapped
primitives through Deref or AsRef.
use ;
For ArcRwLock and ArcAsyncRwLock, the closure-based read and write
methods have the same names as the native guard-based methods. When Lock or
AsyncLock is in scope, use lock.as_ref().read() or explicit dereferencing
such as (*lock).read() to call the native guard API.
Monitor
use ArcMonitor;
Project Layout
src/lock: lock traits and lock wrappers.src/monitor: parking_lot and std monitor primitives.tests/lock: lock behavior tests.tests/monitor: monitor behavior tests.tests/docs: README and doctest consistency tests.
Quality Checks
From a repository checkout:
License
Apache-2.0