libmirage 0.1.1

Rust bindings for libMirage
Documentation
use glib::translate::*;

/// No-op.
macro_rules! skip_assert_initialized {
    () => {};
}

pub static INITIALIZED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);

macro_rules! assert_initialized_main_thread {
    () => {
        if !$crate::rt::INITIALIZED.load(std::sync::atomic::Ordering::SeqCst) {
            panic!("Mirage has not been initialized. Call `libmirage::init` first.");
        }
    };
}

/// Initializes Mirage.
///
/// Call this function before calling any other Mirage functions.
///
/// # Safety
/// Must not be called from multiple threads at the same time.
#[doc(alias = "mirage_initialize")]
pub unsafe fn init() -> Result<(), glib::Error> {
    unsafe {
        let mut error = std::ptr::null_mut();
        let is_ok = ffi::mirage_initialize(&mut error);
        debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
        if error.is_null() {
            INITIALIZED.store(true, std::sync::atomic::Ordering::SeqCst);
            Ok(())
        } else {
            Err(from_glib_full(error))
        }
    }
}