@@ -87,8 +87,8 @@ pub struct AtomicBool {
8787}
8888
8989impl Default for AtomicBool {
90- fn default ( ) -> AtomicBool {
91- ATOMIC_BOOL_INIT
90+ fn default ( ) -> Self {
91+ Self :: new ( Default :: default ( ) )
9292 }
9393}
9494
@@ -101,8 +101,8 @@ pub struct AtomicIsize {
101101}
102102
103103impl Default for AtomicIsize {
104- fn default ( ) -> AtomicIsize {
105- ATOMIC_ISIZE_INIT
104+ fn default ( ) -> Self {
105+ Self :: new ( Default :: default ( ) )
106106 }
107107}
108108
@@ -115,8 +115,8 @@ pub struct AtomicUsize {
115115}
116116
117117impl Default for AtomicUsize {
118- fn default ( ) -> AtomicUsize {
119- ATOMIC_USIZE_INIT
118+ fn default ( ) -> Self {
119+ Self :: new ( Default :: default ( ) )
120120 }
121121}
122122
@@ -125,8 +125,7 @@ unsafe impl Sync for AtomicUsize {}
125125/// A raw pointer type which can be safely shared between threads.
126126#[ stable( feature = "rust1" , since = "1.0.0" ) ]
127127pub struct AtomicPtr < T > {
128- p : UnsafeCell < usize > ,
129- _marker : PhantomData < * mut T > ,
128+ p : UnsafeCell < * mut T > ,
130129}
131130
132131impl < T > Default for AtomicPtr < T > {
@@ -175,16 +174,13 @@ pub enum Ordering {
175174
176175/// An `AtomicBool` initialized to `false`.
177176#[ stable( feature = "rust1" , since = "1.0.0" ) ]
178- pub const ATOMIC_BOOL_INIT : AtomicBool =
179- AtomicBool { v : UnsafeCell { value : 0 } } ;
177+ pub const ATOMIC_BOOL_INIT : AtomicBool = AtomicBool :: new ( false ) ;
180178/// An `AtomicIsize` initialized to `0`.
181179#[ stable( feature = "rust1" , since = "1.0.0" ) ]
182- pub const ATOMIC_ISIZE_INIT : AtomicIsize =
183- AtomicIsize { v : UnsafeCell { value : 0 } } ;
180+ pub const ATOMIC_ISIZE_INIT : AtomicIsize = AtomicIsize :: new ( 0 ) ;
184181/// An `AtomicUsize` initialized to `0`.
185182#[ stable( feature = "rust1" , since = "1.0.0" ) ]
186- pub const ATOMIC_USIZE_INIT : AtomicUsize =
187- AtomicUsize { v : UnsafeCell { value : 0 , } } ;
183+ pub const ATOMIC_USIZE_INIT : AtomicUsize = AtomicUsize :: new ( 0 ) ;
188184
189185// NB: Needs to be -1 (0b11111111...) to make fetch_nand work correctly
190186const UINT_TRUE : usize = !0 ;
@@ -202,9 +198,8 @@ impl AtomicBool {
202198 /// ```
203199 #[ inline]
204200 #[ 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) }
201+ pub const fn new ( v : bool ) -> AtomicBool {
202+ AtomicBool { v : UnsafeCell :: new ( -( v as isize ) as usize ) }
208203 }
209204
210205 /// Loads a value from the bool.
@@ -445,7 +440,7 @@ impl AtomicIsize {
445440 /// ```
446441 #[ inline]
447442 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
448- pub fn new ( v : isize ) -> AtomicIsize {
443+ pub const fn new ( v : isize ) -> AtomicIsize {
449444 AtomicIsize { v : UnsafeCell :: new ( v) }
450445 }
451446
@@ -633,7 +628,7 @@ impl AtomicUsize {
633628 /// ```
634629 #[ inline]
635630 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
636- pub fn new ( v : usize ) -> AtomicUsize {
631+ pub const fn new ( v : usize ) -> AtomicUsize {
637632 AtomicUsize { v : UnsafeCell :: new ( v) }
638633 }
639634
@@ -821,9 +816,8 @@ impl<T> AtomicPtr<T> {
821816 /// ```
822817 #[ inline]
823818 #[ 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 }
819+ pub const fn new ( p : * mut T ) -> AtomicPtr < T > {
820+ AtomicPtr { p : UnsafeCell :: new ( p) }
827821 }
828822
829823 /// Loads a value from the pointer.
@@ -848,7 +842,7 @@ impl<T> AtomicPtr<T> {
848842 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
849843 pub fn load ( & self , order : Ordering ) -> * mut T {
850844 unsafe {
851- atomic_load ( self . p . get ( ) , order) as * mut T
845+ atomic_load ( self . p . get ( ) as * mut usize , order) as * mut T
852846 }
853847 }
854848
@@ -875,7 +869,7 @@ impl<T> AtomicPtr<T> {
875869 #[ inline]
876870 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
877871 pub fn store ( & self , ptr : * mut T , order : Ordering ) {
878- unsafe { atomic_store ( self . p . get ( ) , ptr as usize , order) ; }
872+ unsafe { atomic_store ( self . p . get ( ) as * mut usize , ptr as usize , order) ; }
879873 }
880874
881875 /// Stores a value into the pointer, returning the old value.
@@ -897,7 +891,7 @@ impl<T> AtomicPtr<T> {
897891 #[ inline]
898892 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
899893 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 }
894+ unsafe { atomic_swap ( self . p . get ( ) as * mut usize , ptr as usize , order) as * mut T }
901895 }
902896
903897 /// Stores a value into the pointer if the current value is the same as the expected value.
@@ -925,7 +919,7 @@ impl<T> AtomicPtr<T> {
925919 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
926920 pub fn compare_and_swap ( & self , old : * mut T , new : * mut T , order : Ordering ) -> * mut T {
927921 unsafe {
928- atomic_compare_and_swap ( self . p . get ( ) , old as usize ,
922+ atomic_compare_and_swap ( self . p . get ( ) as * mut usize , old as usize ,
929923 new as usize , order) as * mut T
930924 }
931925 }
0 commit comments