Skip to content

Commit c78d199

Browse files
committed
fix: atomic cas
1 parent e7a6dc1 commit c78d199

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

monoio/src/task/state.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ impl State {
8080
Snapshot(self.0.load(Acquire))
8181
}
8282

83+
#[allow(dead_code)]
8384
pub(crate) fn store(&self, val: Snapshot) {
8485
self.0.store(val.0, Release);
8586
}
@@ -156,12 +157,18 @@ impl State {
156157
/// Optimistically tries to swap the state assuming the join handle is
157158
/// __immediately__ dropped on spawn
158159
pub(super) fn drop_join_handle_fast(&self) -> Result<(), ()> {
159-
if *self.load() == INITIAL_STATE {
160-
self.store(Snapshot((INITIAL_STATE - REF_ONE) & !JOIN_INTEREST));
161-
trace!("MONOIO DEBUG[State]: drop_join_handle_fast");
162-
Ok(())
163-
} else {
164-
Err(())
160+
match self.fetch_update(|curr| {
161+
if *curr == INITIAL_STATE {
162+
Some(Snapshot((INITIAL_STATE - REF_ONE) & !JOIN_INTEREST))
163+
} else {
164+
None
165+
}
166+
}) {
167+
Ok(_) => {
168+
trace!("MONOIO DEBUG[State]: drop_join_handle_fast");
169+
Ok(())
170+
}
171+
Err(_) => Err(()),
165172
}
166173
}
167174

0 commit comments

Comments
 (0)