use std::collections::{HashMap, HashSet};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, RwLock};
static FIRST_COMPILATION: AtomicBool = AtomicBool::new(true);
lazy_static! {
static ref GLOBAL_PREVIOUS_PROGRAM_CACHES: RwLock<HashMap<Arc<str>, HashSet<Arc<str>>>> = RwLock::new(HashMap::new());
}
pub fn lookup_prev_ns_cache(ns: &str) -> Option<HashSet<Arc<str>>> {
let previous_program_caches = &GLOBAL_PREVIOUS_PROGRAM_CACHES.read().expect("load cache");
if previous_program_caches.contains_key(ns) {
Some(previous_program_caches[ns].to_owned())
} else {
None
}
}
pub fn write_as_ns_cache(ns: &str, v: HashSet<Arc<str>>) {
let mut previous_program_caches = GLOBAL_PREVIOUS_PROGRAM_CACHES.write().expect("write cache");
(*previous_program_caches).insert(ns.to_owned().into(), v);
}
pub fn is_first_compilation() -> bool {
FIRST_COMPILATION.load(Ordering::Relaxed)
}
pub fn finish_compilation() -> Result<(), String> {
FIRST_COMPILATION.store(false, Ordering::SeqCst);
Ok(())
}