Module sync

Module sync 

Source
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§

AcquireError
Error returned when acquiring a permit fails because the semaphore is closed.
LockMetrics
Metrics for a tracked synchronization primitive
Mutex
A tracked mutex that automatically records contention metrics and integrates with deadlock detection.
MutexGuard
RAII guard for a tracked mutex.
RwLock
A tracked read-write lock that automatically records contention metrics and integrates with deadlock detection.
RwLockReadGuard
RAII guard for a tracked RwLock read lock.
RwLockWriteGuard
RAII guard for a tracked RwLock write lock.
Semaphore
A tracked semaphore that automatically records acquisition metrics and integrates with deadlock detection.
SemaphorePermit
RAII guard for a tracked semaphore permit.

Enums§

TryAcquireError
Error returned when trying to acquire a permit fails.