#![doc = include_str!("../README.md")]
#[cfg(feature = "yieldpoints")]
mod registry {
use std::collections::HashMap;
use std::sync::Arc;
use std::sync::OnceLock;
use parking_lot::Mutex;
use tokio::sync::Notify;
fn store() -> &'static Mutex<HashMap<&'static str, Arc<Notify>>> {
static STORE: OnceLock<Mutex<HashMap<&'static str, Arc<Notify>>>> = OnceLock::new();
STORE.get_or_init(|| Mutex::new(HashMap::new()))
}
pub fn cfg(name: &'static str) -> Arc<Notify> {
let notify = Arc::new(Notify::new());
store().lock().insert(name, notify.clone());
notify
}
pub fn remove(name: &'static str) {
store().lock().remove(name);
}
#[doc(hidden)]
pub fn get(name: &'static str) -> Option<Arc<Notify>> {
store().lock().get(name).cloned()
}
}
#[cfg(feature = "yieldpoints")]
pub use registry::{cfg, get, remove};
#[cfg(feature = "yieldpoints")]
#[macro_export]
macro_rules! yieldpoint {
($name:expr) => {{
if let Some(yp) = $crate::get($name) {
yp.notified().await;
}
}};
}
#[cfg(not(feature = "yieldpoints"))]
#[macro_export]
macro_rules! yieldpoint {
($name:expr) => {{}};
}