1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//! Instrumented lock types.
//!
//! This module defines a set of instrumented wrappers for the lock
//! types used in `wgpu-core` ([`Mutex`], [`RwLock`], and
//! [`SnatchLock`]) that help us understand and validate `wgpu-core`
//! synchronization.
//!
//! - The [`ranked`] module defines lock types that perform run-time
//! checks to ensure that each thread acquires locks only in a
//! specific order, to prevent deadlocks.
//!
//! - The [`observing`] module defines lock types that record
//! `wgpu-core`'s lock acquisition activity to disk, for later
//! analysis by the `lock-analyzer` binary.
//!
//! - The [`vanilla`] module defines lock types that are
//! uninstrumented, no-overhead wrappers around the standard lock
//! types.
//!
//! To get `ranked`, build with the `wgpu_validate_locks` config set, perhaps
//! with `RUSTFLAGS='--cfg wgpu_validate_locks'`. The `"std"` feature must also
//! be enabled, as `ranked` needs thread-local storage.
//!
//! To get `ranked` only when debug assertions are also enabled, build with the
//! `wgpu_validate_locks_debug` config set. The `wgpu` crate selects this via
//! its `.cargo/config.toml` file, so lock validation is active by default in
//! `wgpu` CI and `wgpu` development trees, but not in `wgpu`-using applications
//! unless specifically requested.
//!
//! To get `observing`, enable the `"observe_locks"` feature. This also enables
//! `"std"`. You must also ensure that `wgpu_validate_locks` is not set, as that
//! takes precedence --- and it's enabled automatically in debug builds for
//! `wgpu`, as explained above.
//!
//! Otherwise, `wgpu-core` uses the [`vanilla`] module's locks.
//!
//! [`Mutex`]: wgpu_sync::Mutex
//! [`RwLock`]: wgpu_sync::RwLock
//! [`SnatchLock`]: crate::snatch::SnatchLock
// Include all the implementations in the build whenever they can be
// compiled, even if they're not selected, to catch errors and help
// `rust-analyzer` find references.
// requires thread-locals to work
// The `observing` module requires the `serde` and `ron` dependencies
// and the "std" feature for thread-locals. All are enabled by the
// `"observe_locks"` feature.
// If "std" is not enabled, then none of the other modules can be built.
use ranked as chosen;
use observing as chosen;
// We must use `vanilla`:
// - whenever `"std"` is not selected, and
// - whenever neither of the instrumented locks are enabled.
use vanilla as chosen;
pub use ;