Skip to content

Commit 0733988

Browse files
committed
Stabilize atomic_try_update
and deprecate fetch_update starting 1.96.0
1 parent c268b39 commit 0733988

File tree

11 files changed

+141
-282
lines changed

11 files changed

+141
-282
lines changed

library/alloc/src/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3186,7 +3186,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
31863186
// Acquire is necessary for the success case to synchronise with `Arc::new_cyclic`, when the inner
31873187
// value can be initialized after `Weak` references have already been created. In that case, we
31883188
// expect to observe the fully initialized value.
3189-
if self.inner()?.strong.fetch_update(Acquire, Relaxed, checked_increment).is_ok() {
3189+
if self.inner()?.strong.try_update(Acquire, Relaxed, checked_increment).is_ok() {
31903190
// SAFETY: pointer is not null, verified in checked_increment
31913191
unsafe { Some(Arc::from_inner_in(self.ptr, self.alloc.clone())) }
31923192
} else {

library/core/src/alloc/global.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use crate::{cmp, ptr};
5757
/// let mut allocated = 0;
5858
/// if self
5959
/// .remaining
60-
/// .fetch_update(Relaxed, Relaxed, |mut remaining| {
60+
/// .try_update(Relaxed, Relaxed, |mut remaining| {
6161
/// if size > remaining {
6262
/// return None;
6363
/// }

library/core/src/sync/atomic.rs

Lines changed: 59 additions & 196 deletions
Large diffs are not rendered by default.

library/std/src/sys/sync/condvar/xous.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl Condvar {
3838
// possible for `counter` to decrease due to a condvar timing out, in which
3939
// case the corresponding `timed_out` will increase accordingly.
4040
let Ok(waiter_count) =
41-
self.counter.fetch_update(Ordering::Relaxed, Ordering::Relaxed, |counter| {
41+
self.counter.try_update(Ordering::Relaxed, Ordering::Relaxed, |counter| {
4242
if counter == 0 {
4343
return None;
4444
} else {

library/std/src/sys/sync/rwlock/futex.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl RwLock {
8686
#[inline]
8787
pub fn try_read(&self) -> bool {
8888
self.state
89-
.fetch_update(Acquire, Relaxed, |s| is_read_lockable(s).then(|| s + READ_LOCKED))
89+
.try_update(Acquire, Relaxed, |s| is_read_lockable(s).then(|| s + READ_LOCKED))
9090
.is_ok()
9191
}
9292

@@ -164,7 +164,7 @@ impl RwLock {
164164
#[inline]
165165
pub fn try_write(&self) -> bool {
166166
self.state
167-
.fetch_update(Acquire, Relaxed, |s| is_unlocked(s).then(|| s + WRITE_LOCKED))
167+
.try_update(Acquire, Relaxed, |s| is_unlocked(s).then(|| s + WRITE_LOCKED))
168168
.is_ok()
169169
}
170170

library/std/src/sys/sync/rwlock/queue.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ impl RwLock {
329329

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

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

454454
#[inline]
455455
pub unsafe fn read_unlock(&self) {
456-
match self.state.fetch_update(Release, Acquire, |state| {
456+
match self.state.try_update(Release, Acquire, |state| {
457457
if state.addr() & QUEUED == 0 {
458458
// If there are no threads queued, simply decrement the reader count.
459459
let count = state.addr() - (SINGLE | LOCKED);

tests/ui/lint/const-item-interior-mutations-const-atomics.fixed

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#![allow(deprecated)]
55
#![allow(dead_code)]
6-
#![feature(atomic_try_update)]
76

87
use std::sync::atomic::{AtomicBool, AtomicPtr, AtomicU32, Ordering};
98

tests/ui/lint/const-item-interior-mutations-const-atomics.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#![allow(deprecated)]
55
#![allow(dead_code)]
6-
#![feature(atomic_try_update)]
76

87
use std::sync::atomic::{AtomicBool, AtomicPtr, AtomicU32, Ordering};
98

0 commit comments

Comments
 (0)