Skip to content

Commit

Permalink
Merge pull request #725 from garypen/main
Browse files Browse the repository at this point in the history
change HokmaLock::write() to use atomic compare_exchange
  • Loading branch information
schungx committed Jun 15, 2023
2 parents 517f219 + ee6b6d6 commit 55a1dae
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/config/hashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ impl HokmaLock {

pub fn write(&'static self) -> WhenTheHokmaSuppression {
loop {
let previous = self.lock.load(Ordering::SeqCst);
self.lock.store(1, Ordering::SeqCst);

if previous != 1 {
// We are only interested in error results
if let Err(previous) = self
.lock
.compare_exchange(1, 1, Ordering::SeqCst, Ordering::SeqCst)
{
// If we failed, previous cannot be 1
return WhenTheHokmaSuppression {
hokma: self,
state: previous,
Expand Down

0 comments on commit 55a1dae

Please sign in to comment.