Skip to content

Commit 008e6e5

Browse files
author
James Miller
committed
Make AtomicPtr use *mut, instead of ~
1 parent 5233604 commit 008e6e5

File tree

1 file changed

+15
-47
lines changed

1 file changed

+15
-47
lines changed

src/libstd/unstable/atomics.rs

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ use cast;
1717
use option::{Option,Some,None};
1818

1919
pub struct AtomicFlag {
20-
priv v:int
20+
priv v: int
2121
}
2222

2323
pub struct AtomicBool {
24-
priv v:uint
24+
priv v: uint
2525
}
2626

2727
pub struct AtomicInt {
28-
priv v:int
28+
priv v: int
2929
}
3030

3131
pub struct AtomicUint {
32-
priv v:uint
32+
priv v: uint
3333
}
3434

3535
pub struct AtomicPtr<T> {
36-
priv p:~T
36+
priv p: *mut T
3737
}
3838

3939
pub enum Ordering {
@@ -173,60 +173,28 @@ impl AtomicUint {
173173
}
174174

175175
impl<T> AtomicPtr<T> {
176-
fn new(p:~T) -> AtomicPtr<T> {
176+
fn new(p:*mut T) -> AtomicPtr<T> {
177177
AtomicPtr { p:p }
178178
}
179179

180-
/**
181-
* Atomically swaps the stored pointer with the one given.
182-
*
183-
* Returns None if the pointer stored has been taken
184-
*/
185180
#[inline(always)]
186-
fn swap(&mut self, ptr:~T, order:Ordering) -> Option<~T> {
187-
unsafe {
188-
let p = atomic_swap(&mut self.p, ptr, order);
189-
let pv : &uint = cast::transmute(&p);
190-
191-
if *pv == 0 {
192-
None
193-
} else {
194-
Some(p)
195-
}
196-
}
181+
fn load(&self, order:Ordering) -> *mut T {
182+
unsafe { atomic_load(&self.p, order) }
197183
}
198184

199-
/**
200-
* Atomically takes the stored pointer out.
201-
*
202-
* Returns None if it was already taken.
203-
*/
204185
#[inline(always)]
205-
fn take(&mut self, order:Ordering) -> Option<~T> {
206-
unsafe { self.swap(cast::transmute(0), order) }
186+
fn store(&mut self, ptr:*mut T, order:Ordering) {
187+
unsafe { atomic_store(&mut self.p, ptr, order); }
207188
}
208189

209-
/**
210-
* Atomically stores the given pointer, this will overwrite
211-
* and previous value stored.
212-
*/
213190
#[inline(always)]
214-
fn give(&mut self, ptr:~T, order:Ordering) {
215-
let _ = self.swap(ptr, order);
191+
fn swap(&mut self, ptr:*mut T, order:Ordering) -> *mut T {
192+
unsafe { atomic_swap(&mut self.p, ptr, order) }
216193
}
217194

218-
/**
219-
* Checks to see if the stored pointer has been taken.
220-
*/
221-
fn taken(&self, order:Ordering) -> bool {
222-
unsafe {
223-
let p : ~T = atomic_load(&self.p, order);
224-
225-
let pv : &uint = cast::transmute(&p);
226-
227-
cast::forget(p);
228-
*pv == 0
229-
}
195+
#[inline(always)]
196+
fn compare_and_swap(&mut self, old: *mut T, new: *mut T, order:Ordering) -> *mut T {
197+
unsafe { atomic_compare_and_swap(&mut self.v, old, new, order) }
230198
}
231199
}
232200

0 commit comments

Comments
 (0)