pub struct LockManager { /* private fields */ }Expand description
Manages concurrent access to workflows through fine-grained locking
The LockManager maintains a mapping of workflow references to mutex guards,
allowing for per-workflow exclusive access control. This approach maximizes
concurrency by only blocking access to the specific workflow being modified,
rather than using a global lock that would block all workflow operations.
§Design Principles
- Fine-grained locking: Each workflow has its own lock
- Lazy initialization: Locks are created on first access
- Shared ownership: Multiple references to the same lock using
Arc - Automatic cleanup: Locks are managed by the
DashMapand cleaned up automatically
§Thread Safety
This struct is completely thread-safe and can be safely accessed from
multiple threads. The Default implementation is used to create the
global singleton instance.
Implementations§
Source§impl LockManager
impl LockManager
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new LockManager instance
Returns a new lock manager with an empty lock table. Locks will be created lazily as workflows are accessed.
§Examples
use aimx::aim::LockManager;
let lock_manager = LockManager::new();Sourcepub fn acquire_workflow_lock(&self, reference: Reference) -> Arc<Mutex<()>>
pub fn acquire_workflow_lock(&self, reference: Reference) -> Arc<Mutex<()>>
Acquires an exclusive write lock for a single workflow by reference
This method retrieves or creates a mutex for the specified workflow reference
and returns a clone of the Arc<Mutex<()>>. The caller must call lock()
on this mutex to actually acquire the exclusive lock.
§Important Notes
- The lock is not acquired by this method - it only provides access to the mutex
- Multiple calls with the same reference return the same mutex
- The lock is released when the
MutexGuardis dropped - For production use, ensure the reference is canonicalized to prevent lock aliasing
§Parameters
reference- The workflow reference to lock
§Returns
An Arc<Mutex<()>> that can be used to acquire the exclusive lock
§Examples
use aimx::aim::LockManager;
use aimx::Reference;
use std::sync::Arc;
let lock_manager = LockManager::new();
let reference = Reference::One("my_workflow".to_string());
// Get the mutex for this workflow
let mutex = lock_manager.acquire_workflow_lock(reference);
// Actually acquire the lock
let _guard = mutex.lock().unwrap();
// Perform exclusive operations...
// Lock is released when `_guard` is droppedNOTE: I plan to probably add an fs lock mechanism to this at some point in the future.