Expand description
A thread-safe key-based locking mechanism for managing concurrent access to resources.
This crate provides a flexible lock manager that allows fine-grained locking based on keys. It supports both single-key and batch locking operations with RAII-style lock guards.
§Features
- Thread-safe key-based locking
- Support for both single key and batch locking operations
- RAII-style lock guards
- Configurable capacity and sharding
§Examples
Single key locking:
use batch_lock::LockManager;
let lock_manager = LockManager::<String>::new();
let key = "resource_1".to_string();
let guard = lock_manager.lock(&key);
// Critical section - exclusive access guaranteed
// Guard automatically releases lock when dropped
Batch locking:
use batch_lock::LockManager;
use std::collections::BTreeSet;
let lock_manager = LockManager::<String>::new();
let mut keys = BTreeSet::new();
keys.insert("resource_1".to_string());
keys.insert("resource_2".to_string());
let guard = lock_manager.batch_lock(&keys);
// Critical section - exclusive access to all keys guaranteed
// Guard automatically releases all locks when dropped
Structs§
- Batch
Lock Guard - RAII guard for multiple locked keys.
- Lock
Guard - RAII guard for a single locked key.
- Lock
Manager - A thread-safe lock manager that provides key-based locking capabilities.