Skip to content

Commit 6d8d73c

Browse files
Aatchbrson
authored andcommitted
Add AtomicUint newtype
1 parent 8072690 commit 6d8d73c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/libcore/unstable/sync.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,26 @@ extern {
205205
fn rust_unlock_little_lock(lock: rust_little_lock);
206206
}
207207

208+
/* *********************************************************************/
209+
210+
//FIXME: #5042 This should be replaced by proper atomic type
211+
pub struct AtomicUint(uint);
212+
pub impl AtomicUint {
213+
fn load(&self) -> uint {
214+
unsafe { intrinsics::atomic_load(cast::transmute(self)) as uint }
215+
}
216+
fn store(&mut self, val:uint) {
217+
unsafe { intrinsics::atomic_store(cast::transmute(self), val as int); }
218+
}
219+
fn add(&mut self, val:int) -> uint {
220+
unsafe { intrinsics::atomic_xadd(cast::transmute(self), val as int) as uint }
221+
}
222+
fn cas(&self, old:uint, new:uint) -> uint {
223+
unsafe { intrinsics::atomic_cxchg(cast::transmute(self), old as int, new as int) as uint }
224+
}
225+
}
226+
227+
208228
#[cfg(test)]
209229
mod tests {
210230
use comm;

0 commit comments

Comments
 (0)