Struct core::atomic::AtomicIntStable [-]  [+] [src]

pub struct AtomicInt {
    // some fields omitted
}

A signed integer type which can be safely shared between threads.

Methods

impl AtomicInt

fn new(v: int) -> AtomicInt

Creates a new AtomicInt.

Examples

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

let atomic_forty_two  = AtomicInt::new(42);

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

Loads a value from the int.

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::{AtomicInt, Ordering}; let some_int = AtomicInt::new(5); let value = some_int.load(Ordering::Relaxed); }
use std::sync::atomic::{AtomicInt, Ordering};

let some_int = AtomicInt::new(5);

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

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

Stores a value into the int.

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

Examples

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

let some_int = AtomicInt::new(5);

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

Panics

Panics if order is Acquire or AcqRel.

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

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

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

Examples

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

let some_int = AtomicInt::new(5);

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

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

Stores a value into the int 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::{AtomicInt, Ordering}; let some_int = AtomicInt::new(5); let value = some_int.compare_and_swap(5, 10, Ordering::Relaxed); }
use std::sync::atomic::{AtomicInt, Ordering};

let some_int = AtomicInt::new(5);

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

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

Add an int to the current value, returning the previous value.

Examples

fn main() { use std::sync::atomic::{AtomicInt, SeqCst}; let foo = AtomicInt::new(0); assert_eq!(0, foo.fetch_add(10, SeqCst)); assert_eq!(10, foo.load(SeqCst)); }
use std::sync::atomic::{AtomicInt, SeqCst};

let foo = AtomicInt::new(0);
assert_eq!(0, foo.fetch_add(10, SeqCst));
assert_eq!(10, foo.load(SeqCst));

fn fetch_sub(&self, val: int, order: Ordering) -> int

Subtract an int from the current value, returning the previous value.

Examples

fn main() { use std::sync::atomic::{AtomicInt, SeqCst}; let foo = AtomicInt::new(0); assert_eq!(0, foo.fetch_sub(10, SeqCst)); assert_eq!(-10, foo.load(SeqCst)); }
use std::sync::atomic::{AtomicInt, SeqCst};

let foo = AtomicInt::new(0);
assert_eq!(0, foo.fetch_sub(10, SeqCst));
assert_eq!(-10, foo.load(SeqCst));

fn fetch_and(&self, val: int, order: Ordering) -> int

Bitwise and with the current int, returning the previous value.

Examples

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

let foo = AtomicInt::new(0b101101);
assert_eq!(0b101101, foo.fetch_and(0b110011, SeqCst));
assert_eq!(0b100001, foo.load(SeqCst));

fn fetch_or(&self, val: int, order: Ordering) -> int

Bitwise or with the current int, returning the previous value.

Examples

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

let foo = AtomicInt::new(0b101101);
assert_eq!(0b101101, foo.fetch_or(0b110011, SeqCst));
assert_eq!(0b111111, foo.load(SeqCst));

fn fetch_xor(&self, val: int, order: Ordering) -> int

Bitwise xor with the current int, returning the previous value.

Examples

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

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

Trait Implementations

impl Sync for AtomicInt