Skip to content
Draft
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
2 changes: 1 addition & 1 deletion library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3181,7 +3181,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
// Acquire is necessary for the success case to synchronise with `Arc::new_cyclic`, when the inner
// value can be initialized after `Weak` references have already been created. In that case, we
// expect to observe the fully initialized value.
if self.inner()?.strong.fetch_update(Acquire, Relaxed, checked_increment).is_ok() {
if self.inner()?.strong.try_update(Acquire, Relaxed, checked_increment).is_ok() {
// SAFETY: pointer is not null, verified in checked_increment
unsafe { Some(Arc::from_inner_in(self.ptr, self.alloc.clone())) }
} else {
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/alloc/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use crate::{cmp, ptr};
/// let mut allocated = 0;
/// if self
/// .remaining
/// .fetch_update(Relaxed, Relaxed, |mut remaining| {
/// .try_update(Relaxed, Relaxed, |mut remaining| {
/// if size > remaining {
/// return None;
/// }
Expand Down
255 changes: 59 additions & 196 deletions library/core/src/sync/atomic.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion library/std/src/sys/sync/condvar/xous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Condvar {
// possible for `counter` to decrease due to a condvar timing out, in which
// case the corresponding `timed_out` will increase accordingly.
let Ok(waiter_count) =
self.counter.fetch_update(Ordering::Relaxed, Ordering::Relaxed, |counter| {
self.counter.try_update(Ordering::Relaxed, Ordering::Relaxed, |counter| {
if counter == 0 {
return None;
} else {
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/sys/sync/rwlock/futex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl RwLock {
#[inline]
pub fn try_read(&self) -> bool {
self.state
.fetch_update(Acquire, Relaxed, |s| is_read_lockable(s).then(|| s + READ_LOCKED))
.try_update(Acquire, Relaxed, |s| is_read_lockable(s).then(|| s + READ_LOCKED))
.is_ok()
}

Expand Down Expand Up @@ -164,7 +164,7 @@ impl RwLock {
#[inline]
pub fn try_write(&self) -> bool {
self.state
.fetch_update(Acquire, Relaxed, |s| is_unlocked(s).then(|| s + WRITE_LOCKED))
.try_update(Acquire, Relaxed, |s| is_unlocked(s).then(|| s + WRITE_LOCKED))
.is_ok()
}

Expand Down
6 changes: 3 additions & 3 deletions library/std/src/sys/sync/rwlock/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ impl RwLock {

#[inline]
pub fn try_read(&self) -> bool {
self.state.fetch_update(Acquire, Relaxed, read_lock).is_ok()
self.state.try_update(Acquire, Relaxed, read_lock).is_ok()
}

#[inline]
Expand All @@ -343,7 +343,7 @@ impl RwLock {
pub fn try_write(&self) -> bool {
// Atomically set the `LOCKED` bit. This is lowered to a single atomic instruction on most
// modern processors (e.g. "lock bts" on x86 and "ldseta" on modern AArch64), and therefore
// is more efficient than `fetch_update(lock(true))`, which can spuriously fail if a new
// is more efficient than `try_update(lock(true))`, which can spuriously fail if a new
// node is appended to the queue.
self.state.fetch_or(LOCKED, Acquire).addr() & LOCKED == 0
}
Expand Down Expand Up @@ -453,7 +453,7 @@ impl RwLock {

#[inline]
pub unsafe fn read_unlock(&self) {
match self.state.fetch_update(Release, Acquire, |state| {
match self.state.try_update(Release, Acquire, |state| {
if state.addr() & QUEUED == 0 {
// If there are no threads queued, simply decrement the reader count.
let count = state.addr() - (SINGLE | LOCKED);
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/lint/lint-invalid-atomic-ordering-update.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//@ only-x86_64
#![feature(atomic_try_update)]

use std::sync::atomic::{AtomicIsize, Ordering};

fn main() {
Expand Down
60 changes: 30 additions & 30 deletions tests/ui/lint/lint-invalid-atomic-ordering-update.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: `fetch_update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `fetch_update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:73:47
--> $DIR/lint-invalid-atomic-ordering-update.rs:71:47
|
LL | let _ = x.fetch_update(Ordering::Relaxed, Ordering::AcqRel, |old| Some(old + 1));
| ^^^^^^^^^^^^^^^^ invalid failure ordering
Expand All @@ -8,231 +8,231 @@ LL | let _ = x.fetch_update(Ordering::Relaxed, Ordering::AcqRel, |old| Some(
= note: `#[deny(invalid_atomic_ordering)]` on by default

error: `try_update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `try_update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:75:45
--> $DIR/lint-invalid-atomic-ordering-update.rs:73:45
|
LL | let _ = x.try_update(Ordering::Relaxed, Ordering::AcqRel, |old| Some(old + 1));
| ^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:77:41
--> $DIR/lint-invalid-atomic-ordering-update.rs:75:41
|
LL | let _ = x.update(Ordering::Relaxed, Ordering::AcqRel, |old| old + 1);
| ^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `fetch_update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `fetch_update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:80:47
--> $DIR/lint-invalid-atomic-ordering-update.rs:78:47
|
LL | let _ = x.fetch_update(Ordering::Acquire, Ordering::AcqRel, |old| Some(old + 1));
| ^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `try_update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `try_update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:82:45
--> $DIR/lint-invalid-atomic-ordering-update.rs:80:45
|
LL | let _ = x.try_update(Ordering::Acquire, Ordering::AcqRel, |old| Some(old + 1));
| ^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:84:41
--> $DIR/lint-invalid-atomic-ordering-update.rs:82:41
|
LL | let _ = x.update(Ordering::Acquire, Ordering::AcqRel, |old| old + 1);
| ^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `fetch_update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `fetch_update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:87:47
--> $DIR/lint-invalid-atomic-ordering-update.rs:85:47
|
LL | let _ = x.fetch_update(Ordering::Release, Ordering::AcqRel, |old| Some(old + 1));
| ^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `try_update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `try_update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:89:45
--> $DIR/lint-invalid-atomic-ordering-update.rs:87:45
|
LL | let _ = x.try_update(Ordering::Release, Ordering::AcqRel, |old| Some(old + 1));
| ^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:91:41
--> $DIR/lint-invalid-atomic-ordering-update.rs:89:41
|
LL | let _ = x.update(Ordering::Release, Ordering::AcqRel, |old| old + 1);
| ^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `fetch_update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `fetch_update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:94:46
--> $DIR/lint-invalid-atomic-ordering-update.rs:92:46
|
LL | let _ = x.fetch_update(Ordering::AcqRel, Ordering::AcqRel, |old| Some(old + 1));
| ^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `try_update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `try_update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:96:44
--> $DIR/lint-invalid-atomic-ordering-update.rs:94:44
|
LL | let _ = x.try_update(Ordering::AcqRel, Ordering::AcqRel, |old| Some(old + 1));
| ^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:98:40
--> $DIR/lint-invalid-atomic-ordering-update.rs:96:40
|
LL | let _ = x.update(Ordering::AcqRel, Ordering::AcqRel, |old| old + 1);
| ^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `fetch_update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `fetch_update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:101:46
--> $DIR/lint-invalid-atomic-ordering-update.rs:99:46
|
LL | let _ = x.fetch_update(Ordering::SeqCst, Ordering::AcqRel, |old| Some(old + 1));
| ^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `try_update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `try_update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:103:44
--> $DIR/lint-invalid-atomic-ordering-update.rs:101:44
|
LL | let _ = x.try_update(Ordering::SeqCst, Ordering::AcqRel, |old| Some(old + 1));
| ^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:105:40
--> $DIR/lint-invalid-atomic-ordering-update.rs:103:40
|
LL | let _ = x.update(Ordering::SeqCst, Ordering::AcqRel, |old| old + 1);
| ^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `fetch_update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `fetch_update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:110:47
--> $DIR/lint-invalid-atomic-ordering-update.rs:108:47
|
LL | let _ = x.fetch_update(Ordering::Relaxed, Ordering::Release, |old| Some(old + 1));
| ^^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `try_update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `try_update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:112:45
--> $DIR/lint-invalid-atomic-ordering-update.rs:110:45
|
LL | let _ = x.try_update(Ordering::Relaxed, Ordering::Release, |old| Some(old + 1));
| ^^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:114:41
--> $DIR/lint-invalid-atomic-ordering-update.rs:112:41
|
LL | let _ = x.update(Ordering::Relaxed, Ordering::Release, |old| old + 1);
| ^^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `fetch_update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `fetch_update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:117:47
--> $DIR/lint-invalid-atomic-ordering-update.rs:115:47
|
LL | let _ = x.fetch_update(Ordering::Acquire, Ordering::Release, |old| Some(old + 1));
| ^^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `try_update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `try_update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:119:45
--> $DIR/lint-invalid-atomic-ordering-update.rs:117:45
|
LL | let _ = x.try_update(Ordering::Acquire, Ordering::Release, |old| Some(old + 1));
| ^^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:121:41
--> $DIR/lint-invalid-atomic-ordering-update.rs:119:41
|
LL | let _ = x.update(Ordering::Acquire, Ordering::Release, |old| old + 1);
| ^^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `fetch_update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `fetch_update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:124:47
--> $DIR/lint-invalid-atomic-ordering-update.rs:122:47
|
LL | let _ = x.fetch_update(Ordering::Release, Ordering::Release, |old| Some(old + 1));
| ^^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `try_update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `try_update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:126:45
--> $DIR/lint-invalid-atomic-ordering-update.rs:124:45
|
LL | let _ = x.try_update(Ordering::Release, Ordering::Release, |old| Some(old + 1));
| ^^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:128:41
--> $DIR/lint-invalid-atomic-ordering-update.rs:126:41
|
LL | let _ = x.update(Ordering::Release, Ordering::Release, |old| old + 1);
| ^^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `fetch_update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `fetch_update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:131:46
--> $DIR/lint-invalid-atomic-ordering-update.rs:129:46
|
LL | let _ = x.fetch_update(Ordering::AcqRel, Ordering::Release, |old| Some(old + 1));
| ^^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `try_update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `try_update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:133:44
--> $DIR/lint-invalid-atomic-ordering-update.rs:131:44
|
LL | let _ = x.try_update(Ordering::AcqRel, Ordering::Release, |old| Some(old + 1));
| ^^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:135:40
--> $DIR/lint-invalid-atomic-ordering-update.rs:133:40
|
LL | let _ = x.update(Ordering::AcqRel, Ordering::Release, |old| old + 1);
| ^^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `fetch_update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `fetch_update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:138:46
--> $DIR/lint-invalid-atomic-ordering-update.rs:136:46
|
LL | let _ = x.fetch_update(Ordering::SeqCst, Ordering::Release, |old| Some(old + 1));
| ^^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `try_update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `try_update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:140:44
--> $DIR/lint-invalid-atomic-ordering-update.rs:138:44
|
LL | let _ = x.try_update(Ordering::SeqCst, Ordering::Release, |old| Some(old + 1));
| ^^^^^^^^^^^^^^^^^ invalid failure ordering
|
= help: consider using `Acquire` or `Relaxed` failure ordering instead

error: `update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-update.rs:142:40
--> $DIR/lint-invalid-atomic-ordering-update.rs:140:40
|
LL | let _ = x.update(Ordering::SeqCst, Ordering::Release, |old| old + 1);
| ^^^^^^^^^^^^^^^^^ invalid failure ordering
Expand Down
Loading