Skip to main content

tracing_mutex/
stdsync.rs

1//! Tracing mutex wrappers for locks found in `std::sync`.
2//!
3//! This module provides wrappers for `std::sync` primitives with exactly the same API and
4//! functionality as their counterparts, with the exception that their acquisition order is tracked.
5//!
6//! Dedicated wrappers that provide the dependency tracing can be found in the [`tracing`] module.
7//! The original primitives are available from [`std::sync`], imported as [`raw`] for convenience.
8//!
9//! If debug assertions are enabled, this module imports the primitives from [`tracing`], otherwise
10//! it will import from [`raw`].
11//!
12//! ```rust
13//! # use tracing_mutex::stdsync::tracing::Mutex;
14//! # use tracing_mutex::stdsync::tracing::RwLock;
15//! let mutex = Mutex::new(());
16//! mutex.lock().unwrap();
17//!
18//! let rwlock = RwLock::new(());
19//! rwlock.read().unwrap();
20//! ```
21pub use std::sync as raw;
22
23// Skip reformatting the combined imports as it duplicates the guards
24#[rustfmt::skip]
25#[cfg(not(debug_assertions))]
26pub use std::sync::{
27    Condvar, Mutex, MutexGuard, Once, OnceLock, RwLock, RwLockReadGuard, RwLockWriteGuard,
28};
29
30#[rustfmt::skip]
31#[cfg(debug_assertions)]
32pub use tracing::{
33    Condvar, Mutex, MutexGuard, Once, OnceLock, RwLock, RwLockReadGuard, RwLockWriteGuard,
34};
35
36#[cfg(all(has_std__sync__LazyLock, debug_assertions))]
37pub use tracing::LazyLock;
38
39#[cfg(all(has_std__sync__LazyLock, not(debug_assertions)))]
40pub use std::sync::LazyLock;
41
42/// Dependency tracing versions of [`std::sync`].
43pub mod tracing;