Struct sync::atomics::AtomicUint[src]
pub struct AtomicUint {
// some fields omitted
}An unsigned atomic integer type, supporting basic atomic arithmetic operations
Methods
impl AtomicUint
fn new(v: uint) -> AtomicUint
Create a new AtomicUint
fn load(&self, order: Ordering) -> uint
Load the value
fn store(&self, val: uint, order: Ordering)
Store the value
fn swap(&self, val: uint, order: Ordering) -> uint
Store a value, returning the old value
fn compare_and_swap(&self, old: uint, new: uint, order: Ordering) -> uint
If the current value is the same as expected, store a new value
Compare the current value with old; if they are the same then
replace the current value with new. Return the previous value.
If the return value is equal to old then the value was updated.
fn fetch_add(&self, val: uint, order: Ordering) -> uint
Add to the current value, returning the previous
Examples
extern crate sync; fn main() { use std::sync::atomics::{AtomicUint, SeqCst}; let foo = AtomicUint::new(0); assert_eq!(0, foo.fetch_add(10, SeqCst)); assert_eq!(10, foo.load(SeqCst)); }use std::sync::atomics::{AtomicUint, SeqCst}; let foo = AtomicUint::new(0); assert_eq!(0, foo.fetch_add(10, SeqCst)); assert_eq!(10, foo.load(SeqCst));
fn fetch_sub(&self, val: uint, order: Ordering) -> uint
Subtract from the current value, returning the previous
Examples
extern crate sync; fn main() { use std::sync::atomics::{AtomicUint, SeqCst}; let foo = AtomicUint::new(10); assert_eq!(10, foo.fetch_sub(10, SeqCst)); assert_eq!(0, foo.load(SeqCst)); }use std::sync::atomics::{AtomicUint, SeqCst}; let foo = AtomicUint::new(10); assert_eq!(10, foo.fetch_sub(10, SeqCst)); assert_eq!(0, foo.load(SeqCst));
fn fetch_and(&self, val: uint, order: Ordering) -> uint
Bitwise and with the current value, returning the previous
Examples
extern crate sync; fn main() { use std::sync::atomics::{AtomicUint, SeqCst}; let foo = AtomicUint::new(0b101101); assert_eq!(0b101101, foo.fetch_and(0b110011, SeqCst)); assert_eq!(0b100001, foo.load(SeqCst)); }use std::sync::atomics::{AtomicUint, SeqCst}; let foo = AtomicUint::new(0b101101); assert_eq!(0b101101, foo.fetch_and(0b110011, SeqCst)); assert_eq!(0b100001, foo.load(SeqCst));
fn fetch_or(&self, val: uint, order: Ordering) -> uint
Bitwise or with the current value, returning the previous
Examples
extern crate sync; fn main() { use std::sync::atomics::{AtomicUint, SeqCst}; let foo = AtomicUint::new(0b101101); assert_eq!(0b101101, foo.fetch_or(0b110011, SeqCst)); assert_eq!(0b111111, foo.load(SeqCst)); }use std::sync::atomics::{AtomicUint, SeqCst}; let foo = AtomicUint::new(0b101101); assert_eq!(0b101101, foo.fetch_or(0b110011, SeqCst)); assert_eq!(0b111111, foo.load(SeqCst));
fn fetch_xor(&self, val: uint, order: Ordering) -> uint
Bitwise xor with the current value, returning the previous
Examples
extern crate sync; fn main() { use std::sync::atomics::{AtomicUint, SeqCst}; let foo = AtomicUint::new(0b101101); assert_eq!(0b101101, foo.fetch_xor(0b110011, SeqCst)); assert_eq!(0b011110, foo.load(SeqCst)); }use std::sync::atomics::{AtomicUint, SeqCst}; let foo = AtomicUint::new(0b101101); assert_eq!(0b101101, foo.fetch_xor(0b110011, SeqCst)); assert_eq!(0b011110, foo.load(SeqCst));