message: Introduce `SharedFlag` type
diff: @@ -19,7 +19,10 @@ use std::{
  ops::{Add, BitXorAssign, Div},
  os::unix::fs::OpenOptionsExt,
  path::{Path, PathBuf},
  - sync::Arc,
  + sync::{
  + atomic::{AtomicBool, Ordering},
  + Arc,
  + },
  time::Duration,
  };
  @@ -120,6 +123,29 @@ pub(crate) fn leak<T>(value: T) -> &'static T {
  Box::leak(Box::new(value))
  }
  +/// A flag shared across multiple subsystem.
  +#[derive(Copy, Clone, Debug)]
  +pub(crate) struct SharedFlag(&'static AtomicBool);
  +
  +impl SharedFlag {
  + /// Creates a new shared flag.
  + ///
  + /// The flag is initially not set.
  + pub(crate) fn new() -> Self {
  + SharedFlag(leak(AtomicBool::new(false)))
  + }
  +
  + /// Checks whether the flag is set.
  + pub(crate) fn is_set(self) -> bool {
  + self.0.load(Ordering::SeqCst)
  + }
  +
  + /// Set the flag.
  + pub(crate) fn set(self) {
  + self.0.store(true, Ordering::SeqCst)
  + }
  +}
  +
  /// A display-helper that shows iterators display joined by ",".
  #[derive(Debug)]
  pub(crate) struct DisplayIter<T>(RefCell<Option<T>>);
  @@ -387,6 +413,8 @@ pub async fn wait_for_arc_drop<T>(arc: Arc<T>, attempts: usize, retry_delay: Dur
  mod tests {
  use std::{sync::Arc, time::Duration};
  + use crate::utils::SharedFlag;
  +
  use super::{wait_for_arc_drop, xor};
  #[test]
  @@ -443,4 +471,17 @@ mod tests {
  // This test fails only if we have a race condition, so false positive tests are possible.
  assert!(weak.upgrade().is_none());
  }
  +
  + #[test]
  + fn shared_flag_sanity_check() {
  + let flag = SharedFlag::new();
  +
  + assert!(!flag.is_set());
  + assert!(!flag.is_set());
  +
  + flag.set();
  +
  + assert!(flag.is_set());
  + assert!(flag.is_set());
  + }
  }
  