Move spin_loop_hint to core::hint module
This commit is contained in:
parent
e2f221c759
commit
24ca530526
3 changed files with 27 additions and 9 deletions
|
@ -49,3 +49,26 @@ use intrinsics;
|
|||
pub unsafe fn unreachable_unchecked() -> ! {
|
||||
intrinsics::unreachable()
|
||||
}
|
||||
|
||||
/// Save power or switch hyperthreads in a busy-wait spin-loop.
|
||||
///
|
||||
/// This function is deliberately more primitive than
|
||||
/// [`std::thread::yield_now`](../../std/thread/fn.yield_now.html) and
|
||||
/// does not directly yield to the system's scheduler.
|
||||
/// In some cases it might be useful to use a combination of both functions.
|
||||
/// Careful benchmarking is advised.
|
||||
///
|
||||
/// On some platforms this function may not do anything at all.
|
||||
#[inline]
|
||||
#[unstable(feature = "renamed_spin_loop", issue = "55002")]
|
||||
pub fn spin_loop() {
|
||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||
unsafe {
|
||||
asm!("pause" ::: "memory" : "volatile");
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
unsafe {
|
||||
asm!("yield" ::: "memory" : "volatile");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue