Struct std::sync::atomic::AtomicUintStable [-]  [+] [src]

pub struct AtomicUint {
    // some fields omitted
}

An unsigned integer type which can be safely shared between threads.

Methods

impl AtomicUint

fn new(v: uint) -> AtomicUint

Creates a new AtomicUint.

Examples

fn main() { use std::sync::atomic::AtomicUint; let atomic_forty_two = AtomicUint::new(42u); }
use std::sync::atomic::AtomicUint;

let atomic_forty_two = AtomicUint::new(42u);

fn load(&self, order: Ordering) -> uint

Loads a value from the uint.

load takes an Ordering argument which describes the memory ordering of this operation.

Panics

Panics if order is Release or AcqRel.

Examples

fn main() { use std::sync::atomic::{AtomicUint, Ordering}; let some_uint = AtomicUint::new(5); let value = some_uint.load(Ordering::Relaxed); }
use std::sync::atomic::{AtomicUint, Ordering};

let some_uint = AtomicUint::new(5);

let value = some_uint.load(Ordering::Relaxed);

fn store(&self, val: uint, order: Ordering)

Stores a value into the uint.

store takes an Ordering argument which describes the memory ordering of this operation.

Examples

fn main() { use std::sync::atomic::{AtomicUint, Ordering}; let some_uint = AtomicUint::new(5); some_uint.store(10, Ordering::Relaxed); }
use std::sync::atomic::{AtomicUint, Ordering};

let some_uint = AtomicUint::new(5);

some_uint.store(10, Ordering::Relaxed);

Panics

Panics if order is Acquire or AcqRel.

fn swap(&self, val: uint, order: Ordering) -> uint

Stores a value into the uint, returning the old value.

swap takes an Ordering argument which describes the memory ordering of this operation.

Examples

fn main() { use std::sync::atomic::{AtomicUint, Ordering}; let some_uint = AtomicUint::new(5); let value = some_uint.swap(10, Ordering::Relaxed); }
use std::sync::atomic::{AtomicUint, Ordering};

let some_uint = AtomicUint::new(5);

let value = some_uint.swap(10, Ordering::Relaxed);

fn compare_and_swap(&self, old: uint, new: uint, order: Ordering) -> uint

Stores a value into the uint if the current value is the same as the expected value.

If the return value is equal to old then the value was updated.

compare_and_swap also takes an Ordering argument which describes the memory ordering of this operation.

Examples

fn main() { use std::sync::atomic::{AtomicUint, Ordering}; let some_uint = AtomicUint::new(5); let value = some_uint.compare_and_swap(5, 10, Ordering::Relaxed); }
use std::sync::atomic::{AtomicUint, Ordering};

let some_uint = AtomicUint::new(5);

let value = some_uint.compare_and_swap(5, 10, Ordering::Relaxed);

fn fetch_add(&self, val: uint, order: Ordering) -> uint

Add to the current uint, returning the previous value.

Examples

fn main() { use std::sync::atomic::{AtomicUint, SeqCst}; let foo = AtomicUint::new(0); assert_eq!(0, foo.fetch_add(10, SeqCst)); assert_eq!(10, foo.load(SeqCst)); }
use std::sync::atomic::{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 uint, returning the previous value.

Examples

fn main() { use std::sync::atomic::{AtomicUint, SeqCst}; let foo = AtomicUint::new(10); assert_eq!(10, foo.fetch_sub(10, SeqCst)); assert_eq!(0, foo.load(SeqCst)); }
use std::sync::atomic::{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 uint, returning the previous value.

Examples

fn main() { use std::sync::atomic::{AtomicUint, SeqCst}; let foo = AtomicUint::new(0b101101); assert_eq!(0b101101, foo.fetch_and(0b110011, SeqCst)); assert_eq!(0b100001, foo.load(SeqCst)); }
use std::sync::atomic::{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 uint, returning the previous value.

Examples

fn main() { use std::sync::atomic::{AtomicUint, SeqCst}; let foo = AtomicUint::new(0b101101); assert_eq!(0b101101, foo.fetch_or(0b110011, SeqCst)); assert_eq!(0b111111, foo.load(SeqCst)); }
use std::sync::atomic::{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 uint, returning the previous value.

Examples

fn main() { use std::sync::atomic::{AtomicUint, SeqCst}; let foo = AtomicUint::new(0b101101); assert_eq!(0b101101, foo.fetch_xor(0b110011, SeqCst)); assert_eq!(0b011110, foo.load(SeqCst)); }
use std::sync::atomic::{AtomicUint, SeqCst};

let foo = AtomicUint::new(0b101101);
assert_eq!(0b101101, foo.fetch_xor(0b110011, SeqCst));
assert_eq!(0b011110, foo.load(SeqCst));

Trait Implementations

impl Sync for AtomicUint