use std::sync::atomic::{AtomicBool, Ordering};
static ALLOW_REAL_MODEL_REQUESTS: AtomicBool = AtomicBool::new(true);
#[must_use]
pub fn allow_real_model_requests() -> bool {
ALLOW_REAL_MODEL_REQUESTS.load(Ordering::SeqCst)
}
pub fn set_allow_real_model_requests(allow: bool) {
ALLOW_REAL_MODEL_REQUESTS.store(allow, Ordering::SeqCst);
}
#[derive(Debug)]
pub struct RealModelRequestGuard {
previous: bool,
}
impl RealModelRequestGuard {
#[must_use]
pub fn set(allow: bool) -> Self {
let previous = ALLOW_REAL_MODEL_REQUESTS.swap(allow, Ordering::SeqCst);
Self { previous }
}
}
impl Drop for RealModelRequestGuard {
fn drop(&mut self) {
ALLOW_REAL_MODEL_REQUESTS.store(self.previous, Ordering::SeqCst);
}
}
#[must_use]
pub fn block_real_model_requests() -> RealModelRequestGuard {
RealModelRequestGuard::set(false)
}
#[must_use]
pub fn allow_real_model_requests_guard() -> RealModelRequestGuard {
RealModelRequestGuard::set(true)
}