Expand description
Tracked synchronization primitives
Drop-in replacements for tokio::sync::Mutex, RwLock, and Semaphore
with automatic contention tracking and deadlock detection integration.
Tracked synchronization primitives
This module provides drop-in replacements for Tokio’s synchronization primitives
(Mutex, RwLock, Semaphore) that automatically track contention and integrate
with async-inspect’s deadlock detection.
§Example
use async_inspect::sync::Mutex;
#[tokio::main]
async fn main() {
// Create a tracked mutex (drop-in replacement for tokio::sync::Mutex)
let mutex = Mutex::new(42, "my_counter");
// Use it like normal - tracking is automatic!
{
let mut guard = mutex.lock().await;
*guard += 1;
}
// Check contention metrics
let metrics = mutex.metrics();
println!("Acquisitions: {}", metrics.acquisitions);
println!("Contentions: {}", metrics.contentions);
}Structs§
- Acquire
Error - Error returned when acquiring a permit fails because the semaphore is closed.
- Lock
Metrics - Metrics for a tracked synchronization primitive
- Mutex
- A tracked mutex that automatically records contention metrics and integrates with deadlock detection.
- Mutex
Guard - RAII guard for a tracked mutex.
- RwLock
- A tracked read-write lock that automatically records contention metrics and integrates with deadlock detection.
- RwLock
Read Guard - RAII guard for a tracked
RwLockread lock. - RwLock
Write Guard - RAII guard for a tracked
RwLockwrite lock. - Semaphore
- A tracked semaphore that automatically records acquisition metrics and integrates with deadlock detection.
- Semaphore
Permit - RAII guard for a tracked semaphore permit.
Enums§
- TryAcquire
Error - Error returned when trying to acquire a permit fails.