Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated function compare_and_swap #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ where
}
}

// compare_and_swap returns the last value on success,
// or the current value on failure. We want to keep
// compare_exchange returns Ok with the last value on success,
// or Err with the current value on failure. We want to keep
// looping as long as it returns true, so we don't need
// any explicit conversion here.
while self.init_mu.compare_and_swap(false, true, SeqCst) {}
while self.init_mu.compare_exchange(false, true, SeqCst, SeqCst).unwrap_or_else(|x| x) {}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be more concise

Suggested change
while self.init_mu.compare_exchange(false, true, SeqCst, SeqCst).unwrap_or_else(|x| x) {}
while self
.init_mu
.compare_exchange(false, true, SeqCst, SeqCst)
.is_err()
{}


{
let value_ptr = self.value.load(SeqCst);
Expand Down