Next Generation WASM Microkernel Operating System
at trap_handler 40 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::future::Future; 9use core::pin::Pin; 10use core::task::{Context, Poll}; 11 12/// Yields execution to back to the runtime. 13pub async fn yield_now() { 14 /// Yield implementation 15 struct YieldNow { 16 yielded: bool, 17 } 18 19 impl Future for YieldNow { 20 type Output = (); 21 22 fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> { 23 // ready!(crate::trace::trace_leaf(cx)); 24 25 if self.yielded { 26 return Poll::Ready(()); 27 } 28 29 self.yielded = true; 30 31 // Yielding works by immediately calling `wake_by_ref` which will reinsert this 32 // task into the queue (essentially a reschedule) and then returning `Poll::Pending` 33 // to signal that this task is not done yet 34 cx.waker().wake_by_ref(); 35 Poll::Pending 36 } 37 } 38 39 YieldNow { yielded: false }.await; 40}