diff options
author | 2023-01-28 20:47:21 +0100 | |
---|---|---|
committer | 2023-01-28 20:47:21 +0100 | |
commit | bb98c315e0f5fd85a9fb11653f5f5f768dd6bd9a (patch) | |
tree | 02894331c3355b00eb7e77e8f5e3d3b9aec20fee /rtic-channel/src/wait_queue.rs | |
parent | 664f7b0ab0b93ce47f1a16ab0a031de63041549d (diff) | |
download | rtic-bb98c315e0f5fd85a9fb11653f5f5f768dd6bd9a.tar.gz rtic-bb98c315e0f5fd85a9fb11653f5f5f768dd6bd9a.tar.zst rtic-bb98c315e0f5fd85a9fb11653f5f5f768dd6bd9a.zip |
rtic-channel: Add testing, fix bugs
Diffstat (limited to '')
-rw-r--r-- | rtic-channel/src/wait_queue.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/rtic-channel/src/wait_queue.rs b/rtic-channel/src/wait_queue.rs index ba05e6bb..e6d5a8b9 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<T: Clone> LinkedList<T> { // 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<T> { pub(crate) val: T, next: AtomicPtr<Link<T>>, prev: AtomicPtr<Link<T>>, + is_poped: AtomicBool, _up: PhantomPinned, } +unsafe impl<T> Send for Link<T> {} + impl<T: Clone> Link<T> { const R: Ordering = Ordering::Relaxed; @@ -112,10 +116,15 @@ impl<T: Clone> Link<T> { 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<T>) { cs::with(|_| { // Make sure all previous writes are visible @@ -123,6 +132,7 @@ impl<T: Clone> Link<T> { 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::<u32>::new(); + let wq = LinkedList::<u32>::new(); let mut i1 = Link::new(10); let mut i2 = Link::new(11); |