Skip to content

Commit

Permalink
fix: atomic cas
Browse files Browse the repository at this point in the history
  • Loading branch information
NKID00 committed Aug 24, 2024
1 parent e7a6dc1 commit c78d199
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions monoio/src/task/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ impl State {
Snapshot(self.0.load(Acquire))
}

#[allow(dead_code)]
pub(crate) fn store(&self, val: Snapshot) {
self.0.store(val.0, Release);
}
Expand Down Expand Up @@ -156,12 +157,18 @@ impl State {
/// Optimistically tries to swap the state assuming the join handle is
/// __immediately__ dropped on spawn
pub(super) fn drop_join_handle_fast(&self) -> Result<(), ()> {
if *self.load() == INITIAL_STATE {
self.store(Snapshot((INITIAL_STATE - REF_ONE) & !JOIN_INTEREST));
trace!("MONOIO DEBUG[State]: drop_join_handle_fast");
Ok(())
} else {
Err(())
match self.fetch_update(|curr| {
if *curr == INITIAL_STATE {
Some(Snapshot((INITIAL_STATE - REF_ONE) & !JOIN_INTEREST))
} else {
None
}
}) {
Ok(_) => {
trace!("MONOIO DEBUG[State]: drop_join_handle_fast");
Ok(())
}
Err(_) => Err(()),
}
}

Expand Down

0 comments on commit c78d199

Please sign in to comment.