use crate::{Error, Result};
use std::os::raw::c_int;
use std::sync::atomic::{AtomicBool, Ordering::Relaxed};
static IS_INSTANTIATED: AtomicBool = AtomicBool::new(false);
pub struct VipsInstance {}
impl VipsInstance {
pub fn new(name: &str, leak_test: bool) -> Result<VipsInstance> {
crate::init(Some(name))?;
match IS_INSTANTIATED.compare_exchange(false, true, Relaxed, Relaxed) {
Ok(_) => {
unsafe {
if leak_test {
vips_sys::vips_leak_set(leak_test as c_int);
}
}
Ok(VipsInstance {})
}
Err(_) => Err(Error::Other(
"You cannot create VipsInstance more than once.".to_string(),
)),
}
}
}