diff options
| author | bors <bors@rust-lang.org> | 2017-05-02 17:48:28 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-05-02 17:48:28 +0000 |
| commit | 6a5fc9eecec235312755e737fb5b984abe537f2e (patch) | |
| tree | 657314e4a33fe0b2c5911d9f5b6435068005ee7d /src/libcore/sync | |
| parent | ed1f26ddda15b2bcf613a257e813e8b02ee14dff (diff) | |
| parent | f4fe3cd0e997fc417a245fd33d0d27fb0b44ba10 (diff) | |
Auto merge of #41207 - sstewartgallus:spinpause, r=alexcrichton
Spin loop pause function redux GitHub's interface is screwy. This is the same PR as https://github.com/rust-lang/rust/pull/40537
Diffstat (limited to 'src/libcore/sync')
| -rw-r--r-- | src/libcore/sync/atomic.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/libcore/sync/atomic.rs b/src/libcore/sync/atomic.rs index fad58deecd4..3c51dbc2550 100644 --- a/src/libcore/sync/atomic.rs +++ b/src/libcore/sync/atomic.rs @@ -94,6 +94,29 @@ use intrinsics; use cell::UnsafeCell; use fmt; +/// Save power or switch hyperthreads in a busy-wait spin-loop. +/// +/// This function is deliberately more primitive than +/// `std::thread::yield_now` 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 = "hint_core_should_pause", issue = "41196")] +pub fn hint_core_should_pause() +{ + #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] + unsafe { + asm!("pause" ::: "memory" : "volatile"); + } + + #[cfg(target_arch = "aarch64")] + unsafe { + asm!("yield" ::: "memory" : "volatile"); + } +} + /// A boolean type which can be safely shared between threads. /// /// This type has the same in-memory representation as a `bool`. |
