Skip to content

Commit 7855a73

Browse files
authored
Rollup merge of #80966 - KodrAus:deprecate/spin_loop_hint, r=m-ou-se
Deprecate atomic::spin_loop_hint in favour of hint::spin_loop For #55002 We wanted to leave `atomic::spin_loop_hint` alone when stabilizing `hint::spin_loop` so folks had some time to migrate. This now deprecates `atomic_spin_loop_hint`.
2 parents ce48709 + d65cb6e commit 7855a73

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

library/alloc/src/sync/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ fn test_weak_count_locked() {
370370
let n = Arc::weak_count(&a2);
371371
assert!(n < 2, "bad weak count: {}", n);
372372
#[cfg(miri)] // Miri's scheduler does not guarantee liveness, and thus needs this hint.
373-
atomic::spin_loop_hint();
373+
std::hint::spin_loop();
374374
}
375375
t.join().unwrap();
376376
}

library/core/src/sync/atomic.rs

+12-15
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,6 @@ use crate::intrinsics;
120120

121121
use crate::hint::spin_loop;
122122

123-
/// Signals the processor that it is inside a busy-wait spin-loop ("spin lock").
124-
///
125-
/// This function is expected to be deprecated in favor of
126-
/// [`hint::spin_loop`].
127-
///
128-
/// **Note**: On platforms that do not support receiving spin-loop hints this function does not
129-
/// do anything at all.
130-
///
131-
/// [`hint::spin_loop`]: crate::hint::spin_loop
132-
#[inline]
133-
#[stable(feature = "spin_loop_hint", since = "1.24.0")]
134-
pub fn spin_loop_hint() {
135-
spin_loop()
136-
}
137-
138123
/// A boolean type which can be safely shared between threads.
139124
///
140125
/// This type has the same in-memory representation as a [`bool`].
@@ -2791,3 +2776,15 @@ impl<T> fmt::Pointer for AtomicPtr<T> {
27912776
fmt::Pointer::fmt(&self.load(Ordering::SeqCst), f)
27922777
}
27932778
}
2779+
2780+
/// Signals the processor that it is inside a busy-wait spin-loop ("spin lock").
2781+
///
2782+
/// This function is deprecated in favor of [`hint::spin_loop`].
2783+
///
2784+
/// [`hint::spin_loop`]: crate::hint::spin_loop
2785+
#[inline]
2786+
#[stable(feature = "spin_loop_hint", since = "1.24.0")]
2787+
#[rustc_deprecated(since = "1.51.0", reason = "use hint::spin_loop instead")]
2788+
pub fn spin_loop_hint() {
2789+
spin_loop()
2790+
}

library/std/src/sys/hermit/mutex.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use crate::cell::UnsafeCell;
22
use crate::collections::VecDeque;
33
use crate::ffi::c_void;
4+
use crate::hint;
45
use crate::ops::{Deref, DerefMut, Drop};
56
use crate::ptr;
6-
use crate::sync::atomic::{spin_loop_hint, AtomicUsize, Ordering};
7+
use crate::sync::atomic::{AtomicUsize, Ordering};
78
use crate::sys::hermit::abi;
89

910
/// This type provides a lock based on busy waiting to realize mutual exclusion
@@ -46,7 +47,7 @@ impl<T> Spinlock<T> {
4647
fn obtain_lock(&self) {
4748
let ticket = self.queue.fetch_add(1, Ordering::SeqCst) + 1;
4849
while self.dequeue.load(Ordering::SeqCst) != ticket {
49-
spin_loop_hint();
50+
hint::spin_loop();
5051
}
5152
}
5253

library/std/src/sys/sgx/waitqueue/spin_mutex.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
mod tests;
33

44
use crate::cell::UnsafeCell;
5+
use crate::hint;
56
use crate::ops::{Deref, DerefMut};
6-
use crate::sync::atomic::{spin_loop_hint, AtomicBool, Ordering};
7+
use crate::sync::atomic::{AtomicBool, Ordering};
78

89
#[derive(Default)]
910
pub struct SpinMutex<T> {
@@ -32,7 +33,7 @@ impl<T> SpinMutex<T> {
3233
match self.try_lock() {
3334
None => {
3435
while self.lock.load(Ordering::Relaxed) {
35-
spin_loop_hint()
36+
hint::spin_loop()
3637
}
3738
}
3839
Some(guard) => return guard,

0 commit comments

Comments
 (0)