Skip to content

Commit

Permalink
src/riot-rs-embassy: use thread flag for Waker
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspar030 committed Oct 17, 2023
1 parent 6f800fa commit ddac069
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/riot-rs-embassy/src/blocker.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use core::future::Future;
use core::pin::Pin;
use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
use riot_rs_core::thread::{current_pid, sleep, wakeup, ThreadId};
use riot_rs_core::thread::{current_pid, flags, flags::ThreadFlags, ThreadId};

const THREAD_FLAG_WAKER: ThreadFlags = 1; // TODO: find more appropriate value

fn wake(ptr: *const ()) {
// wake
let thread_id = ptr as usize as ThreadId;
wakeup(thread_id);
flags::set(thread_id, THREAD_FLAG_WAKER);
}

static VTABLE: RawWakerVTable = RawWakerVTable::new(
Expand All @@ -29,6 +31,6 @@ pub fn block_on<F: Future>(mut fut: F) -> F::Output {
if let Poll::Ready(res) = fut.as_mut().poll(&mut cx) {
return res;
}
sleep();
flags::wait_any(THREAD_FLAG_WAKER);
}
}

0 comments on commit ddac069

Please sign in to comment.