aboutsummaryrefslogtreecommitdiff
path: root/rtic-channel/src/wait_queue.rs
diff options
context:
space:
mode:
authorEmil Fresk <emil.fresk@gmail.com>2023-01-28 20:47:21 +0100
committerHenrik Tjäder <henrik@tjaders.com>2023-03-01 00:33:37 +0100
commit94b00df2c7e82efb9003945bb90675e73ed0f5e0 (patch)
tree5cf235406625936ec54282266d3234aa43b1c899 /rtic-channel/src/wait_queue.rs
parent48ac310036bb0053d36d9cfce191351028808651 (diff)
rtic-channel: Add testing, fix bugs
Diffstat (limited to 'rtic-channel/src/wait_queue.rs')
-rw-r--r--rtic-channel/src/wait_queue.rs14
1 files changed, 12 insertions, 2 deletions
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<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);