use std::sync::atomic::{AtomicUsize, Ordering};
static MAX_CONTEXT_SIZE: AtomicUsize = AtomicUsize::new(0);
pub fn set_max_context_size(limit: usize) {
MAX_CONTEXT_SIZE.store(limit, Ordering::Relaxed);
}
pub fn max_context_size() -> usize {
MAX_CONTEXT_SIZE.load(Ordering::Relaxed)
}
pub(crate) fn check_size(size: usize) -> Result<(), crate::error::ContextError> {
let limit = max_context_size();
if limit > 0 && size > limit {
Err(crate::error::ContextError::ContextTooLarge { size, limit })
} else {
Ok(())
}
}