diff --git a/src/sealed.rs b/src/sealed.rs index 092485d187..bd0ac12e38 100644 --- a/src/sealed.rs +++ b/src/sealed.rs @@ -1,27 +1,7 @@ /// Sealed traits and implementations for `spsc` pub mod spsc { #[cfg(has_atomics)] - use crate::spsc::{MultiCore, SingleCore}; - #[cfg(has_atomics)] - use core::sync::atomic::{self, AtomicU16, AtomicU8, AtomicUsize, Ordering}; - - pub unsafe trait XCore { - fn is_multi_core() -> bool; - } - - #[cfg(has_atomics)] - unsafe impl XCore for SingleCore { - fn is_multi_core() -> bool { - false - } - } - - #[cfg(has_atomics)] - unsafe impl XCore for MultiCore { - fn is_multi_core() -> bool { - true - } - } + use core::sync::atomic::{AtomicU16, AtomicU8, AtomicUsize, Ordering}; pub unsafe trait Uxx: Into + Send { #[doc(hidden)] @@ -32,9 +12,7 @@ pub mod spsc { #[cfg(has_atomics)] #[doc(hidden)] - unsafe fn load_acquire(x: *const Self) -> Self - where - C: XCore; + unsafe fn load_acquire(x: *const Self) -> Self; #[cfg(has_atomics)] #[doc(hidden)] @@ -42,9 +20,7 @@ pub mod spsc { #[cfg(has_atomics)] #[doc(hidden)] - unsafe fn store_release(x: *const Self, val: Self) - where - C: XCore; + unsafe fn store_release(x: *const Self, val: Self); } unsafe impl Uxx for u8 { @@ -62,17 +38,11 @@ pub mod spsc { } #[cfg(has_atomics)] - unsafe fn load_acquire(x: *const Self) -> Self - where - C: XCore, - { - if C::is_multi_core() { - (*(x as *const AtomicU8)).load(Ordering::Acquire) - } else { - let y = (*(x as *const AtomicU8)).load(Ordering::Relaxed); // read - atomic::compiler_fence(Ordering::Acquire); // ▼ - y - } + unsafe fn load_acquire(x: *const Self) -> Self { + (*(x as *const AtomicU8)).load(Ordering::Acquire) + // let y = (*(x as *const AtomicU8)).load(Ordering::Relaxed); // read + // atomic::compiler_fence(Ordering::Acquire); // ▼ + // y } #[cfg(has_atomics)] @@ -81,16 +51,10 @@ pub mod spsc { } #[cfg(has_atomics)] - unsafe fn store_release(x: *const Self, val: Self) - where - C: XCore, - { - if C::is_multi_core() { - (*(x as *const AtomicU8)).store(val, Ordering::Release) - } else { - atomic::compiler_fence(Ordering::Release); // ▲ - (*(x as *const AtomicU8)).store(val, Ordering::Relaxed) // write - } + unsafe fn store_release(x: *const Self, val: Self) { + (*(x as *const AtomicU8)).store(val, Ordering::Release) + // atomic::compiler_fence(Ordering::Release); // ▲ + // (*(x as *const AtomicU8)).store(val, Ordering::Relaxed) // write } } @@ -109,17 +73,11 @@ pub mod spsc { } #[cfg(has_atomics)] - unsafe fn load_acquire(x: *const Self) -> Self - where - C: XCore, - { - if C::is_multi_core() { - (*(x as *const AtomicU16)).load(Ordering::Acquire) - } else { - let y = (*(x as *const AtomicU16)).load(Ordering::Relaxed); // read - atomic::compiler_fence(Ordering::Acquire); // ▼ - y - } + unsafe fn load_acquire(x: *const Self) -> Self { + (*(x as *const AtomicU16)).load(Ordering::Acquire) + // let y = (*(x as *const AtomicU16)).load(Ordering::Relaxed); // read + // atomic::compiler_fence(Ordering::Acquire); // ▼ + // y } #[cfg(has_atomics)] @@ -128,16 +86,10 @@ pub mod spsc { } #[cfg(has_atomics)] - unsafe fn store_release(x: *const Self, val: Self) - where - C: XCore, - { - if C::is_multi_core() { - (*(x as *const AtomicU16)).store(val, Ordering::Release) - } else { - atomic::compiler_fence(Ordering::Release); // ▲ - (*(x as *const AtomicU16)).store(val, Ordering::Relaxed) // write - } + unsafe fn store_release(x: *const Self, val: Self) { + (*(x as *const AtomicU16)).store(val, Ordering::Release) + // atomic::compiler_fence(Ordering::Release); // ▲ + // (*(x as *const AtomicU16)).store(val, Ordering::Relaxed) // write } } @@ -151,17 +103,11 @@ pub mod spsc { } #[cfg(has_atomics)] - unsafe fn load_acquire(x: *const Self) -> Self - where - C: XCore, - { - if C::is_multi_core() { - (*(x as *const AtomicUsize)).load(Ordering::Acquire) - } else { - let y = (*(x as *const AtomicUsize)).load(Ordering::Relaxed); // read - atomic::compiler_fence(Ordering::Acquire); // ▼ - y - } + unsafe fn load_acquire(x: *const Self) -> Self { + (*(x as *const AtomicUsize)).load(Ordering::Acquire) + // let y = (*(x as *const AtomicUsize)).load(Ordering::Relaxed); // read + // atomic::compiler_fence(Ordering::Acquire); // ▼ + // y } #[cfg(has_atomics)] @@ -170,16 +116,10 @@ pub mod spsc { } #[cfg(has_atomics)] - unsafe fn store_release(x: *const Self, val: Self) - where - C: XCore, - { - if C::is_multi_core() { - (*(x as *const AtomicUsize)).store(val, Ordering::Release) - } else { - atomic::compiler_fence(Ordering::Release); // ▲ - (*(x as *const AtomicUsize)).store(val, Ordering::Relaxed); // write - } + unsafe fn store_release(x: *const Self, val: Self) { + (*(x as *const AtomicUsize)).store(val, Ordering::Release) + // atomic::compiler_fence(Ordering::Release); // ▲ + // (*(x as *const AtomicUsize)).store(val, Ordering::Relaxed); // write } } } diff --git a/src/spsc/mod.rs b/src/spsc/mod.rs index ef7820b0e1..76007e9cd1 100644 --- a/src/spsc/mod.rs +++ b/src/spsc/mod.rs @@ -10,7 +10,7 @@ //! ``` //! use heapless::spsc::Queue; //! -//! let mut rb: Queue = Queue::new(); +//! let mut rb: Queue = Queue::new(); //! //! assert!(rb.enqueue(0).is_ok()); //! assert!(rb.enqueue(1).is_ok()); @@ -24,11 +24,11 @@ //! - `Queue` can be `split` and then be used in Single Producer Single Consumer mode //! //! ``` -//! use heapless::spsc::{Queue, MultiCore}; +//! use heapless::spsc::{Queue}; //! //! // Notice, type signature needs to be explicit for now. //! // (min_const_eval, does not allow for default type assignments) -//! static mut Q: Queue = Queue::new(); +//! static mut Q: Queue = Queue::new(); //! //! enum Event { A, B } //! @@ -83,7 +83,7 @@ //! - The numbers reported correspond to the successful path (i.e. `Some` is returned by `dequeue` //! and `Ok` is returned by `enqueue`). -use core::{cell::UnsafeCell, fmt, hash, marker::PhantomData, mem::MaybeUninit, ptr}; +use core::{cell::UnsafeCell, fmt, hash, mem::MaybeUninit, ptr}; use hash32; @@ -92,32 +92,23 @@ pub use split::{Consumer, Producer}; mod split; -/// Multi core synchronization - a memory barrier is used for synchronization -pub struct MultiCore; - -/// Single core synchronization - no memory barrier synchronization, just a compiler fence -pub struct SingleCore; - -// Atomic{U8,U16, Usize} with no CAS operations that works on targets that have "no atomic support" +// Atomic{U8, U16, Usize} with no CAS operations that works on targets that have "no atomic support" // according to their specification -pub(crate) struct Atomic { +pub(crate) struct Atomic { v: UnsafeCell, - c: PhantomData, } -impl Atomic { +impl Atomic { pub(crate) const fn new(v: U) -> Self { Atomic { v: UnsafeCell::new(v), - c: PhantomData, } } } -impl Atomic +impl Atomic where U: sealed::Uxx, - C: sealed::XCore, { fn get(&self) -> &U { unsafe { &*self.v.get() } @@ -128,7 +119,7 @@ where } fn load_acquire(&self) -> U { - unsafe { U::load_acquire::(self.v.get()) } + unsafe { U::load_acquire(self.v.get()) } } fn load_relaxed(&self) -> U { @@ -136,7 +127,7 @@ where } fn store_release(&self, val: U) { - unsafe { U::store_release::(self.v.get(), val) } + unsafe { U::store_release(self.v.get(), val) } } } @@ -153,8 +144,8 @@ where /// [`u8`]: struct.Queue.html#method.u8 /// [`u16`]: struct.Queue.html#method.u16 /// -/// *IMPORTANT*: `spsc::Queue<_, _, u8>` has a maximum capacity of 255 elements; `spsc::Queue<_, _, -/// u16>` has a maximum capacity of 65535 elements. +/// *IMPORTANT*: `spsc::Queue<_, u8, N>` has a maximum capacity of 255 elements; `spsc::Queue<_, +/// u16, N>` has a maximum capacity of 65535 elements. /// /// `spsc::Queue` also comes in a single core variant. This variant can be created using the /// following constructors: `u8_sc`, `u16_sc`, `usize_sc` and `new_sc`. This variant is `unsafe` to @@ -162,24 +153,22 @@ where /// (if split) are kept on a single core for their entire lifetime. #[cfg(has_atomics)] -pub struct Queue +pub struct Queue where U: sealed::Uxx, - C: sealed::XCore, { // this is from where we dequeue items - pub(crate) head: Atomic, + pub(crate) head: Atomic, // this is where we enqueue new items - pub(crate) tail: Atomic, + pub(crate) tail: Atomic, pub(crate) buffer: MaybeUninit<[T; N]>, } -impl Queue +impl Queue where U: sealed::Uxx, - C: sealed::XCore, { /// Returns the maximum number of elements the queue can hold pub fn capacity(&self) -> U { @@ -192,7 +181,7 @@ where } /// Iterates from the front of the queue to the back - pub fn iter(&self) -> Iter<'_, T, U, C, N> { + pub fn iter(&self) -> Iter<'_, T, U, N> { Iter { rb: self, index: 0, @@ -201,7 +190,7 @@ where } /// Returns an iterator that allows modifying each value. - pub fn iter_mut(&mut self) -> IterMut<'_, T, U, C, N> { + pub fn iter_mut(&mut self) -> IterMut<'_, T, U, N> { let len = self.len_usize(); IterMut { rb: self, @@ -218,10 +207,9 @@ where } } -impl Drop for Queue +impl Drop for Queue where U: sealed::Uxx, - C: sealed::XCore, { fn drop(&mut self) { for item in self { @@ -232,22 +220,20 @@ where } } -impl fmt::Debug for Queue +impl fmt::Debug for Queue where T: fmt::Debug, U: sealed::Uxx, - C: sealed::XCore, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_list().entries(self.iter()).finish() } } -impl hash::Hash for Queue +impl hash::Hash for Queue where T: hash::Hash, U: sealed::Uxx, - C: sealed::XCore, { fn hash(&self, state: &mut H) { // iterate over self in order @@ -257,11 +243,10 @@ where } } -impl hash32::Hash for Queue +impl hash32::Hash for Queue where T: hash32::Hash, U: sealed::Uxx, - C: sealed::XCore, { fn hash(&self, state: &mut H) { // iterate over self in order @@ -271,26 +256,24 @@ where } } -impl<'a, T, U, C, const N: usize> IntoIterator for &'a Queue +impl<'a, T, U, const N: usize> IntoIterator for &'a Queue where U: sealed::Uxx, - C: sealed::XCore, { type Item = &'a T; - type IntoIter = Iter<'a, T, U, C, N>; + type IntoIter = Iter<'a, T, U, N>; fn into_iter(self) -> Self::IntoIter { self.iter() } } -impl<'a, T, U, C, const N: usize> IntoIterator for &'a mut Queue +impl<'a, T, U, const N: usize> IntoIterator for &'a mut Queue where U: sealed::Uxx, - C: sealed::XCore, { type Item = &'a mut T; - type IntoIter = IterMut<'a, T, U, C, N>; + type IntoIter = IterMut<'a, T, U, N>; fn into_iter(self) -> Self::IntoIter { self.iter_mut() @@ -299,7 +282,7 @@ where macro_rules! impl_ { ($uxx:ident, $uxx_sc:ident) => { - impl Queue { + impl Queue { /// Creates an empty queue with a fixed capacity of `N` pub const fn $uxx() -> Self { Self { @@ -310,21 +293,7 @@ macro_rules! impl_ { } } - impl Queue { - /// Creates an empty queue with a fixed capacity of `N` (single core variant) - pub const unsafe fn $uxx_sc() -> Self { - Self { - buffer: MaybeUninit::uninit(), - head: Atomic::new(0), - tail: Atomic::new(0), - } - } - } - - impl Queue - where - C: sealed::XCore, - { + impl Queue { /// Returns a reference to the item in the front of the queue without dequeuing, or /// `None` if the queue is empty. /// @@ -332,7 +301,7 @@ macro_rules! impl_ { /// ``` /// use heapless::spsc::Queue; /// - /// let mut queue: Queue = Queue::u8(); + /// let mut queue: Queue = Queue::u8(); /// let (mut producer, mut consumer) = queue.split(); /// assert_eq!(None, consumer.peek()); /// producer.enqueue(1); @@ -419,13 +388,12 @@ macro_rules! impl_ { } } - impl Clone for Queue + impl Clone for Queue where T: Clone, - C: sealed::XCore, { fn clone(&self) -> Self { - let mut new: Queue = Queue { + let mut new: Queue = Queue { buffer: MaybeUninit::uninit(), head: Atomic::new(0), tail: Atomic::new(0), @@ -444,14 +412,14 @@ macro_rules! impl_ { }; } -impl Queue { +impl Queue { /// Alias for [`spsc::Queue::usize`](struct.Queue.html#method.usize) pub const fn new() -> Self { Queue::usize() } } -impl Queue { +impl Queue { /// Alias for [`spsc::Queue::usize_sc`](struct.Queue.html#method.usize_sc) pub unsafe fn new_sc() -> Self { Queue::usize_sc() @@ -462,44 +430,38 @@ impl_!(u8, u8_sc); impl_!(u16, u16_sc); impl_!(usize, usize_sc); -impl PartialEq> - for Queue +impl PartialEq> for Queue where T: PartialEq, U: sealed::Uxx, - C: sealed::XCore, U2: sealed::Uxx, - C2: sealed::XCore, { - fn eq(&self, other: &Queue) -> bool { + fn eq(&self, other: &Queue) -> bool { self.len_usize() == other.len_usize() && self.iter().zip(other.iter()).all(|(v1, v2)| v1 == v2) } } -impl Eq for Queue +impl Eq for Queue where T: Eq, U: sealed::Uxx, - C: sealed::XCore, { } /// An iterator over the items of a queue -pub struct Iter<'a, T, U, C, const N: usize> +pub struct Iter<'a, T, U, const N: usize> where U: sealed::Uxx, - C: sealed::XCore, { - rb: &'a Queue, + rb: &'a Queue, index: usize, len: usize, } -impl<'a, T, U, C, const N: usize> Clone for Iter<'a, T, U, C, N> +impl<'a, T, U, const N: usize> Clone for Iter<'a, T, U, N> where U: sealed::Uxx, - C: sealed::XCore, { fn clone(&self) -> Self { Self { @@ -511,22 +473,20 @@ where } /// A mutable iterator over the items of a queue -pub struct IterMut<'a, T, U, C, const N: usize> +pub struct IterMut<'a, T, U, const N: usize> where U: sealed::Uxx, - C: sealed::XCore, { - rb: &'a mut Queue, + rb: &'a mut Queue, index: usize, len: usize, } macro_rules! iterator { (struct $name:ident -> $elem:ty, $ptr:ty, $asptr:ident, $mkref:ident) => { - impl<'a, T, U, C, const N: usize> Iterator for $name<'a, T, U, C, N> + impl<'a, T, U, const N: usize> Iterator for $name<'a, T, U, N> where U: sealed::Uxx, - C: sealed::XCore, { type Item = $elem; @@ -545,10 +505,9 @@ macro_rules! iterator { } } - impl<'a, T, U, C, const N: usize> DoubleEndedIterator for $name<'a, T, U, C, N> + impl<'a, T, U, const N: usize> DoubleEndedIterator for $name<'a, T, U, N> where U: sealed::Uxx, - C: sealed::XCore, { fn next_back(&mut self) -> Option<$elem> { if self.index < self.len { @@ -587,21 +546,21 @@ iterator!(struct IterMut -> &'a mut T, *mut T, as_mut_ptr, make_ref_mut); mod tests { use hash32::Hasher; - use crate::spsc::{MultiCore, Queue, SingleCore}; + use crate::spsc::Queue; #[test] fn static_usize_sc() { - static mut _Q: Queue = unsafe { Queue::usize_sc() }; + static mut _Q: Queue = unsafe { Queue::usize_sc() }; } #[test] fn static_usize() { - static mut _Q: Queue = Queue::usize(); + static mut _Q: Queue = Queue::usize(); } #[test] fn static_new() { - static mut _Q: Queue = Queue::new(); + static mut _Q: Queue = Queue::new(); } #[test] @@ -627,7 +586,7 @@ mod tests { static mut COUNT: i32 = 0; { - let mut v: Queue = unsafe { Queue::usize_sc() }; + let mut v: Queue = unsafe { Queue::usize_sc() }; v.enqueue(Droppable::new()).ok().unwrap(); v.enqueue(Droppable::new()).ok().unwrap(); v.dequeue().unwrap(); @@ -636,7 +595,7 @@ mod tests { assert_eq!(unsafe { COUNT }, 0); { - let mut v: Queue = Queue::usize(); + let mut v: Queue = Queue::usize(); v.enqueue(Droppable::new()).ok().unwrap(); v.enqueue(Droppable::new()).ok().unwrap(); } @@ -646,7 +605,7 @@ mod tests { #[test] fn full() { - let mut rb: Queue = Queue::u8(); + let mut rb: Queue = Queue::u8(); rb.enqueue(0).unwrap(); rb.enqueue(1).unwrap(); @@ -658,7 +617,7 @@ mod tests { #[test] fn iter() { - let mut rb: Queue = Queue::u16(); + let mut rb: Queue = Queue::u16(); rb.enqueue(0).unwrap(); rb.enqueue(1).unwrap(); @@ -674,7 +633,7 @@ mod tests { #[test] fn iter_double_ended() { - let mut rb: Queue = Queue::u8(); + let mut rb: Queue = Queue::u8(); rb.enqueue(0).unwrap(); rb.enqueue(1).unwrap(); @@ -691,7 +650,7 @@ mod tests { #[test] fn iter_overflow() { - let mut rb: Queue = Queue::u8(); + let mut rb: Queue = Queue::u8(); rb.enqueue(0).unwrap(); for _ in 0..300 { @@ -705,7 +664,7 @@ mod tests { #[test] fn iter_mut() { - let mut rb: Queue = Queue::u8(); + let mut rb: Queue = Queue::u8(); rb.enqueue(0).unwrap(); rb.enqueue(1).unwrap(); @@ -721,7 +680,7 @@ mod tests { #[test] fn iter_mut_double_ended() { - let mut rb: Queue = Queue::u8(); + let mut rb: Queue = Queue::u8(); rb.enqueue(0).unwrap(); rb.enqueue(1).unwrap(); @@ -738,7 +697,7 @@ mod tests { #[test] fn sanity() { - let mut rb: Queue = Queue::u8(); + let mut rb: Queue = Queue::u8(); assert_eq!(rb.dequeue(), None); rb.enqueue(0).unwrap(); assert_eq!(rb.dequeue(), Some(0)); @@ -748,7 +707,7 @@ mod tests { #[test] #[cfg(feature = "smaller-atomics")] fn u8() { - let mut rb: Queue = Queue::u8(); + let mut rb: Queue = Queue::u8(); for _ in 0..255 { rb.enqueue(0).unwrap(); @@ -759,7 +718,7 @@ mod tests { #[test] fn wrap_around() { - let mut rb: Queue = Queue::u8(); + let mut rb: Queue = Queue::u8(); rb.enqueue(0).unwrap(); rb.enqueue(1).unwrap(); @@ -775,7 +734,7 @@ mod tests { #[test] fn ready_flag() { - let mut rb: Queue = Queue::u8(); + let mut rb: Queue = Queue::u8(); let (mut p, mut c) = rb.split(); assert_eq!(c.ready(), false); assert_eq!(p.ready(), true); @@ -803,7 +762,7 @@ mod tests { #[test] fn clone() { - let mut rb1: Queue = Queue::u8(); + let mut rb1: Queue = Queue::u8(); rb1.enqueue(0).unwrap(); rb1.enqueue(0).unwrap(); rb1.dequeue().unwrap(); @@ -818,12 +777,12 @@ mod tests { fn eq() { // generate two queues with same content // but different buffer alignment - let mut rb1: Queue = Queue::u8(); + let mut rb1: Queue = Queue::u8(); rb1.enqueue(0).unwrap(); rb1.enqueue(0).unwrap(); rb1.dequeue().unwrap(); rb1.enqueue(0).unwrap(); - let mut rb2: Queue = Queue::u8(); + let mut rb2: Queue = Queue::u8(); rb2.enqueue(0).unwrap(); rb2.enqueue(0).unwrap(); assert!(rb1 == rb2); @@ -844,7 +803,7 @@ mod tests { // generate two queues with same content // but different buffer alignment let rb1 = { - let mut rb1: Queue = Queue::u8(); + let mut rb1: Queue = Queue::u8(); rb1.enqueue(0).unwrap(); rb1.enqueue(0).unwrap(); rb1.dequeue().unwrap(); @@ -852,7 +811,7 @@ mod tests { rb1 }; let rb2 = { - let mut rb2: Queue = Queue::u8(); + let mut rb2: Queue = Queue::u8(); rb2.enqueue(0).unwrap(); rb2.enqueue(0).unwrap(); rb2 diff --git a/src/spsc/split.rs b/src/spsc/split.rs index 5cd6264a6e..88dcc90cef 100644 --- a/src/spsc/split.rs +++ b/src/spsc/split.rs @@ -1,18 +1,13 @@ use core::{marker::PhantomData, ptr::NonNull}; -use crate::{ - sealed::spsc as sealed, - spsc::Queue, - // spsc::{MultiCore, Queue}, // we cannot currently default to MultiCore -}; +use crate::{sealed::spsc as sealed, spsc::Queue}; -impl Queue +impl Queue where U: sealed::Uxx, - C: sealed::XCore, { /// Splits a statically allocated queue into producer and consumer end points - pub fn split<'rb>(&'rb mut self) -> (Producer<'rb, T, U, C, N>, Consumer<'rb, T, U, C, N>) { + pub fn split<'rb>(&'rb mut self) -> (Producer<'rb, T, U, N>, Consumer<'rb, T, U, N>) { ( Producer { rb: unsafe { NonNull::new_unchecked(self) }, @@ -28,48 +23,41 @@ where /// A queue "consumer"; it can dequeue items from the queue // NOTE the consumer semantically owns the `head` pointer of the queue -pub struct Consumer<'a, T, U, C, const N: usize> +pub struct Consumer<'a, T, U, const N: usize> where U: sealed::Uxx, - C: sealed::XCore, { - rb: NonNull>, + rb: NonNull>, _marker: PhantomData<&'a ()>, } -unsafe impl<'a, T, U, C, const N: usize> Send for Consumer<'a, T, U, C, N> +unsafe impl<'a, T, U, const N: usize> Send for Consumer<'a, T, U, N> where T: Send, U: sealed::Uxx, - C: sealed::XCore, { } /// A queue "producer"; it can enqueue items into the queue // NOTE the producer semantically owns the `tail` pointer of the queue -pub struct Producer<'a, T, U, C, const N: usize> +pub struct Producer<'a, T, U, const N: usize> where U: sealed::Uxx, - C: sealed::XCore, { - rb: NonNull>, + rb: NonNull>, _marker: PhantomData<&'a ()>, } -unsafe impl<'a, T, U, C, const N: usize> Send for Producer<'a, T, U, C, N> +unsafe impl<'a, T, U, const N: usize> Send for Producer<'a, T, U, N> where T: Send, U: sealed::Uxx, - C: sealed::XCore, { } macro_rules! impl_ { ($uxx:ident) => { - impl<'a, T, C, const N: usize> Consumer<'a, T, $uxx, C, N> - where - C: sealed::XCore, - { + impl<'a, T, const N: usize> Consumer<'a, T, $uxx, N> { /// Returns if there are any items to dequeue. When this returns true, at least the /// first subsequent dequeue will succeed. pub fn ready(&self) -> bool { @@ -84,7 +72,7 @@ macro_rules! impl_ { /// ``` /// use heapless::spsc::Queue; /// - /// let mut queue: Queue = Queue::u8(); + /// let mut queue: Queue = Queue::u8(); /// let (mut producer, mut consumer) = queue.split(); /// assert_eq!(None, consumer.peek()); /// producer.enqueue(1); @@ -165,10 +153,7 @@ macro_rules! impl_ { } } - impl<'a, T, C, const N: usize> Producer<'a, T, $uxx, C, N> - where - C: sealed::XCore, - { + impl<'a, T, const N: usize> Producer<'a, T, $uxx, N> { /// Returns if there is any space to enqueue a new item. When this returns true, at /// least the first subsequent enqueue will succeed. pub fn ready(&self) -> bool { @@ -259,11 +244,11 @@ impl_!(usize); #[cfg(test)] mod tests { - use crate::spsc::{MultiCore, Queue}; + use crate::spsc::Queue; #[test] fn sanity() { - let mut rb: Queue = Queue::u8(); + let mut rb: Queue = Queue::u8(); let (mut p, mut c) = rb.split(); diff --git a/tests/cpass.rs b/tests/cpass.rs index 18d88d194b..f525ee5688 100644 --- a/tests/cpass.rs +++ b/tests/cpass.rs @@ -1,7 +1,7 @@ //! Collections of `Send`-able things are `Send` use heapless::{ - spsc::{Consumer, MultiCore, Producer, Queue}, + spsc::{Consumer, Producer, Queue}, HistoryBuffer, Vec, }; @@ -17,9 +17,9 @@ fn send() { { } - is_send::>(); - is_send::>(); - is_send::>(); + is_send::>(); + is_send::>(); + is_send::>(); is_send::>(); is_send::>(); } diff --git a/tests/tsan.rs b/tests/tsan.rs index 9ea18add39..c3d6638460 100644 --- a/tests/tsan.rs +++ b/tests/tsan.rs @@ -4,15 +4,12 @@ use std::{sync::mpsc, thread}; -use heapless::{ - mpmc::Q64, - spsc::{self, MultiCore}, -}; +use heapless::{mpmc::Q64, spsc}; use scoped_threadpool::Pool; #[test] fn once() { - static mut RB: spsc::Queue = spsc::Queue::new(); + static mut RB: spsc::Queue = spsc::Queue::new(); let rb = unsafe { &mut RB }; @@ -33,7 +30,7 @@ fn once() { #[test] fn twice() { - static mut RB: spsc::Queue = spsc::Queue::new(); + static mut RB: spsc::Queue = spsc::Queue::new(); let rb = unsafe { &mut RB }; @@ -55,7 +52,7 @@ fn twice() { #[test] fn scoped() { - let mut rb: spsc::Queue = spsc::Queue::new(); + let mut rb: spsc::Queue = spsc::Queue::new(); rb.enqueue(0).unwrap(); @@ -80,7 +77,7 @@ fn scoped() { fn contention() { const N: usize = 1024; - let mut rb: spsc::Queue = spsc::Queue::new(); + let mut rb: spsc::Queue = spsc::Queue::new(); { let (mut p, mut c) = rb.split(); @@ -167,7 +164,7 @@ fn mpmc_contention() { fn unchecked() { const N: usize = 1024; - let mut rb: spsc::Queue = spsc::Queue::new(); + let mut rb: spsc::Queue = spsc::Queue::new(); for _ in 0..N / 2 { rb.enqueue(1).unwrap(); @@ -203,7 +200,7 @@ fn unchecked() { #[test] fn len_properly_wraps() { const N: usize = 3; - let mut rb: spsc::Queue = spsc::Queue::new(); + let mut rb: spsc::Queue = spsc::Queue::new(); rb.enqueue(1).unwrap(); assert_eq!(rb.len(), 1); @@ -220,7 +217,7 @@ fn len_properly_wraps() { #[test] fn iterator_properly_wraps() { const N: usize = 3; - let mut rb: spsc::Queue = spsc::Queue::new(); + let mut rb: spsc::Queue = spsc::Queue::new(); rb.enqueue(1).unwrap(); rb.dequeue();