@@ -41,7 +41,15 @@ fn static_atomic_bool(val: bool) -> &'static AtomicBool {
41
41
}
42
42
43
43
/// 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 {
45
53
while loc. load ( ord) != val {
46
54
std:: hint:: spin_loop ( ) ;
47
55
}
@@ -65,7 +73,7 @@ fn test_corr() {
65
73
} ) ; // | |
66
74
#[ rustfmt:: skip] // |synchronizes-with |happens-before
67
75
let j3 = spawn ( move || { // | |
68
- loads_value ( & y, Acquire , 1 ) ; // <--- ---------+ |
76
+ spin_until_i32 ( & y, Acquire , 1 ) ; // <---------+ |
69
77
x. load ( Relaxed ) // <----------------------------------------------+
70
78
// The two reads on x are ordered by hb, so they cannot observe values
71
79
// differently from the modification order. If the first read observed
@@ -90,12 +98,12 @@ fn test_wrc() {
90
98
} ) ; // | |
91
99
#[ rustfmt:: skip] // |synchronizes-with |
92
100
let j2 = spawn ( move || { // | |
93
- loads_value ( & x, Acquire , 1 ) ; // <--- ---------+ |
101
+ spin_until_i32 ( & x, Acquire , 1 ) ; // <---------+ |
94
102
y. store ( 1 , Release ) ; // ---------------------+ |happens-before
95
103
} ) ; // | |
96
104
#[ rustfmt:: skip] // |synchronizes-with |
97
105
let j3 = spawn ( move || { // | |
98
- loads_value ( & y, Acquire , 1 ) ; // <--- ---------+ |
106
+ spin_until_i32 ( & y, Acquire , 1 ) ; // <---------+ |
99
107
x. load ( Relaxed ) // <-----------------------------------------------+
100
108
} ) ;
101
109
@@ -121,7 +129,7 @@ fn test_message_passing() {
121
129
#[ rustfmt:: skip] // |synchronizes-with | happens-before
122
130
let j2 = spawn ( move || { // | |
123
131
let x = x; // avoid field capturing | |
124
- loads_value ( & y, Acquire , 1 ) ; // <--- ---------+ |
132
+ spin_until_i32 ( & y, Acquire , 1 ) ; // <---------+ |
125
133
unsafe { * x. 0 } // <---------------------------------------------+
126
134
} ) ;
127
135
@@ -216,12 +224,12 @@ fn test_sync_through_rmw_and_fences() {
216
224
let go = static_atomic_bool ( false ) ;
217
225
218
226
let t1 = spawn ( move || {
219
- while !go . load ( Relaxed ) { }
227
+ spin_until_bool ( go , Relaxed , true ) ;
220
228
rdmw ( y, x, z)
221
229
} ) ;
222
230
223
231
let t2 = spawn ( move || {
224
- while !go . load ( Relaxed ) { }
232
+ spin_until_bool ( go , Relaxed , true ) ;
225
233
rdmw ( z, x, y)
226
234
} ) ;
227
235
0 commit comments