Next Generation WASM Microkernel Operating System
at main 51 lines 1.2 kB view raw
1// Copyright 2025 Jonas Kruckenberg 2// 3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or 4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or 5// http://opensource.org/licenses/MIT>, at your option. This file may not be 6// copied, modified, or distributed except according to those terms. 7 8use core::task::Waker; 9 10use k23_arrayvec::ArrayVec; 11 12const NUM_WAKERS: usize = 32; 13 14pub struct WakeBatch { 15 inner: ArrayVec<Waker, NUM_WAKERS>, 16} 17 18impl Default for WakeBatch { 19 fn default() -> Self { 20 Self::new() 21 } 22} 23 24impl WakeBatch { 25 pub const fn new() -> Self { 26 Self { 27 inner: ArrayVec::new(), 28 } 29 } 30 31 /// Adds a [`Waker`] to the batch, returning `true` if the batch needs to be flushed because it 32 /// is full. 33 pub fn add_waker(&mut self, waker: Waker) -> bool { 34 self.inner.push(waker); 35 self.inner.is_full() 36 } 37 38 pub fn wake_all(&mut self) { 39 for waker in self.inner.drain(..) { 40 waker.wake(); 41 } 42 } 43 44 pub fn len(&self) -> usize { 45 self.inner.len() 46 } 47 48 pub fn is_empty(&self) -> bool { 49 self.inner.is_empty() 50 } 51}