From 94b00df2c7e82efb9003945bb90675e73ed0f5e0 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Sat, 28 Jan 2023 20:47:21 +0100 Subject: rtic-channel: Add testing, fix bugs --- rtic-channel/src/wait_queue.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'rtic-channel/src/wait_queue.rs') diff --git a/rtic-channel/src/wait_queue.rs b/rtic-channel/src/wait_queue.rs index ba05e6b..e6d5a8b 100644 --- a/rtic-channel/src/wait_queue.rs +++ b/rtic-channel/src/wait_queue.rs @@ -3,7 +3,7 @@ use core::marker::PhantomPinned; use core::pin::Pin; use core::ptr::null_mut; -use core::sync::atomic::{AtomicPtr, Ordering}; +use core::sync::atomic::{AtomicBool, AtomicPtr, Ordering}; use core::task::Waker; use critical_section as cs; @@ -57,6 +57,7 @@ impl LinkedList { // Clear the pointers in the node. head_ref.next.store(null_mut(), Self::R); head_ref.prev.store(null_mut(), Self::R); + head_ref.is_poped.store(true, Self::R); return Some(head_val); } @@ -100,9 +101,12 @@ pub struct Link { pub(crate) val: T, next: AtomicPtr>, prev: AtomicPtr>, + is_poped: AtomicBool, _up: PhantomPinned, } +unsafe impl Send for Link {} + impl Link { const R: Ordering = Ordering::Relaxed; @@ -112,10 +116,15 @@ impl Link { val, next: AtomicPtr::new(null_mut()), prev: AtomicPtr::new(null_mut()), + is_poped: AtomicBool::new(false), _up: PhantomPinned, } } + pub fn is_poped(&self) -> bool { + self.is_poped.load(Self::R) + } + pub fn remove_from_list(&mut self, list: &LinkedList) { cs::with(|_| { // Make sure all previous writes are visible @@ -123,6 +132,7 @@ impl Link { let prev = self.prev.load(Self::R); let next = self.next.load(Self::R); + self.is_poped.store(true, Self::R); match unsafe { (prev.as_ref(), next.as_ref()) } { (None, None) => { @@ -217,7 +227,7 @@ mod tests { #[test] fn linked_list() { - let mut wq = LinkedList::::new(); + let wq = LinkedList::::new(); let mut i1 = Link::new(10); let mut i2 = Link::new(11); -- cgit v1.2.3