Skip to content

Commit

Permalink
chore: Move fetch_and after the prev_value check
Browse files Browse the repository at this point in the history
cc #58 (comment)

Signed-off-by: John Nunley <[email protected]>
  • Loading branch information
notgull committed Apr 23, 2024
1 parent 576965a commit e232ec9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ impl<T> Single<T> {
.with_mut(move |slot| ptr::replace(slot, MaybeUninit::new(value)))
};

// We can unlock the slot now.
self.state.fetch_and(!LOCKED, Ordering::Release);

// If the value was pushed, initialize it and return it.
let prev_value = if prev & PUSHED == 0 {
None
} else {
Some(unsafe { prev_value.assume_init() })
};

// We can unlock the slot now.
self.state.fetch_and(!LOCKED, Ordering::Release);

// Return the old value.
return Ok(prev_value);
}
Expand Down

0 comments on commit e232ec9

Please sign in to comment.