Skip to content

Commit 7ffe34e

Browse files
committed
Stabilize atomic_try_update
and deprecate fetch_update starting 1.96.0
1 parent 20f1c04 commit 7ffe34e

File tree

8 files changed

+97
-236
lines changed

8 files changed

+97
-236
lines changed

library/alloc/src/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3181,7 +3181,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
31813181
// Acquire is necessary for the success case to synchronise with `Arc::new_cyclic`, when the inner
31823182
// value can be initialized after `Weak` references have already been created. In that case, we
31833183
// expect to observe the fully initialized value.
3184-
if self.inner()?.strong.fetch_update(Acquire, Relaxed, checked_increment).is_ok() {
3184+
if self.inner()?.strong.try_update(Acquire, Relaxed, checked_increment).is_ok() {
31853185
// SAFETY: pointer is not null, verified in checked_increment
31863186
unsafe { Some(Arc::from_inner_in(self.ptr, self.alloc.clone())) }
31873187
} 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/lint-invalid-atomic-ordering-update.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
//@ only-x86_64
2-
#![feature(atomic_try_update)]
3-
42
use std::sync::atomic::{AtomicIsize, Ordering};
53

64
fn main() {

tests/ui/lint/lint-invalid-atomic-ordering-update.stderr

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: `fetch_update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `fetch_update` does not result in a write
2-
--> $DIR/lint-invalid-atomic-ordering-update.rs:73:47
2+
--> $DIR/lint-invalid-atomic-ordering-update.rs:71:47
33
|
44
LL | let _ = x.fetch_update(Ordering::Relaxed, Ordering::AcqRel, |old| Some(old + 1));
55
| ^^^^^^^^^^^^^^^^ invalid failure ordering
@@ -8,231 +8,231 @@ LL | let _ = x.fetch_update(Ordering::Relaxed, Ordering::AcqRel, |old| Some(
88
= note: `#[deny(invalid_atomic_ordering)]` on by default
99

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)