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
//! Shutdown authority for scheduled UI shell commands.
#[cfg(test)]
mod tests;
use std::sync::atomic::{AtomicU64, Ordering};
/// Process-local shutdown generation captured by one scheduled UI shell
/// command.
///
/// A command whose captured generation differs from the current generation must
/// cancel before executing.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(super) struct UiShellShutdownGeneration(
/// Process-local atomic-owner counter snapshot.
u64,
);
impl UiShellShutdownGeneration {
/// Construct a generation for a test-owned scheduler fixture.
#[cfg(test)]
#[must_use]
const fn new(value: u64) -> Self {
Self(value)
}
}
/// Atomic owner of the shutdown authority for scheduled UI shell commands.
#[derive(Debug, Default)]
pub(super) struct UiShellShutdownGenerationCounter(
/// Process-local scalar counter updated when the shell runtime shuts down.
AtomicU64,
);
impl UiShellShutdownGenerationCounter {
/// Return the generation currently authorizing scheduled UI shell commands.
#[must_use]
pub(super) fn current(&self) -> UiShellShutdownGeneration {
UiShellShutdownGeneration(self.0.load(Ordering::SeqCst))
}
/// Advance scheduled UI shell shutdown authority with atomic wrapping
/// overflow.
pub(super) fn advance(&self) {
self.0.fetch_add(1, Ordering::SeqCst);
}
/// Construct an atomic owner for a test-owned scheduler fixture.
#[cfg(test)]
#[must_use]
const fn new(value: u64) -> Self {
Self(AtomicU64::new(value))
}
}