From 5b897b6605e571adb148ff1a35ea7ab3973861b0 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Thu, 21 Jan 2021 00:59:09 +0100 Subject: [PATCH] executor: Add 'raw' api to wake tasks through raw pointers. --- embassy/src/executor/mod.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/embassy/src/executor/mod.rs b/embassy/src/executor/mod.rs index 5e8354767..922b0fe0c 100644 --- a/embassy/src/executor/mod.rs +++ b/embassy/src/executor/mod.rs @@ -259,3 +259,18 @@ pub(crate) unsafe fn register_timer(at: Instant, waker: &Waker) { let expires_at = header.expires_at.get(); header.expires_at.set(min(expires_at, at)); } + +pub mod raw { + use super::waker; + use core::ptr::NonNull; + use core::task::Waker; + + pub fn task_from_waker(waker: &Waker) -> NonNull<()> { + unsafe { NonNull::new_unchecked(waker::task_from_waker(waker) as *mut ()) } + } + + pub unsafe fn wake_task(task: NonNull<()>) { + let header = &*waker::task_from_ptr(task.as_ptr()); + header.enqueue(); + } +}