From 6d8d73cfc4cba2fdb2ee67448df39d89be08ce69 Mon Sep 17 00:00:00 2001 From: James Miller Date: Tue, 21 May 2013 17:31:24 +1200 Subject: [PATCH] Add AtomicUint newtype --- src/libcore/unstable/sync.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/libcore/unstable/sync.rs b/src/libcore/unstable/sync.rs index 734368c70c4a..7c228ff56477 100644 --- a/src/libcore/unstable/sync.rs +++ b/src/libcore/unstable/sync.rs @@ -205,6 +205,26 @@ extern { fn rust_unlock_little_lock(lock: rust_little_lock); } +/* *********************************************************************/ + +//FIXME: #5042 This should be replaced by proper atomic type +pub struct AtomicUint(uint); +pub impl AtomicUint { + fn load(&self) -> uint { + unsafe { intrinsics::atomic_load(cast::transmute(self)) as uint } + } + fn store(&mut self, val:uint) { + unsafe { intrinsics::atomic_store(cast::transmute(self), val as int); } + } + fn add(&mut self, val:int) -> uint { + unsafe { intrinsics::atomic_xadd(cast::transmute(self), val as int) as uint } + } + fn cas(&self, old:uint, new:uint) -> uint { + unsafe { intrinsics::atomic_cxchg(cast::transmute(self), old as int, new as int) as uint } + } +} + + #[cfg(test)] mod tests { use comm;