@@ -41,7 +41,15 @@ fn static_atomic_bool(val: bool) -> &'static AtomicBool {
4141}
4242
4343/// Spins until it acquires a pre-determined value.
44- fn loads_value ( loc : & AtomicI32 , ord : Ordering , val : i32 ) -> i32 {
44+ fn spin_until_i32 ( loc : & AtomicI32 , ord : Ordering , val : i32 ) -> i32 {
45+ while loc. load ( ord) != val {
46+ std:: hint:: spin_loop ( ) ;
47+ }
48+ val
49+ }
50+
51+ /// Spins until it acquires a pre-determined boolean.
52+ fn spin_until_bool ( loc : & AtomicBool , ord : Ordering , val : bool ) -> bool {
4553 while loc. load ( ord) != val {
4654 std:: hint:: spin_loop ( ) ;
4755 }
@@ -65,7 +73,7 @@ fn test_corr() {
6573 } ) ; // | |
6674 #[ rustfmt:: skip] // |synchronizes-with |happens-before
6775 let j3 = spawn ( move || { // | |
68- loads_value ( & y, Acquire , 1 ) ; // <--- ---------+ |
76+ spin_until_i32 ( & y, Acquire , 1 ) ; // <---------+ |
6977 x. load ( Relaxed ) // <----------------------------------------------+
7078 // The two reads on x are ordered by hb, so they cannot observe values
7179 // differently from the modification order. If the first read observed
@@ -90,12 +98,12 @@ fn test_wrc() {
9098 } ) ; // | |
9199 #[ rustfmt:: skip] // |synchronizes-with |
92100 let j2 = spawn ( move || { // | |
93- loads_value ( & x, Acquire , 1 ) ; // <--- ---------+ |
101+ spin_until_i32 ( & x, Acquire , 1 ) ; // <---------+ |
94102 y. store ( 1 , Release ) ; // ---------------------+ |happens-before
95103 } ) ; // | |
96104 #[ rustfmt:: skip] // |synchronizes-with |
97105 let j3 = spawn ( move || { // | |
98- loads_value ( & y, Acquire , 1 ) ; // <--- ---------+ |
106+ spin_until_i32 ( & y, Acquire , 1 ) ; // <---------+ |
99107 x. load ( Relaxed ) // <-----------------------------------------------+
100108 } ) ;
101109
@@ -121,7 +129,7 @@ fn test_message_passing() {
121129 #[ rustfmt:: skip] // |synchronizes-with | happens-before
122130 let j2 = spawn ( move || { // | |
123131 let x = x; // avoid field capturing | |
124- loads_value ( & y, Acquire , 1 ) ; // <--- ---------+ |
132+ spin_until_i32 ( & y, Acquire , 1 ) ; // <---------+ |
125133 unsafe { * x. 0 } // <---------------------------------------------+
126134 } ) ;
127135
@@ -216,12 +224,12 @@ fn test_sync_through_rmw_and_fences() {
216224 let go = static_atomic_bool ( false ) ;
217225
218226 let t1 = spawn ( move || {
219- while !go . load ( Relaxed ) { }
227+ spin_until_bool ( go , Relaxed , true ) ;
220228 rdmw ( y, x, z)
221229 } ) ;
222230
223231 let t2 = spawn ( move || {
224- while !go . load ( Relaxed ) { }
232+ spin_until_bool ( go , Relaxed , true ) ;
225233 rdmw ( z, x, y)
226234 } ) ;
227235
0 commit comments