@@ -76,7 +76,6 @@ use marker::Sync;
76
76
77
77
use intrinsics;
78
78
use cell:: UnsafeCell ;
79
- use marker:: PhantomData ;
80
79
81
80
use default:: Default ;
82
81
@@ -87,8 +86,8 @@ pub struct AtomicBool {
87
86
}
88
87
89
88
impl Default for AtomicBool {
90
- fn default ( ) -> AtomicBool {
91
- ATOMIC_BOOL_INIT
89
+ fn default ( ) -> Self {
90
+ Self :: new ( Default :: default ( ) )
92
91
}
93
92
}
94
93
@@ -101,8 +100,8 @@ pub struct AtomicIsize {
101
100
}
102
101
103
102
impl Default for AtomicIsize {
104
- fn default ( ) -> AtomicIsize {
105
- ATOMIC_ISIZE_INIT
103
+ fn default ( ) -> Self {
104
+ Self :: new ( Default :: default ( ) )
106
105
}
107
106
}
108
107
@@ -115,8 +114,8 @@ pub struct AtomicUsize {
115
114
}
116
115
117
116
impl Default for AtomicUsize {
118
- fn default ( ) -> AtomicUsize {
119
- ATOMIC_USIZE_INIT
117
+ fn default ( ) -> Self {
118
+ Self :: new ( Default :: default ( ) )
120
119
}
121
120
}
122
121
@@ -125,8 +124,7 @@ unsafe impl Sync for AtomicUsize {}
125
124
/// A raw pointer type which can be safely shared between threads.
126
125
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
127
126
pub struct AtomicPtr < T > {
128
- p : UnsafeCell < usize > ,
129
- _marker : PhantomData < * mut T > ,
127
+ p : UnsafeCell < * mut T > ,
130
128
}
131
129
132
130
impl < T > Default for AtomicPtr < T > {
@@ -175,16 +173,13 @@ pub enum Ordering {
175
173
176
174
/// An `AtomicBool` initialized to `false`.
177
175
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
178
- pub const ATOMIC_BOOL_INIT : AtomicBool =
179
- AtomicBool { v : UnsafeCell { value : 0 } } ;
176
+ pub const ATOMIC_BOOL_INIT : AtomicBool = AtomicBool :: new ( false ) ;
180
177
/// An `AtomicIsize` initialized to `0`.
181
178
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
182
- pub const ATOMIC_ISIZE_INIT : AtomicIsize =
183
- AtomicIsize { v : UnsafeCell { value : 0 } } ;
179
+ pub const ATOMIC_ISIZE_INIT : AtomicIsize = AtomicIsize :: new ( 0 ) ;
184
180
/// An `AtomicUsize` initialized to `0`.
185
181
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
186
- pub const ATOMIC_USIZE_INIT : AtomicUsize =
187
- AtomicUsize { v : UnsafeCell { value : 0 , } } ;
182
+ pub const ATOMIC_USIZE_INIT : AtomicUsize = AtomicUsize :: new ( 0 ) ;
188
183
189
184
// NB: Needs to be -1 (0b11111111...) to make fetch_nand work correctly
190
185
const UINT_TRUE : usize = !0 ;
@@ -202,9 +197,8 @@ impl AtomicBool {
202
197
/// ```
203
198
#[ inline]
204
199
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
205
- pub fn new ( v : bool ) -> AtomicBool {
206
- let val = if v { UINT_TRUE } else { 0 } ;
207
- AtomicBool { v : UnsafeCell :: new ( val) }
200
+ pub const fn new ( v : bool ) -> AtomicBool {
201
+ AtomicBool { v : UnsafeCell :: new ( -( v as isize ) as usize ) }
208
202
}
209
203
210
204
/// Loads a value from the bool.
@@ -445,7 +439,7 @@ impl AtomicIsize {
445
439
/// ```
446
440
#[ inline]
447
441
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
448
- pub fn new ( v : isize ) -> AtomicIsize {
442
+ pub const fn new ( v : isize ) -> AtomicIsize {
449
443
AtomicIsize { v : UnsafeCell :: new ( v) }
450
444
}
451
445
@@ -633,7 +627,7 @@ impl AtomicUsize {
633
627
/// ```
634
628
#[ inline]
635
629
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
636
- pub fn new ( v : usize ) -> AtomicUsize {
630
+ pub const fn new ( v : usize ) -> AtomicUsize {
637
631
AtomicUsize { v : UnsafeCell :: new ( v) }
638
632
}
639
633
@@ -821,9 +815,8 @@ impl<T> AtomicPtr<T> {
821
815
/// ```
822
816
#[ inline]
823
817
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
824
- pub fn new ( p : * mut T ) -> AtomicPtr < T > {
825
- AtomicPtr { p : UnsafeCell :: new ( p as usize ) ,
826
- _marker : PhantomData }
818
+ pub const fn new ( p : * mut T ) -> AtomicPtr < T > {
819
+ AtomicPtr { p : UnsafeCell :: new ( p) }
827
820
}
828
821
829
822
/// Loads a value from the pointer.
@@ -848,7 +841,7 @@ impl<T> AtomicPtr<T> {
848
841
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
849
842
pub fn load ( & self , order : Ordering ) -> * mut T {
850
843
unsafe {
851
- atomic_load ( self . p . get ( ) , order) as * mut T
844
+ atomic_load ( self . p . get ( ) as * mut usize , order) as * mut T
852
845
}
853
846
}
854
847
@@ -875,7 +868,7 @@ impl<T> AtomicPtr<T> {
875
868
#[ inline]
876
869
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
877
870
pub fn store ( & self , ptr : * mut T , order : Ordering ) {
878
- unsafe { atomic_store ( self . p . get ( ) , ptr as usize , order) ; }
871
+ unsafe { atomic_store ( self . p . get ( ) as * mut usize , ptr as usize , order) ; }
879
872
}
880
873
881
874
/// Stores a value into the pointer, returning the old value.
@@ -897,7 +890,7 @@ impl<T> AtomicPtr<T> {
897
890
#[ inline]
898
891
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
899
892
pub fn swap ( & self , ptr : * mut T , order : Ordering ) -> * mut T {
900
- unsafe { atomic_swap ( self . p . get ( ) , ptr as usize , order) as * mut T }
893
+ unsafe { atomic_swap ( self . p . get ( ) as * mut usize , ptr as usize , order) as * mut T }
901
894
}
902
895
903
896
/// Stores a value into the pointer if the current value is the same as the expected value.
@@ -925,7 +918,7 @@ impl<T> AtomicPtr<T> {
925
918
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
926
919
pub fn compare_and_swap ( & self , old : * mut T , new : * mut T , order : Ordering ) -> * mut T {
927
920
unsafe {
928
- atomic_compare_and_swap ( self . p . get ( ) , old as usize ,
921
+ atomic_compare_and_swap ( self . p . get ( ) as * mut usize , old as usize ,
929
922
new as usize , order) as * mut T
930
923
}
931
924
}
0 commit comments