initialise to the no logger iff no other logger has been loaded

This commit is contained in:
Corwin 2023-08-05 19:14:49 +01:00
parent 3430668bdd
commit 987928a9a8
No known key found for this signature in database

View file

@ -1,7 +1,7 @@
mod log;
mod vfile;
use std::ptr::NonNull;
use std::{ptr::NonNull, sync::atomic::{AtomicBool, Ordering}};
pub use log::{Logger, LogLevel};
pub use vfile::{file::FileBacked, memory::MemoryBacked, shared::Shared, MapFlag, VFile};
@ -27,13 +27,18 @@ macro_rules! call_on_core {
};
}
static GLOBAL_LOGGER_HAS_BEEN_INITIALISED: AtomicBool = AtomicBool::new(false);
pub fn set_global_default_logger(logger: &'static Logger) {
GLOBAL_LOGGER_HAS_BEEN_INITIALISED.store(true, Ordering::SeqCst);
unsafe { mgba_sys::mLogSetDefaultLogger(logger.to_mgba()) }
}
impl MCore {
pub fn new() -> Option<Self> {
set_global_default_logger(&log::NO_LOGGER);
if !GLOBAL_LOGGER_HAS_BEEN_INITIALISED.load(Ordering::SeqCst) {
set_global_default_logger(&log::NO_LOGGER);
}
let core = unsafe { mgba_sys::GBACoreCreate() };
let core = NonNull::new(core)?;