Skip to content

Commit

Permalink
mpmc: use cmp() as per clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
jordens committed Nov 17, 2023
1 parent d9b06bd commit ef899ce
Showing 1 changed file with 38 additions and 32 deletions.
70 changes: 38 additions & 32 deletions src/mpmc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ impl<T> Cell<T> {
}
}

#[allow(clippy::comparison_chain)]
unsafe fn dequeue<T>(
buffer: *mut Cell<T>,
dequeue_pos: &AtomicTargetSize,
Expand All @@ -219,22 +218,26 @@ unsafe fn dequeue<T>(
let seq = (*cell).sequence.load(Ordering::Acquire);
let dif = (seq as i8).wrapping_sub((pos.wrapping_add(1)) as i8);

if dif == 0 {
if dequeue_pos
.compare_exchange_weak(
pos,
pos.wrapping_add(1),
Ordering::Relaxed,
Ordering::Relaxed,
)
.is_ok()
{
break;
match dif.cmp(&0) {
core::cmp::Ordering::Equal => {
if dequeue_pos
.compare_exchange_weak(
pos,
pos.wrapping_add(1),
Ordering::Relaxed,
Ordering::Relaxed,
)
.is_ok()
{
break;
}
}
core::cmp::Ordering::Less => {
return None;
}
core::cmp::Ordering::Greater => {
pos = dequeue_pos.load(Ordering::Relaxed);
}
} else if dif < 0 {
return None;
} else {
pos = dequeue_pos.load(Ordering::Relaxed);
}
}

Expand All @@ -245,7 +248,6 @@ unsafe fn dequeue<T>(
Some(data)
}

#[allow(clippy::comparison_chain)]
unsafe fn enqueue<T>(
buffer: *mut Cell<T>,
enqueue_pos: &AtomicTargetSize,
Expand All @@ -260,22 +262,26 @@ unsafe fn enqueue<T>(
let seq = (*cell).sequence.load(Ordering::Acquire);
let dif = (seq as i8).wrapping_sub(pos as i8);

if dif == 0 {
if enqueue_pos
.compare_exchange_weak(
pos,
pos.wrapping_add(1),
Ordering::Relaxed,
Ordering::Relaxed,
)
.is_ok()
{
break;
match dif.cmp(&0) {
core::cmp::Ordering::Equal => {
if enqueue_pos
.compare_exchange_weak(
pos,
pos.wrapping_add(1),
Ordering::Relaxed,
Ordering::Relaxed,
)
.is_ok()
{
break;
}
}
core::cmp::Ordering::Less => {
return Err(item);
}
core::cmp::Ordering::Greater => {
pos = enqueue_pos.load(Ordering::Relaxed);
}
} else if dif < 0 {
return Err(item);
} else {
pos = enqueue_pos.load(Ordering::Relaxed);
}
}

Expand Down

0 comments on commit ef899ce

Please sign in to comment.