@@ -76,7 +76,6 @@ use marker::Sync;
7676
7777use intrinsics;
7878use cell:: UnsafeCell ;
79- use marker:: PhantomData ;
8079
8180use default:: Default ;
8281
@@ -87,8 +86,8 @@ pub struct AtomicBool {
8786}
8887
8988impl Default for AtomicBool {
90- fn default ( ) -> AtomicBool {
91- ATOMIC_BOOL_INIT
89+ fn default ( ) -> Self {
90+ Self :: new ( Default :: default ( ) )
9291 }
9392}
9493
@@ -101,8 +100,8 @@ pub struct AtomicIsize {
101100}
102101
103102impl Default for AtomicIsize {
104- fn default ( ) -> AtomicIsize {
105- ATOMIC_ISIZE_INIT
103+ fn default ( ) -> Self {
104+ Self :: new ( Default :: default ( ) )
106105 }
107106}
108107
@@ -115,8 +114,8 @@ pub struct AtomicUsize {
115114}
116115
117116impl Default for AtomicUsize {
118- fn default ( ) -> AtomicUsize {
119- ATOMIC_USIZE_INIT
117+ fn default ( ) -> Self {
118+ Self :: new ( Default :: default ( ) )
120119 }
121120}
122121
@@ -125,8 +124,7 @@ unsafe impl Sync for AtomicUsize {}
125124/// A raw pointer type which can be safely shared between threads.
126125#[ stable( feature = "rust1" , since = "1.0.0" ) ]
127126pub struct AtomicPtr < T > {
128- p : UnsafeCell < usize > ,
129- _marker : PhantomData < * mut T > ,
127+ p : UnsafeCell < * mut T > ,
130128}
131129
132130impl < T > Default for AtomicPtr < T > {
@@ -175,16 +173,13 @@ pub enum Ordering {
175173
176174/// An `AtomicBool` initialized to `false`.
177175#[ 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 ) ;
180177/// An `AtomicIsize` initialized to `0`.
181178#[ 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 ) ;
184180/// An `AtomicUsize` initialized to `0`.
185181#[ 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 ) ;
188183
189184// NB: Needs to be -1 (0b11111111...) to make fetch_nand work correctly
190185const UINT_TRUE : usize = !0 ;
@@ -202,9 +197,8 @@ impl AtomicBool {
202197 /// ```
203198 #[ inline]
204199 #[ 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 ) }
208202 }
209203
210204 /// Loads a value from the bool.
@@ -445,7 +439,7 @@ impl AtomicIsize {
445439 /// ```
446440 #[ inline]
447441 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
448- pub fn new ( v : isize ) -> AtomicIsize {
442+ pub const fn new ( v : isize ) -> AtomicIsize {
449443 AtomicIsize { v : UnsafeCell :: new ( v) }
450444 }
451445
@@ -633,7 +627,7 @@ impl AtomicUsize {
633627 /// ```
634628 #[ inline]
635629 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
636- pub fn new ( v : usize ) -> AtomicUsize {
630+ pub const fn new ( v : usize ) -> AtomicUsize {
637631 AtomicUsize { v : UnsafeCell :: new ( v) }
638632 }
639633
@@ -821,9 +815,8 @@ impl<T> AtomicPtr<T> {
821815 /// ```
822816 #[ inline]
823817 #[ 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) }
827820 }
828821
829822 /// Loads a value from the pointer.
@@ -848,7 +841,7 @@ impl<T> AtomicPtr<T> {
848841 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
849842 pub fn load ( & self , order : Ordering ) -> * mut T {
850843 unsafe {
851- atomic_load ( self . p . get ( ) , order) as * mut T
844+ atomic_load ( self . p . get ( ) as * mut usize , order) as * mut T
852845 }
853846 }
854847
@@ -875,7 +868,7 @@ impl<T> AtomicPtr<T> {
875868 #[ inline]
876869 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
877870 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) ; }
879872 }
880873
881874 /// Stores a value into the pointer, returning the old value.
@@ -897,7 +890,7 @@ impl<T> AtomicPtr<T> {
897890 #[ inline]
898891 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
899892 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 }
901894 }
902895
903896 /// 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> {
925918 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
926919 pub fn compare_and_swap ( & self , old : * mut T , new : * mut T , order : Ordering ) -> * mut T {
927920 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 ,
929922 new as usize , order) as * mut T
930923 }
931924 }
0 commit comments