@@ -27,14 +27,6 @@ use std::kinds::marker;
2727use option:: { Option , Some , None } ;
2828use 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 } ;
9687pub static INIT_ATOMIC_BOOL : AtomicBool = AtomicBool { v : 0 , nopod : marker:: NoPod } ;
9788pub static INIT_ATOMIC_INT : AtomicInt = AtomicInt { v : 0 , nopod : marker:: NoPod } ;
9889pub static INIT_ATOMIC_UINT : AtomicUint = AtomicUint { v : 0 , nopod : marker:: NoPod } ;
9990pub 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-
12592impl 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 ) ;
0 commit comments