diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2023-04-16 12:05:20 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-16 12:05:20 +0000 |
| commit | 56bf829931cd3f8267ad435f6ff8f3ae200418b4 (patch) | |
| tree | 41afd65c26f8e77b02845476cbc15fce672119b3 /rtic-common | |
| parent | ef8046b060a375fd5e6b23d62c3a9a303bbd6e11 (diff) | |
| parent | cb83309462b1ed6d20ef498d7c2aaa86184c16fc (diff) | |
Merge #732
732: Docs 1 r=korken89 a=datdenkikniet
Going over all of the subprojects and trying to find stuff that may need docs
Co-authored-by: datdenkikniet <jcdra1@gmail.com>
Diffstat (limited to 'rtic-common')
| -rw-r--r-- | rtic-common/src/lib.rs | 2 | ||||
| -rw-r--r-- | rtic-common/src/wait_queue.rs | 21 |
2 files changed, 13 insertions, 10 deletions
diff --git a/rtic-common/src/lib.rs b/rtic-common/src/lib.rs index 03d0306..2dd9673 100644 --- a/rtic-common/src/lib.rs +++ b/rtic-common/src/lib.rs @@ -1,4 +1,4 @@ -//! Crate +//! Utility structs that can be useful to other subcrates. #![no_std] #![deny(missing_docs)] diff --git a/rtic-common/src/wait_queue.rs b/rtic-common/src/wait_queue.rs index b1aa775..4b1b0f3 100644 --- a/rtic-common/src/wait_queue.rs +++ b/rtic-common/src/wait_queue.rs @@ -1,4 +1,4 @@ -//! ... +//! A wait queue implementation using a doubly linked list. use core::marker::PhantomPinned; use core::pin::Pin; @@ -8,15 +8,18 @@ use core::task::Waker; use critical_section as cs; /// A helper definition of a wait queue. -pub type WaitQueue = LinkedList<Waker>; +pub type WaitQueue = DoublyLinkedList<Waker>; -/// A FIFO linked list for a wait queue. -pub struct LinkedList<T> { +/// An atomic, doubly linked, FIFO list for a wait queue. +/// +/// Atomicity is guaranteed by short [`critical_section`]s, so this list is _not_ lock free, +/// but it will not deadlock. +pub struct DoublyLinkedList<T> { head: AtomicPtr<Link<T>>, // UnsafeCell<*mut Link<T>> tail: AtomicPtr<Link<T>>, } -impl<T> LinkedList<T> { +impl<T> DoublyLinkedList<T> { /// Create a new linked list. pub const fn new() -> Self { Self { @@ -26,7 +29,7 @@ impl<T> LinkedList<T> { } } -impl<T: Clone> LinkedList<T> { +impl<T: Clone> DoublyLinkedList<T> { const R: Ordering = Ordering::Relaxed; /// Pop the first element in the queue. @@ -130,7 +133,7 @@ impl<T: Clone> Link<T> { } /// Remove this link from a linked list. - pub fn remove_from_list(&self, list: &LinkedList<T>) { + pub fn remove_from_list(&self, list: &DoublyLinkedList<T>) { cs::with(|_| { // Make sure all previous writes are visible core::sync::atomic::fence(Ordering::SeqCst); @@ -172,7 +175,7 @@ impl<T: Clone> Link<T> { } #[cfg(test)] -impl<T: core::fmt::Debug + Clone> LinkedList<T> { +impl<T: core::fmt::Debug + Clone> DoublyLinkedList<T> { fn print(&self) { cs::with(|_| { // Make sure all previous writes are visible @@ -232,7 +235,7 @@ mod tests { #[test] fn linked_list() { - let wq = LinkedList::<u32>::new(); + let wq = DoublyLinkedList::<u32>::new(); let i1 = Link::new(10); let i2 = Link::new(11); |
