@@ -27,14 +27,6 @@ use std::kinds::marker;
27
27
use option:: { Option , Some , None } ;
28
28
use ops:: Drop ;
29
29
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
-
38
30
/**
39
31
* An atomic boolean type.
40
32
*/
@@ -92,36 +84,11 @@ pub enum Ordering {
92
84
SeqCst
93
85
}
94
86
95
- pub static INIT_ATOMIC_FLAG : AtomicFlag = AtomicFlag { v : 0 , nopod : marker:: NoPod } ;
96
87
pub static INIT_ATOMIC_BOOL : AtomicBool = AtomicBool { v : 0 , nopod : marker:: NoPod } ;
97
88
pub static INIT_ATOMIC_INT : AtomicInt = AtomicInt { v : 0 , nopod : marker:: NoPod } ;
98
89
pub static INIT_ATOMIC_UINT : AtomicUint = AtomicUint { v : 0 , nopod : marker:: NoPod } ;
99
90
pub static INIT_ATOMIC_U64 : AtomicU64 = AtomicU64 { v : 0 , nopod : marker:: NoPod } ;
100
91
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
-
125
92
impl AtomicBool {
126
93
pub fn new ( v : bool ) -> AtomicBool {
127
94
AtomicBool { v : if v { 1 } else { 0 } , nopod : marker:: NoPod }
@@ -539,13 +506,13 @@ mod test {
539
506
use super :: * ;
540
507
541
508
#[ 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 ) ;
546
513
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 ) ;
549
516
}
550
517
551
518
#[ test]
@@ -595,15 +562,13 @@ mod test {
595
562
assert_eq ! ( a. load( SeqCst ) , false ) ;
596
563
}
597
564
598
- static mut S_FLAG : AtomicFlag = INIT_ATOMIC_FLAG ;
599
565
static mut S_BOOL : AtomicBool = INIT_ATOMIC_BOOL ;
600
566
static mut S_INT : AtomicInt = INIT_ATOMIC_INT ;
601
567
static mut S_UINT : AtomicUint = INIT_ATOMIC_UINT ;
602
568
603
569
#[ test]
604
570
fn static_init ( ) {
605
571
unsafe {
606
- assert ! ( !S_FLAG . test_and_set( SeqCst ) ) ;
607
572
assert ! ( !S_BOOL . load( SeqCst ) ) ;
608
573
assert ! ( S_INT . load( SeqCst ) == 0 ) ;
609
574
assert ! ( S_UINT . load( SeqCst ) == 0 ) ;
0 commit comments