aft_base/
scope_watch_events.rs1use std::sync::atomic::{AtomicU64, Ordering};
2
3#[derive(Clone, Copy)]
4pub enum Source {
5 Shell,
6 Grants,
7 Held,
8 Parked,
9}
10impl Source {
11 pub const ALL: [Self; 4] = [Self::Shell, Self::Grants, Self::Held, Self::Parked];
12 pub fn index(self) -> usize {
13 self as usize
14 }
15 pub fn name(self) -> &'static str {
16 match self {
17 Self::Shell => "shell",
18 Self::Grants => "grants",
19 Self::Held => "held",
20 Self::Parked => "parked",
21 }
22 }
23}
24static CHANGED: std::sync::LazyLock<tokio::sync::Notify> =
25 std::sync::LazyLock::new(tokio::sync::Notify::new);
26static REVISIONS: [AtomicU64; 4] = [const { AtomicU64::new(0) }; 4];
27
28pub fn changed(source: Source) {
31 REVISIONS[source.index()].fetch_add(1, Ordering::Release);
32 CHANGED.notify_waiters();
33}
34pub fn context_changed() {
35 for source in Source::ALL {
36 changed(source);
37 }
38}
39pub fn notifier() -> &'static tokio::sync::Notify {
40 &CHANGED
41}
42pub fn revisions() -> [u64; 4] {
43 std::array::from_fn(|i| REVISIONS[i].load(Ordering::Acquire))
44}
45#[cfg(all(any(test, feature = "test-support"), unix))]
46pub fn revision(source: Source) -> u64 {
47 REVISIONS[source.index()].load(Ordering::Acquire)
48}