Skip to content

Commit e0edbac

Browse files
committed
fix(driver): use AtomicBool instead of AtomicUsize for waits
1 parent d95a88d commit e0edbac

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

compio-driver/src/fd.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{
99
mem::ManuallyDrop,
1010
panic::RefUnwindSafe,
1111
sync::{
12-
atomic::{AtomicUsize, Ordering},
12+
atomic::{AtomicBool, Ordering},
1313
Arc,
1414
},
1515
task::Poll,
@@ -22,7 +22,8 @@ use crate::{AsRawFd, OwnedFd, RawFd};
2222
#[derive(Debug)]
2323
struct Inner {
2424
fd: OwnedFd,
25-
waits: AtomicUsize,
25+
// whether there is a future waiting
26+
waits: AtomicBool,
2627
waker: AtomicWaker,
2728
}
2829

@@ -38,7 +39,7 @@ impl SharedFd {
3839
pub fn new(fd: impl Into<OwnedFd>) -> Self {
3940
Self(Arc::new(Inner {
4041
fd: fd.into(),
41-
waits: AtomicUsize::new(0),
42+
waits: AtomicBool::new(false),
4243
waker: AtomicWaker::new(),
4344
}))
4445
}
@@ -70,7 +71,7 @@ impl SharedFd {
7071
pub fn take(self) -> impl Future<Output = Option<OwnedFd>> {
7172
let this = ManuallyDrop::new(self);
7273
async move {
73-
if this.0.waits.fetch_add(1, Ordering::AcqRel) == 0 {
74+
if !this.0.waits.swap(true, Ordering::AcqRel) {
7475
poll_fn(move |cx| {
7576
if let Some(fd) = unsafe { Self::try_unwrap_inner(&this) } {
7677
return Poll::Ready(Some(fd));

0 commit comments

Comments
 (0)