From 6ceb5f4bec83b525c5df409559272f0e10863f6a Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Wed, 22 Nov 2017 00:00:01 +0100 Subject: [PATCH 1/3] Stabilize spin_loop_hint --- .../{hint-core-should-pause.md => spin-loop-hint.md} | 8 ++++---- src/libcore/sync/atomic.rs | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) rename src/doc/unstable-book/src/library-features/{hint-core-should-pause.md => spin-loop-hint.md} (80%) diff --git a/src/doc/unstable-book/src/library-features/hint-core-should-pause.md b/src/doc/unstable-book/src/library-features/spin-loop-hint.md similarity index 80% rename from src/doc/unstable-book/src/library-features/hint-core-should-pause.md rename to src/doc/unstable-book/src/library-features/spin-loop-hint.md index 05e057be4932d..cd33f0c5e0293 100644 --- a/src/doc/unstable-book/src/library-features/hint-core-should-pause.md +++ b/src/doc/unstable-book/src/library-features/spin-loop-hint.md @@ -1,4 +1,4 @@ -# `hint_core_should_pause` +# `spin_loop_hint` The tracking issue for this feature is: [#41196] @@ -23,7 +23,7 @@ fn spin_loop(value: &AtomicBool) { These programs can be improved in performance like so: ```rust,no_run -#![feature(hint_core_should_pause)] +#![feature(spin_loop_hint)] use std::sync::atomic; use std::sync::atomic::{AtomicBool,Ordering}; @@ -32,10 +32,10 @@ fn spin_loop(value: &AtomicBool) { if value.load(Ordering::Acquire) { break; } - atomic::hint_core_should_pause(); + atomic::spin_loop_hint(); } } ``` -Further improvements could combine `hint_core_should_pause` with +Further improvements could combine `spin_loop_hint` with exponential backoff or `std::thread::yield_now`. diff --git a/src/libcore/sync/atomic.rs b/src/libcore/sync/atomic.rs index b7cf6d778a2f9..5486cb2926650 100644 --- a/src/libcore/sync/atomic.rs +++ b/src/libcore/sync/atomic.rs @@ -103,9 +103,8 @@ use fmt; /// /// On some platforms this function may not do anything at all. #[inline] -#[unstable(feature = "hint_core_should_pause", issue = "41196")] -pub fn hint_core_should_pause() -{ +#[stable(feature = "spin_loop_hint", since = "1.23.0")] +pub fn spin_loop_hint() { #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] unsafe { asm!("pause" ::: "memory" : "volatile"); From a115fcd1a0c272e1a176e3e341b323b134f23097 Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Wed, 22 Nov 2017 11:24:57 +0100 Subject: [PATCH 2/3] Remove spin-loop-hint from the unstable book --- .../src/library-features/spin-loop-hint.md | 41 ------------------- 1 file changed, 41 deletions(-) delete mode 100644 src/doc/unstable-book/src/library-features/spin-loop-hint.md diff --git a/src/doc/unstable-book/src/library-features/spin-loop-hint.md b/src/doc/unstable-book/src/library-features/spin-loop-hint.md deleted file mode 100644 index cd33f0c5e0293..0000000000000 --- a/src/doc/unstable-book/src/library-features/spin-loop-hint.md +++ /dev/null @@ -1,41 +0,0 @@ -# `spin_loop_hint` - -The tracking issue for this feature is: [#41196] - -[#41196]: https://github.com/rust-lang/rust/issues/41196 - ------------------------- - -Many programs have spin loops like the following: - -```rust,no_run -use std::sync::atomic::{AtomicBool,Ordering}; - -fn spin_loop(value: &AtomicBool) { - loop { - if value.load(Ordering::Acquire) { - break; - } - } -} -``` - -These programs can be improved in performance like so: - -```rust,no_run -#![feature(spin_loop_hint)] -use std::sync::atomic; -use std::sync::atomic::{AtomicBool,Ordering}; - -fn spin_loop(value: &AtomicBool) { - loop { - if value.load(Ordering::Acquire) { - break; - } - atomic::spin_loop_hint(); - } -} -``` - -Further improvements could combine `spin_loop_hint` with -exponential backoff or `std::thread::yield_now`. From d5e8b61054018799c09d0e4c7166a6c4f198cbc5 Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Mon, 27 Nov 2017 19:24:13 +0100 Subject: [PATCH 3/3] Change the stabilization version to 1.24.0 --- src/libcore/sync/atomic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/sync/atomic.rs b/src/libcore/sync/atomic.rs index 5486cb2926650..8a261b8f07737 100644 --- a/src/libcore/sync/atomic.rs +++ b/src/libcore/sync/atomic.rs @@ -103,7 +103,7 @@ use fmt; /// /// On some platforms this function may not do anything at all. #[inline] -#[stable(feature = "spin_loop_hint", since = "1.23.0")] +#[stable(feature = "spin_loop_hint", since = "1.24.0")] pub fn spin_loop_hint() { #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] unsafe {