]> git.lizzy.rs Git - rust.git/commitdiff
Replace yield_now() with spin loop hint
authorAndy Wang <cbeuw.andy@gmail.com>
Tue, 17 May 2022 19:04:18 +0000 (20:04 +0100)
committerAndy Wang <cbeuw.andy@gmail.com>
Mon, 6 Jun 2022 18:15:55 +0000 (19:15 +0100)
tests/compile-fail/weak_memory/cpp20_rwc_syncs.rs
tests/run-pass/weak_memory/consistency.rs

index b9e395fd7741f9f7321415cceeaf94a153747664..423d0e0e8ffb153f57895680b86ab191fa05d2fc 100644 (file)
@@ -9,13 +9,13 @@
 // so we have to stick to C++11 emulation from exiting research.
 
 use std::sync::atomic::Ordering::*;
-use std::thread::{spawn, yield_now};
+use std::thread::spawn;
 use std::sync::atomic::{fence, AtomicUsize};
 
-// Spins and yields until until it reads value
+// Spins until it reads value
 fn reads_value(loc: &AtomicUsize, val: usize) -> usize {
     while loc.load(Relaxed) != val {
-        yield_now();
+        std::hint::spin_loop();
     }
     val
 }
index 67f0e8d35dd31a2f25e5f770e909951e59f4f01f..fa13803830f5924b23fa192eea34e9c7f75b05fe 100644 (file)
@@ -22,7 +22,7 @@
 
 use std::sync::atomic::AtomicUsize;
 use std::sync::atomic::Ordering::*;
-use std::thread::{spawn, yield_now};
+use std::thread::spawn;
 
 #[derive(Copy, Clone)]
 struct EvilSend<T>(pub T);
@@ -37,10 +37,10 @@ fn static_atomic(val: usize) -> &'static AtomicUsize {
     ret
 }
 
-// Spins and yields until until acquires a pre-determined value
+// Spins until acquires a pre-determined value
 fn acquires_value(loc: &AtomicUsize, val: usize) -> usize {
     while loc.load(Acquire) != val {
-        yield_now();
+        std::hint::spin_loop();
     }
     val
 }