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
//! Atomic gauge for point-in-time values.
use CachePadded;
use ;
/// A cache-padded atomic gauge for point-in-time measurements.
///
/// Gauges represent a current value that is periodically sampled and set,
/// such as memory usage, queue depth, or progress percentage.
///
/// # Why Only `set()` and `get()`?
///
/// This type intentionally omits `add()`/`inc()`/`dec()` methods. If you need
/// to increment or decrement a value from multiple threads (e.g., tracking
/// active connections), use [`Counter`] instead - it's thread-sharded for
/// contention-free concurrent increments.
///
/// Providing increment methods here would create a footgun: the API would look
/// convenient for counting, but the single-atomic implementation would cause
/// cache-line contention under concurrent writes. By limiting the API to
/// `set()`/`get()`, we make the intended usage pattern clear: periodic
/// point-in-time snapshots from a single writer.
///
/// # Why Not Thread-Sharded?
///
/// Thread-sharding works for `Counter` because addition is commutative — you
/// can sum the shards to get the total. This includes subtraction (adding
/// negative values): the shard sums still produce the correct aggregate.
/// `set()` is not commutative; there's no meaningful way to aggregate "last
/// value written" across shards.
///
/// The cache padding prevents false sharing if this gauge is stored adjacent
/// to frequently-accessed data.
///
/// [`Counter`]: crate::Counter