Struct coco::epoch::Atomic [] [src]

pub struct Atomic<T> { /* fields omitted */ }

An atomic pointer that can be safely shared between threads.

The pointer must be properly aligned. Since it is aligned, a tag can be stored into the unused least significant bits of the address.

Any method that loads the pointer must be passed a reference to a Scope.

Methods

impl<T> Atomic<T>
[src]

[src]

Returns a new null atomic pointer.

Examples

use coco::epoch::Atomic;

let a = Atomic::<i32>::null();

[src]

Allocates value on the heap and returns a new atomic pointer pointing to it.

Examples

use coco::epoch::Atomic;

let a = Atomic::new(1234);

[src]

Returns a new atomic pointer pointing to owned.

Examples

use coco::epoch::{Atomic, Owned};

let a = Atomic::from_owned(Owned::new(1234));

[src]

Returns a new atomic pointer pointing to ptr.

Examples

use coco::epoch::{Atomic, Ptr};

let a = Atomic::from_ptr(Ptr::<i32>::null());

[src]

Loads a Ptr from the atomic pointer.

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

Examples

use coco::epoch::{self, Atomic};
use std::sync::atomic::Ordering::SeqCst;

let a = Atomic::new(1234);
epoch::pin(|scope| {
    let p = a.load(SeqCst, scope);
});

[src]

Stores a Ptr into the atomic pointer.

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

Examples

use coco::epoch::{self, Atomic, Ptr};
use std::sync::atomic::Ordering::SeqCst;

let a = Atomic::new(1234);
a.store(Ptr::null(), SeqCst);

[src]

Stores an Owned into the atomic pointer.

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

Examples

use coco::epoch::{self, Atomic, Owned};
use std::sync::atomic::Ordering::SeqCst;

let a = Atomic::null();
a.store_owned(Owned::new(1234), SeqCst);

[src]

Stores a Ptr into the atomic pointer, returning the previous Ptr.

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

Examples

use coco::epoch::{self, Atomic, Owned, Ptr};
use std::sync::atomic::Ordering::SeqCst;

let a = Atomic::new(1234);
epoch::pin(|scope| {
    let p = a.swap(Ptr::null(), SeqCst, scope);
});

[src]

Stores new into the atomic pointer if the current value is the same as current.

The return value is a result indicating whether the new pointer was written. On failure the actual current value is returned.

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

Examples

use coco::epoch::{self, Atomic, Ptr};
use std::sync::atomic::Ordering::SeqCst;

let a = Atomic::new(1234);

epoch::pin(|scope| {
    let mut curr = a.load(SeqCst, scope);
    let res = a.compare_and_swap(curr, Ptr::null(), SeqCst, scope);
});

[src]

Stores new into the atomic pointer if the current value is the same as current.

Unlike compare_and_swap, this method is allowed to spuriously fail even when comparison succeeds, which can result in more efficient code on some platforms. The return value is a result indicating whether the new pointer was written. On failure the actual current value is returned.

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

Examples

use coco::epoch::{self, Atomic, Ptr};
use std::sync::atomic::Ordering::SeqCst;

let a = Atomic::new(1234);

epoch::pin(|scope| {
    let mut curr = a.load(SeqCst, scope);
    loop {
        match a.compare_and_swap_weak(curr, Ptr::null(), SeqCst, scope) {
            Ok(()) => break,
            Err(c) => curr = c,
        }
    }
});

[src]

Stores new into the atomic pointer if the current value is the same as current.

The return value is a result indicating whether the new pointer was written. On success the pointer that was written is returned. On failure new and the actual current value are returned.

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

Examples

use coco::epoch::{self, Atomic, Owned};
use std::sync::atomic::Ordering::SeqCst;

let a = Atomic::new(1234);

epoch::pin(|scope| {
    let mut curr = a.load(SeqCst, scope);
    let res = a.compare_and_swap_owned(curr, Owned::new(5678), SeqCst, scope);
});

[src]

Stores new into the atomic pointer if the current value is the same as current.

Unlike compare_and_swap_owned, this method is allowed to spuriously fail even when comparison succeeds, which can result in more efficient code on some platforms. The return value is a result indicating whether the new pointer was written. On success the pointer that was written is returned. On failure new and the actual current value are returned.

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

Examples

use coco::epoch::{self, Atomic, Owned};
use std::sync::atomic::Ordering::SeqCst;

let a = Atomic::new(1234);

epoch::pin(|scope| {
    let mut new = Owned::new(5678);
    let mut ptr = a.load(SeqCst, scope);
    loop {
        match a.compare_and_swap_weak_owned(ptr, new, SeqCst, scope) {
            Ok(p) => {
                ptr = p;
                break;
            }
            Err((p, n)) => {
                ptr = p;
                new = n;
            }
        }
    }
});

[src]

Bitwise "and" with the current tag.

Performs a bitwise "and" operation on the current tag and the argument val, and sets the new tag to the result. Returns the previous pointer.

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

Examples

use coco::epoch::{self, Atomic, Ptr};
use std::sync::atomic::Ordering::SeqCst;

let a = Atomic::<i32>::from_ptr(Ptr::null().with_tag(3));
epoch::pin(|scope| {
    assert_eq!(a.fetch_and(2, SeqCst, scope).tag(), 3);
    assert_eq!(a.load(SeqCst, scope).tag(), 2);
});

[src]

Bitwise "or" with the current tag.

Performs a bitwise "or" operation on the current tag and the argument val, and sets the new tag to the result. Returns the previous pointer.

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

Examples

use coco::epoch::{self, Atomic, Ptr};
use std::sync::atomic::Ordering::SeqCst;

let a = Atomic::<i32>::from_ptr(Ptr::null().with_tag(1));
epoch::pin(|scope| {
    assert_eq!(a.fetch_or(2, SeqCst, scope).tag(), 1);
    assert_eq!(a.load(SeqCst, scope).tag(), 3);
});

[src]

Bitwise "xor" with the current tag.

Performs a bitwise "xor" operation on the current tag and the argument val, and sets the new tag to the result. Returns the previous pointer.

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

Examples

use coco::epoch::{self, Atomic, Ptr};
use std::sync::atomic::Ordering::SeqCst;

let a = Atomic::<i32>::from_ptr(Ptr::null().with_tag(1));
epoch::pin(|scope| {
    assert_eq!(a.fetch_xor(3, SeqCst, scope).tag(), 1);
    assert_eq!(a.load(SeqCst, scope).tag(), 2);
});

Trait Implementations

impl<T: Debug> Debug for Atomic<T>
[src]

[src]

Formats the value using the given formatter.

impl<T: Send + Sync> Send for Atomic<T>
[src]

impl<T: Send + Sync> Sync for Atomic<T>
[src]

impl<T> Default for Atomic<T>
[src]

[src]

Returns the "default value" for a type. Read more