use crate::utils::InitOnce;
static LOCK: std::sync::RwLock<()> = std::sync::RwLock::new(());
static mut ALT_GLOBAL_VAR: i32 = 0;
#[unsafe(no_mangle)]
pub extern "C" fn __wasip1_vfs_memory_grow_global_alt_set(v: i32) {
unsafe { ALT_GLOBAL_VAR = v };
}
#[unsafe(no_mangle)]
pub extern "C" fn __wasip1_vfs_memory_grow_global_alt_init_once(v: i32) {
static INIT: InitOnce = InitOnce::new_const();
INIT.call_once(|| {
unsafe { ALT_GLOBAL_VAR = v };
});
}
#[unsafe(no_mangle)]
pub extern "C" fn __wasip1_vfs_memory_grow_global_alt_pos() -> i32 {
&raw const ALT_GLOBAL_VAR as *const i32 as i32
}
#[unsafe(no_mangle)]
pub extern "C" fn __wasip1_vfs_memory_grow_global_alt_get_no_wait() -> i32 {
let i = unsafe { ALT_GLOBAL_VAR };
i
}
#[unsafe(no_mangle)]
pub extern "C" fn __wasip1_vfs_memory_grow_global_alt_get() -> i32 {
let _guard = LOCK.read().unwrap();
let i = unsafe { ALT_GLOBAL_VAR };
core::mem::drop(_guard);
i
}
#[cfg(target_arch = "wasm32")]
#[link(wasm_import_module = "wasip1-vfs_single_memory")]
unsafe extern "C" {
fn __wasip1_vfs_memory_grow_alt(_: i32) -> i32;
}
#[unsafe(no_mangle)]
extern "C" fn __wasip1_vfs_memory_grow_locker(page_size: i32) -> i32 {
let _guard = LOCK.write().unwrap();
let pre_page_size = unsafe { __wasip1_vfs_memory_grow_alt(page_size) };
core::mem::drop(_guard);
pre_page_size
}