Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix loom tests
Browse files Browse the repository at this point in the history
james7132 committed Apr 13, 2024
1 parent 124458f commit 45a9e02
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -140,6 +140,13 @@ impl<T> ConcurrentQueue<T> {
///
/// let q = ConcurrentQueue::<i32>::unbounded();
/// ```
#[cfg(not(loom))]
pub const fn unbounded() -> ConcurrentQueue<T> {
ConcurrentQueue(Inner::Unbounded(Unbounded::new()))
}

// Loom's primitives are not const constructible.
#[cfg(loom)]
pub const fn unbounded() -> ConcurrentQueue<T> {
ConcurrentQueue(Inner::Unbounded(Unbounded::new()))
}
16 changes: 16 additions & 0 deletions src/unbounded.rs
Original file line number Diff line number Diff line change
@@ -149,6 +149,7 @@ pub struct Unbounded<T> {

impl<T> Unbounded<T> {
/// Creates a new unbounded queue.
#[cfg(not(loom))]
pub const fn new() -> Unbounded<T> {
Unbounded {
head: CachePadded::new(Position {
@@ -162,6 +163,21 @@ impl<T> Unbounded<T> {
}
}

// Loom's AtomicPtrs are not const constructible.
#[cfg(loom)]
pub fn new() -> Unbounded<T> {
Unbounded {
head: CachePadded::new(Position {
block: AtomicPtr::new(ptr::null_mut()),
index: AtomicUsize::new(0),
}),
tail: CachePadded::new(Position {
block: AtomicPtr::new(ptr::null_mut()),
index: AtomicUsize::new(0),
}),
}
}

/// Pushes an item into the queue.
pub fn push(&self, value: T) -> Result<(), PushError<T>> {
let mut tail = self.tail.index.load(Ordering::Acquire);

0 comments on commit 45a9e02

Please sign in to comment.