Skip to content

Commit ef899ce

Browse files
committed
mpmc: use cmp() as per clippy
c.f. #411
1 parent d9b06bd commit ef899ce

File tree

1 file changed

+38
-32
lines changed

1 file changed

+38
-32
lines changed

src/mpmc.rs

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ impl<T> Cell<T> {
205205
}
206206
}
207207

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

222-
if dif == 0 {
223-
if dequeue_pos
224-
.compare_exchange_weak(
225-
pos,
226-
pos.wrapping_add(1),
227-
Ordering::Relaxed,
228-
Ordering::Relaxed,
229-
)
230-
.is_ok()
231-
{
232-
break;
221+
match dif.cmp(&0) {
222+
core::cmp::Ordering::Equal => {
223+
if dequeue_pos
224+
.compare_exchange_weak(
225+
pos,
226+
pos.wrapping_add(1),
227+
Ordering::Relaxed,
228+
Ordering::Relaxed,
229+
)
230+
.is_ok()
231+
{
232+
break;
233+
}
234+
}
235+
core::cmp::Ordering::Less => {
236+
return None;
237+
}
238+
core::cmp::Ordering::Greater => {
239+
pos = dequeue_pos.load(Ordering::Relaxed);
233240
}
234-
} else if dif < 0 {
235-
return None;
236-
} else {
237-
pos = dequeue_pos.load(Ordering::Relaxed);
238241
}
239242
}
240243

@@ -245,7 +248,6 @@ unsafe fn dequeue<T>(
245248
Some(data)
246249
}
247250

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

263-
if dif == 0 {
264-
if enqueue_pos
265-
.compare_exchange_weak(
266-
pos,
267-
pos.wrapping_add(1),
268-
Ordering::Relaxed,
269-
Ordering::Relaxed,
270-
)
271-
.is_ok()
272-
{
273-
break;
265+
match dif.cmp(&0) {
266+
core::cmp::Ordering::Equal => {
267+
if enqueue_pos
268+
.compare_exchange_weak(
269+
pos,
270+
pos.wrapping_add(1),
271+
Ordering::Relaxed,
272+
Ordering::Relaxed,
273+
)
274+
.is_ok()
275+
{
276+
break;
277+
}
278+
}
279+
core::cmp::Ordering::Less => {
280+
return Err(item);
281+
}
282+
core::cmp::Ordering::Greater => {
283+
pos = enqueue_pos.load(Ordering::Relaxed);
274284
}
275-
} else if dif < 0 {
276-
return Err(item);
277-
} else {
278-
pos = enqueue_pos.load(Ordering::Relaxed);
279285
}
280286
}
281287

0 commit comments

Comments
 (0)