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

Deprecate atomic::spin_loop_hint in favour of hint::spin_loop #80966

Merged
merged 1 commit into from
Jan 14, 2021
Merged
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/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ fn test_weak_count_locked() {
let n = Arc::weak_count(&a2);
assert!(n < 2, "bad weak count: {}", n);
#[cfg(miri)] // Miri's scheduler does not guarantee liveness, and thus needs this hint.
atomic::spin_loop_hint();
std::hint::spin_loop();
}
t.join().unwrap();
}
Expand Down
27 changes: 12 additions & 15 deletions library/core/src/sync/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,6 @@ use crate::intrinsics;

use crate::hint::spin_loop;

/// Signals the processor that it is inside a busy-wait spin-loop ("spin lock").
///
/// This function is expected to be deprecated in favor of
/// [`hint::spin_loop`].
///
/// **Note**: On platforms that do not support receiving spin-loop hints this function does not
/// do anything at all.
///
/// [`hint::spin_loop`]: crate::hint::spin_loop
#[inline]
#[stable(feature = "spin_loop_hint", since = "1.24.0")]
pub fn spin_loop_hint() {
spin_loop()
}

/// A boolean type which can be safely shared between threads.
///
/// This type has the same in-memory representation as a [`bool`].
Expand Down Expand Up @@ -2791,3 +2776,15 @@ impl<T> fmt::Pointer for AtomicPtr<T> {
fmt::Pointer::fmt(&self.load(Ordering::SeqCst), f)
}
}

/// Signals the processor that it is inside a busy-wait spin-loop ("spin lock").
///
/// This function is deprecated in favor of [`hint::spin_loop`].
///
/// [`hint::spin_loop`]: crate::hint::spin_loop
#[inline]
#[stable(feature = "spin_loop_hint", since = "1.24.0")]
#[rustc_deprecated(since = "1.51.0", reason = "use hint::spin_loop instead")]
pub fn spin_loop_hint() {
spin_loop()
}
5 changes: 3 additions & 2 deletions library/std/src/sys/hermit/mutex.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::cell::UnsafeCell;
use crate::collections::VecDeque;
use crate::ffi::c_void;
use crate::hint;
use crate::ops::{Deref, DerefMut, Drop};
use crate::ptr;
use crate::sync::atomic::{spin_loop_hint, AtomicUsize, Ordering};
use crate::sync::atomic::{AtomicUsize, Ordering};
use crate::sys::hermit::abi;

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

Expand Down
5 changes: 3 additions & 2 deletions library/std/src/sys/sgx/waitqueue/spin_mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
mod tests;

use crate::cell::UnsafeCell;
use crate::hint;
use crate::ops::{Deref, DerefMut};
use crate::sync::atomic::{spin_loop_hint, AtomicBool, Ordering};
use crate::sync::atomic::{AtomicBool, Ordering};

#[derive(Default)]
pub struct SpinMutex<T> {
Expand Down Expand Up @@ -32,7 +33,7 @@ impl<T> SpinMutex<T> {
match self.try_lock() {
None => {
while self.lock.load(Ordering::Relaxed) {
spin_loop_hint()
hint::spin_loop()
}
}
Some(guard) => return guard,
Expand Down