@@ -220,7 +220,11 @@ impl Once {
220
220
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
221
221
pub fn call_once < F > ( & self , f : F ) where F : FnOnce ( ) {
222
222
// Fast path, just see if we've completed initialization.
223
- if self . state . load ( Ordering :: SeqCst ) == COMPLETE {
223
+ // An `Acquire` load is enough because that makes all the initialization
224
+ // operations visible to us. The cold path uses SeqCst consistently
225
+ // because the performance difference really does not matter there,
226
+ // and SeqCst minimizes the chances of something going wrong.
227
+ if self . state . load ( Ordering :: Acquire ) == COMPLETE {
224
228
return
225
229
}
226
230
@@ -277,7 +281,11 @@ impl Once {
277
281
#[ unstable( feature = "once_poison" , issue = "33577" ) ]
278
282
pub fn call_once_force < F > ( & self , f : F ) where F : FnOnce ( & OnceState ) {
279
283
// same as above, just with a different parameter to `call_inner`.
280
- if self . state . load ( Ordering :: SeqCst ) == COMPLETE {
284
+ // An `Acquire` load is enough because that makes all the initialization
285
+ // operations visible to us. The cold path uses SeqCst consistently
286
+ // because the performance difference really does not matter there,
287
+ // and SeqCst minimizes the chances of something going wrong.
288
+ if self . state . load ( Ordering :: Acquire ) == COMPLETE {
281
289
return
282
290
}
283
291
0 commit comments