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#[cfg(not(debug_assertions))]
24pub use std::sync::{
25    Condvar, Mutex, MutexGuard, Once, OnceLock, RwLock, RwLockReadGuard, RwLockWriteGuard,
26};
27
28#[cfg(debug_assertions)]
29pub use tracing::{
30    Condvar, Mutex, MutexGuard, Once, OnceLock, RwLock, RwLockReadGuard, RwLockWriteGuard,
31};
32
33#[cfg(all(has_std__sync__LazyLock, debug_assertions))]
34pub use tracing::LazyLock;
35
36#[cfg(all(has_std__sync__LazyLock, not(debug_assertions)))]
37pub use std::sync::LazyLock;
38
39/// Dependency tracing versions of [`std::sync`].
40pub mod tracing;