use std::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering};
use c_signatures::*;
static mut LIBXML_OBJECTS: i64 = 0;
pub fn _libxml_global_init() {
with_lock(||
unsafe {
if LIBXML_OBJECTS == 0 {
xmlInitParser();
xmlInitGlobals();
}
LIBXML_OBJECTS += 1;
}
);
}
pub fn _libxml_global_drop() {
with_lock(||
unsafe {
if LIBXML_OBJECTS == 1 {
}
LIBXML_OBJECTS -= 1;
}
);
}
pub fn force_global_drop() {
unsafe {
xmlCleanupGlobals();
xmlCleanupParser();
}
}
fn with_lock<F>(thunk: F) where F: Fn() {
static LIBXML_LOCK: AtomicBool = ATOMIC_BOOL_INIT;
while LIBXML_LOCK.compare_and_swap(false, true, Ordering::SeqCst) {}
thunk();
LIBXML_LOCK.store(false, Ordering::SeqCst);
}