Struct core::atomics::AtomicInt[src]
pub struct AtomicInt {
// some fields omitted
}A signed atomic integer type, supporting basic atomic arithmetic operations
Methods
impl AtomicInt
fn new(v: int) -> AtomicInt
Create a new AtomicInt
fn load(&self, order: Ordering) -> int
Load the value
fn store(&self, val: int, order: Ordering)
Store the value
fn swap(&self, val: int, order: Ordering) -> int
Store a value, returning the old value
fn compare_and_swap(&self, old: int, new: int, order: Ordering) -> int
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: int, order: Ordering) -> int
Add to the current value, returning the previous
Examples
fn main() { use std::sync::atomics::{AtomicInt, SeqCst}; let foo = AtomicInt::new(0); assert_eq!(0, foo.fetch_add(10, SeqCst)); assert_eq!(10, foo.load(SeqCst)); }use std::sync::atomics::{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 from the current value, returning the previous
Examples
fn main() { use std::sync::atomics::{AtomicInt, SeqCst}; let foo = AtomicInt::new(0); assert_eq!(0, foo.fetch_sub(10, SeqCst)); assert_eq!(-10, foo.load(SeqCst)); }use std::sync::atomics::{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 value, returning the previous
Examples
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: int, order: Ordering) -> int
Bitwise or with the current value, returning the previous
Examples
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: int, order: Ordering) -> int
Bitwise xor with the current value, returning the previous
Examples
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));