diff options
| author | James Miller <james@aatch.net> | 2013-05-21 17:31:24 +1200 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2013-05-21 15:45:40 -0700 |
| commit | 6d8d73cfc4cba2fdb2ee67448df39d89be08ce69 (patch) | |
| tree | b5aef70cde6068fd2c928f5c09df894ef548c1fc /src | |
| parent | 807269041437411df49a9a893c86310283d6eb91 (diff) | |
| download | rust-6d8d73cfc4cba2fdb2ee67448df39d89be08ce69.tar.gz rust-6d8d73cfc4cba2fdb2ee67448df39d89be08ce69.zip | |
Add AtomicUint newtype
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/unstable/sync.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libcore/unstable/sync.rs b/src/libcore/unstable/sync.rs index 734368c70c4..7c228ff5647 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; |
