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

AcqRel -> Release for compare_exchange success ordering in race module #221

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

-

## 1.17.1

- Make `OnceRef` implementation compliant with [strict provenance](https://github.com/rust-lang/rust/issues/95228).
- Weaken `compare_exchange` success case ordering in `race::*` implementations
from `AcqRel` to `Release`, [#xxx](https://github.com/matklad/once_cell/pull/xxx)

## 1.17.0

- Add `race::OnceRef` for storing a `&'a T`.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "once_cell"
version = "1.17.0"
version = "1.17.1"
authors = ["Aleksey Kladov <[email protected]>"]
license = "MIT OR Apache-2.0"
edition = "2021"
Expand Down
12 changes: 6 additions & 6 deletions src/race.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl OnceNonZeroUsize {
#[inline]
pub fn set(&self, value: NonZeroUsize) -> Result<(), ()> {
let exchange =
self.inner.compare_exchange(0, value.get(), Ordering::AcqRel, Ordering::Acquire);
self.inner.compare_exchange(0, value.get(), Ordering::Release, Ordering::Acquire);
match exchange {
Ok(_) => Ok(()),
Err(_) => Err(()),
Expand Down Expand Up @@ -98,7 +98,7 @@ impl OnceNonZeroUsize {
None => {
let mut val = f()?.get();
let exchange =
self.inner.compare_exchange(0, val, Ordering::AcqRel, Ordering::Acquire);
self.inner.compare_exchange(0, val, Ordering::Release, Ordering::Acquire);
if let Err(old) = exchange {
val = old;
}
Expand Down Expand Up @@ -215,7 +215,7 @@ impl<'a, T> OnceRef<'a, T> {
pub fn set(&self, value: &'a T) -> Result<(), ()> {
let ptr = value as *const T as *mut T;
let exchange =
self.inner.compare_exchange(ptr::null_mut(), ptr, Ordering::AcqRel, Ordering::Acquire);
self.inner.compare_exchange(ptr::null_mut(), ptr, Ordering::Release, Ordering::Acquire);
match exchange {
Ok(_) => Ok(()),
Err(_) => Err(()),
Expand Down Expand Up @@ -258,7 +258,7 @@ impl<'a, T> OnceRef<'a, T> {
let exchange = self.inner.compare_exchange(
ptr::null_mut(),
ptr,
Ordering::AcqRel,
Ordering::Release,
Ordering::Acquire,
);
if let Err(old) = exchange {
Expand Down Expand Up @@ -348,7 +348,7 @@ mod once_box {
let exchange = self.inner.compare_exchange(
ptr::null_mut(),
ptr,
Ordering::AcqRel,
Ordering::Release,
Ordering::Acquire,
);
if let Err(_) = exchange {
Expand Down Expand Up @@ -394,7 +394,7 @@ mod once_box {
let exchange = self.inner.compare_exchange(
ptr::null_mut(),
ptr,
Ordering::AcqRel,
Ordering::Release,
Ordering::Acquire,
);
if let Err(old) = exchange {
Expand Down