aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--rtic-channel/Cargo.toml3
-rw-r--r--rtic-channel/src/lib.rs17
-rw-r--r--rtic-common/.gitignore2
-rw-r--r--rtic-common/CHANGELOG.md16
-rw-r--r--rtic-common/Cargo.toml13
-rw-r--r--rtic-common/src/lib.rs8
-rw-r--r--rtic-common/src/wait_queue.rs (renamed from rtic-channel/src/wait_queue.rs)3
-rw-r--r--rtic-common/src/waker_registration.rs (renamed from rtic-channel/src/waker_registration.rs)2
8 files changed, 53 insertions, 11 deletions
diff --git a/rtic-channel/Cargo.toml b/rtic-channel/Cargo.toml
index 5d4cbd0e..a0955bc4 100644
--- a/rtic-channel/Cargo.toml
+++ b/rtic-channel/Cargo.toml
@@ -8,6 +8,7 @@ edition = "2021"
[dependencies]
heapless = "0.7"
critical-section = "1"
+rtic-common = { version = "1.0.0", path = "../rtic-common" }
[dev-dependencies]
tokio = { version = "1", features = ["rt", "macros", "time"] }
@@ -15,4 +16,4 @@ tokio = { version = "1", features = ["rt", "macros", "time"] }
[features]
default = []
-testing = ["critical-section/std"]
+testing = ["critical-section/std", "rtic-common/testing"]
diff --git a/rtic-channel/src/lib.rs b/rtic-channel/src/lib.rs
index acfa8013..2b237f66 100644
--- a/rtic-channel/src/lib.rs
+++ b/rtic-channel/src/lib.rs
@@ -14,11 +14,8 @@ use core::{
task::{Poll, Waker},
};
use heapless::Deque;
-use wait_queue::WaitQueue;
-use waker_registration::CriticalSectionWakerRegistration as WakerRegistration;
-
-mod wait_queue;
-mod waker_registration;
+use rtic_common::wait_queue::{Link, WaitQueue};
+use rtic_common::waker_registration::CriticalSectionWakerRegistration as WakerRegistration;
/// An MPSC channel for use in no-alloc systems. `N` sets the size of the queue.
///
@@ -136,11 +133,11 @@ unsafe impl<'a, T, const N: usize> Send for Sender<'a, T, N> {}
/// This is needed to make the async closure in `send` accept that we "share"
/// the link possible between threads.
#[derive(Clone)]
-struct LinkPtr(*mut Option<wait_queue::Link<Waker>>);
+struct LinkPtr(*mut Option<Link<Waker>>);
impl LinkPtr {
/// This will dereference the pointer stored within and give out an `&mut`.
- unsafe fn get(&mut self) -> &mut Option<wait_queue::Link<Waker>> {
+ unsafe fn get(&mut self) -> &mut Option<Link<Waker>> {
&mut *self.0
}
}
@@ -200,10 +197,10 @@ impl<'a, T, const N: usize> Sender<'a, T, N> {
/// Send a value. If there is no place left in the queue this will wait until there is.
/// If the receiver does not exist this will return an error.
pub async fn send(&mut self, val: T) -> Result<(), NoReceiver<T>> {
- let mut link_ptr: Option<wait_queue::Link<Waker>> = None;
+ let mut link_ptr: Option<Link<Waker>> = None;
// Make this future `Drop`-safe, also shadow the original definition so we can't abuse it.
- let mut link_ptr = LinkPtr(&mut link_ptr as *mut Option<wait_queue::Link<Waker>>);
+ let mut link_ptr = LinkPtr(&mut link_ptr as *mut Option<Link<Waker>>);
let mut link_ptr2 = link_ptr.clone();
let dropper = OnDrop::new(|| {
@@ -236,7 +233,7 @@ impl<'a, T, const N: usize> Sender<'a, T, N> {
}
} else {
// Place the link in the wait queue on first run.
- let link_ref = link.insert(wait_queue::Link::new(cx.waker().clone()));
+ let link_ref = link.insert(Link::new(cx.waker().clone()));
// SAFETY: The address to the link is stable as it is hidden behind
// `link_ptr`, and `link_ptr` shadows the original making it unmovable.
diff --git a/rtic-common/.gitignore b/rtic-common/.gitignore
new file mode 100644
index 00000000..1e7caa9e
--- /dev/null
+++ b/rtic-common/.gitignore
@@ -0,0 +1,2 @@
+Cargo.lock
+target/
diff --git a/rtic-common/CHANGELOG.md b/rtic-common/CHANGELOG.md
new file mode 100644
index 00000000..d3a9d846
--- /dev/null
+++ b/rtic-common/CHANGELOG.md
@@ -0,0 +1,16 @@
+# Change Log
+
+All notable changes to this project will be documented in this file.
+This project adheres to [Semantic Versioning](http://semver.org/).
+
+For each category, *Added*, *Changed*, *Fixed* add new entries at the top!
+
+## [Unreleased]
+
+### Added
+
+### Changed
+
+### Fixed
+
+## [v1.0.0] - 2023-xx-xx
diff --git a/rtic-common/Cargo.toml b/rtic-common/Cargo.toml
new file mode 100644
index 00000000..258caae0
--- /dev/null
+++ b/rtic-common/Cargo.toml
@@ -0,0 +1,13 @@
+[package]
+name = "rtic-common"
+version = "1.0.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+critical-section = "1"
+
+[features]
+default = []
+testing = ["critical-section/std"]
diff --git a/rtic-common/src/lib.rs b/rtic-common/src/lib.rs
new file mode 100644
index 00000000..3c75856c
--- /dev/null
+++ b/rtic-common/src/lib.rs
@@ -0,0 +1,8 @@
+//! Crate
+
+#![no_std]
+#![deny(missing_docs)]
+//deny_warnings_placeholder_for_ci
+
+pub mod wait_queue;
+pub mod waker_registration;
diff --git a/rtic-channel/src/wait_queue.rs b/rtic-common/src/wait_queue.rs
index 2de6311d..ba8ff547 100644
--- a/rtic-channel/src/wait_queue.rs
+++ b/rtic-common/src/wait_queue.rs
@@ -7,6 +7,7 @@ use core::sync::atomic::{AtomicBool, AtomicPtr, Ordering};
use core::task::Waker;
use critical_section as cs;
+/// A helper definition of a wait queue.
pub type WaitQueue = LinkedList<Waker>;
/// A FIFO linked list for a wait queue.
@@ -119,10 +120,12 @@ impl<T: Clone> Link<T> {
}
}
+ /// Return true if this link has been poped from the list.
pub fn is_poped(&self) -> bool {
self.is_poped.load(Self::R)
}
+ /// Remove this link from a linked list.
pub fn remove_from_list(&mut self, list: &LinkedList<T>) {
cs::with(|_| {
// Make sure all previous writes are visible
diff --git a/rtic-channel/src/waker_registration.rs b/rtic-common/src/waker_registration.rs
index c30df7fe..174765c2 100644
--- a/rtic-channel/src/waker_registration.rs
+++ b/rtic-common/src/waker_registration.rs
@@ -1,3 +1,5 @@
+//! Waker registration utility.
+
use core::cell::UnsafeCell;
use core::task::Waker;