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
//! Sync instrumentation for `ctx_gates` integration tests.
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
static COUNTING: AtomicBool = AtomicBool::new(false);
static SHOULD_SYNC_READS: AtomicUsize = AtomicUsize::new(0);
static SYNC_CALLS: AtomicUsize = AtomicUsize::new(0);
/// Enable observed `should_sync` / `sync` counting (test-only usage).
pub fn set_counting(enabled: bool) {
COUNTING.store(enabled, Ordering::Relaxed);
}
/// Reset observed counters.
pub fn reset() {
SHOULD_SYNC_READS.store(0, Ordering::Relaxed);
SYNC_CALLS.store(0, Ordering::Relaxed);
}
/// Observed `should_sync()` reads since last [`reset`] while counting is enabled.
pub fn should_sync_reads() -> usize {
SHOULD_SYNC_READS.load(Ordering::Relaxed)
}
/// Observed `sync()` calls since last [`reset`] while counting is enabled.
pub fn sync_calls() -> usize {
SYNC_CALLS.load(Ordering::Relaxed)
}
pub(crate) fn record_should_sync_read() {
if COUNTING.load(Ordering::Relaxed) {
SHOULD_SYNC_READS.fetch_add(1, Ordering::Relaxed);
}
}
pub(crate) fn record_sync_call() {
if COUNTING.load(Ordering::Relaxed) {
SYNC_CALLS.fetch_add(1, Ordering::Relaxed);
}
}
/// T10 Task 5 review (F1, second round): counts the additive pre-read the
/// non-transactional claim guard's *outer* gate performs — `typed_tree.rs`/
/// `typed_map.rs`'s `put_locked_inner` and `const_tree.rs`'s `upsert_locked`,
/// the three call sites where the guard fix made an extra locked-body read
/// conditional on `H::CLAIMS && hook.claim_targets().is_some()` instead of
/// `H::CLAIMS` alone.
///
/// This whole module already only exists under `feature = "ctx-gates"` (see
/// the `pub mod ctx_gates_sync` declaration in `lib.rs`), same as
/// `should_sync_reads`/`sync_calls` above — the difference from those two is
/// that this counter has no separate runtime `set_counting`-style opt-in: it
/// always counts once the feature is on, because the call sites that
/// increment it are themselves reachable only inside `if H::CLAIMS &&
/// hook.claim_targets().is_some()`, which is already the condition under
/// test.
#[cfg(feature = "ctx-gates")]
static CLAIM_PRE_READ_CALLS: AtomicUsize = AtomicUsize::new(0);
/// Reset [`claim_pre_read_calls`]'s counter.
#[cfg(feature = "ctx-gates")]
pub fn reset_claim_pre_read_calls() {
CLAIM_PRE_READ_CALLS.store(0, Ordering::Relaxed);
}
/// Observed additive-pre-read count since the last [`reset_claim_pre_read_calls`].
/// Always counting (no `set_counting`-style opt-in) — the counter itself is
/// the opt-in, via the `ctx-gates` feature.
#[cfg(feature = "ctx-gates")]
pub fn claim_pre_read_calls() -> usize {
CLAIM_PRE_READ_CALLS.load(Ordering::Relaxed)
}
#[cfg(feature = "ctx-gates")]
pub(crate) fn record_claim_pre_read() {
CLAIM_PRE_READ_CALLS.fetch_add(1, Ordering::Relaxed);
}