Add rtic-arbiter

This commit is contained in:
Emil Fresk 2023-01-30 14:49:24 +01:00 committed by Henrik Tjäder
parent e65e532c2a
commit 5c1cefbf4e
7 changed files with 242 additions and 24 deletions

View file

@ -14,8 +14,11 @@ use core::{
task::{Poll, Waker},
};
use heapless::Deque;
use rtic_common::wait_queue::{Link, WaitQueue};
use rtic_common::waker_registration::CriticalSectionWakerRegistration as WakerRegistration;
use rtic_common::{
dropper::OnDrop,
wait_queue::{Link, WaitQueue},
};
/// An MPSC channel for use in no-alloc systems. `N` sets the size of the queue.
///
@ -417,29 +420,6 @@ impl<'a, T, const N: usize> Drop for Receiver<'a, T, N> {
}
}
struct OnDrop<F: FnOnce()> {
f: core::mem::MaybeUninit<F>,
}
impl<F: FnOnce()> OnDrop<F> {
pub fn new(f: F) -> Self {
Self {
f: core::mem::MaybeUninit::new(f),
}
}
#[allow(unused)]
pub fn defuse(self) {
core::mem::forget(self)
}
}
impl<F: FnOnce()> Drop for OnDrop<F> {
fn drop(&mut self) {
unsafe { self.f.as_ptr().read()() }
}
}
#[cfg(test)]
#[macro_use]
extern crate std;