@@ -75,6 +75,10 @@ pub enum Ordering {
75
75
SeqCst
76
76
}
77
77
78
+ pub static INIT_ATOMIC_FLAG : AtomicFlag = AtomicFlag { v : 0 } ;
79
+ pub static INIT_ATOMIC_BOOL : AtomicBool = AtomicBool { v : 0 } ;
80
+ pub static INIT_ATOMIC_INT : AtomicInt = AtomicInt { v : 0 } ;
81
+ pub static INIT_ATOMIC_UINT : AtomicUint = AtomicUint { v : 0 } ;
78
82
79
83
impl AtomicFlag {
80
84
@@ -589,11 +593,13 @@ pub unsafe fn atomic_umin<T>(dst: &mut T, val: T, order: Ordering) -> T {
589
593
*/
590
594
#[ inline] #[ cfg( not( stage0) ) ]
591
595
pub fn fence ( order : Ordering ) {
592
- match order {
593
- Acquire => intrinsics:: atomic_fence_acq ( ) ,
594
- Release => intrinsics:: atomic_fence_rel ( ) ,
595
- AcqRel => intrinsics:: atomic_fence_rel ( ) ,
596
- _ => intrinsics:: atomic_fence ( ) ,
596
+ unsafe {
597
+ match order {
598
+ Acquire => intrinsics:: atomic_fence_acq ( ) ,
599
+ Release => intrinsics:: atomic_fence_rel ( ) ,
600
+ AcqRel => intrinsics:: atomic_fence_rel ( ) ,
601
+ _ => intrinsics:: atomic_fence ( ) ,
602
+ }
597
603
}
598
604
}
599
605
@@ -657,4 +663,19 @@ mod test {
657
663
assert_eq ! ( a. fetch_and( false , SeqCst ) , true ) ;
658
664
assert_eq ! ( a. load( SeqCst ) , false ) ;
659
665
}
666
+
667
+ static mut S_FLAG : AtomicFlag = INIT_ATOMIC_FLAG ;
668
+ static mut S_BOOL : AtomicBool = INIT_ATOMIC_BOOL ;
669
+ static mut S_INT : AtomicInt = INIT_ATOMIC_INT ;
670
+ static mut S_UINT : AtomicUint = INIT_ATOMIC_UINT ;
671
+
672
+ #[ test]
673
+ fn static_init ( ) {
674
+ unsafe {
675
+ assert ! ( !S_FLAG . test_and_set( SeqCst ) ) ;
676
+ assert ! ( !S_BOOL . load( SeqCst ) ) ;
677
+ assert ! ( S_INT . load( SeqCst ) == 0 ) ;
678
+ assert ! ( S_UINT . load( SeqCst ) == 0 ) ;
679
+ }
680
+ }
660
681
}
0 commit comments