Skip to content

Commit 6ecdb36

Browse files
committed
---
yaml --- r: 143339 b: refs/heads/try2 c: 5c7e016 h: refs/heads/master i: 143337: 4b94889 143335: 89b93b4 v: v3
1 parent ee6d591 commit 6ecdb36

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 4a1a0fbed5a57958eb7b658bbe3e5257872ae99f
8+
refs/heads/try2: 5c7e016700cd002647508ec4be764606c0086ce8
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libstd/unstable/atomics.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ pub enum Ordering {
7575
SeqCst
7676
}
7777

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 };
7882

7983
impl AtomicFlag {
8084

@@ -589,11 +593,13 @@ pub unsafe fn atomic_umin<T>(dst: &mut T, val: T, order: Ordering) -> T {
589593
*/
590594
#[inline] #[cfg(not(stage0))]
591595
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+
}
597603
}
598604
}
599605

@@ -657,4 +663,19 @@ mod test {
657663
assert_eq!(a.fetch_and(false, SeqCst),true);
658664
assert_eq!(a.load(SeqCst),false);
659665
}
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+
}
660681
}

0 commit comments

Comments
 (0)