Skip to content

Commit 13d73e9

Browse files
Remove AtomicFlag
fixes #12943
1 parent 7647849 commit 13d73e9

File tree

2 files changed

+6
-43
lines changed

2 files changed

+6
-43
lines changed

src/libstd/sync/atomics.rs

+6-41
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@ use std::kinds::marker;
2727
use option::{Option,Some,None};
2828
use ops::Drop;
2929

30-
/**
31-
* A simple atomic flag, that can be set and cleared. The most basic atomic type.
32-
*/
33-
pub struct AtomicFlag {
34-
priv v: int,
35-
priv nopod: marker::NoPod
36-
}
37-
3830
/**
3931
* An atomic boolean type.
4032
*/
@@ -92,36 +84,11 @@ pub enum Ordering {
9284
SeqCst
9385
}
9486

95-
pub static INIT_ATOMIC_FLAG : AtomicFlag = AtomicFlag { v: 0, nopod: marker::NoPod };
9687
pub static INIT_ATOMIC_BOOL : AtomicBool = AtomicBool { v: 0, nopod: marker::NoPod };
9788
pub static INIT_ATOMIC_INT : AtomicInt = AtomicInt { v: 0, nopod: marker::NoPod };
9889
pub static INIT_ATOMIC_UINT : AtomicUint = AtomicUint { v: 0, nopod: marker::NoPod };
9990
pub static INIT_ATOMIC_U64 : AtomicU64 = AtomicU64 { v: 0, nopod: marker::NoPod };
10091

101-
impl AtomicFlag {
102-
103-
pub fn new() -> AtomicFlag {
104-
AtomicFlag { v: 0, nopod: marker::NoPod}
105-
}
106-
107-
/**
108-
* Clears the atomic flag
109-
*/
110-
#[inline]
111-
pub fn clear(&mut self, order: Ordering) {
112-
unsafe {atomic_store(&mut self.v, 0, order)}
113-
}
114-
115-
/**
116-
* Sets the flag if it was previously unset, returns the previous value of the
117-
* flag.
118-
*/
119-
#[inline]
120-
pub fn test_and_set(&mut self, order: Ordering) -> bool {
121-
unsafe { atomic_compare_and_swap(&mut self.v, 0, 1, order) > 0 }
122-
}
123-
}
124-
12592
impl AtomicBool {
12693
pub fn new(v: bool) -> AtomicBool {
12794
AtomicBool { v: if v { 1 } else { 0 }, nopod: marker::NoPod }
@@ -539,13 +506,13 @@ mod test {
539506
use super::*;
540507

541508
#[test]
542-
fn flag() {
543-
let mut flg = AtomicFlag::new();
544-
assert!(!flg.test_and_set(SeqCst));
545-
assert!(flg.test_and_set(SeqCst));
509+
fn bool_() {
510+
let mut a = AtomicBool::new(false);
511+
assert_eq!(a.compare_and_swap(false, true, SeqCst), false);
512+
assert_eq!(a.compare_and_swap(false, true, SeqCst), true);
546513

547-
flg.clear(SeqCst);
548-
assert!(!flg.test_and_set(SeqCst));
514+
a.store(false, SeqCst);
515+
assert_eq!(a.compare_and_swap(false, true, SeqCst), false);
549516
}
550517

551518
#[test]
@@ -595,15 +562,13 @@ mod test {
595562
assert_eq!(a.load(SeqCst),false);
596563
}
597564

598-
static mut S_FLAG : AtomicFlag = INIT_ATOMIC_FLAG;
599565
static mut S_BOOL : AtomicBool = INIT_ATOMIC_BOOL;
600566
static mut S_INT : AtomicInt = INIT_ATOMIC_INT;
601567
static mut S_UINT : AtomicUint = INIT_ATOMIC_UINT;
602568

603569
#[test]
604570
fn static_init() {
605571
unsafe {
606-
assert!(!S_FLAG.test_and_set(SeqCst));
607572
assert!(!S_BOOL.load(SeqCst));
608573
assert!(S_INT.load(SeqCst) == 0);
609574
assert!(S_UINT.load(SeqCst) == 0);

src/test/compile-fail/std-uncopyable-atomics.rs

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ use std::sync::atomics::*;
1616
use std::ptr;
1717

1818
fn main() {
19-
let x = INIT_ATOMIC_FLAG; //~ ERROR cannot move out of static item
20-
let x = *&x; //~ ERROR: cannot move out of dereference
2119
let x = INIT_ATOMIC_BOOL; //~ ERROR cannot move out of static item
2220
let x = *&x; //~ ERROR: cannot move out of dereference
2321
let x = INIT_ATOMIC_INT; //~ ERROR cannot move out of static item

0 commit comments

Comments
 (0)