use super::*;
use crate::syscalls::*;
#[instrument(level = "trace", skip_all, fields(futex_idx = field::Empty, woken = field::Empty), ret)]
pub fn futex_wake_all<M: MemorySize>(
ctx: FunctionEnvMut<'_, WasiEnv>,
futex_ptr: WasmPtr<u32, M>,
ret_woken: WasmPtr<Bool, M>,
) -> Errno {
let env = ctx.data();
let memory = unsafe { env.memory_view(&ctx) };
let state = env.state.deref();
let pointer: u64 = futex_ptr.offset().into();
let mut woken = false;
let woken = {
let mut guard = state.futexs.lock().unwrap();
if let Some(futex) = guard.futexes.remove(&pointer) {
for waker in futex.wakers {
if let Some(waker) = waker.1 {
waker.wake();
}
}
tracing::trace!("wake_all (hit) on {pointer}");
true
} else {
tracing::trace!("wake_all (miss) on {pointer}");
true
}
};
let woken = match woken {
false => Bool::False,
true => Bool::True,
};
wasi_try_mem!(ret_woken.write(&memory, woken));
Errno::Success
}