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]
fn null() -> Self
[src]
fn new(value: T) -> Self
[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);
fn from_owned(owned: Owned<T>) -> Self
[src]
Returns a new atomic pointer pointing to owned
.
Examples
use coco::epoch::{Atomic, Owned}; let a = Atomic::from_owned(Owned::new(1234));
fn from_ptr(ptr: Ptr<T>) -> Self
[src]
Returns a new atomic pointer pointing to ptr
.
Examples
use coco::epoch::{Atomic, Ptr}; let a = Atomic::from_ptr(Ptr::<i32>::null());
fn load<'scope>(&self, ord: Ordering, _: &'scope Scope) -> Ptr<'scope, T>
[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); });
fn store(&self, new: Ptr<T>, ord: Ordering)
[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);
fn store_owned(&self, new: Owned<T>, ord: Ordering)
[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);
fn swap<'scope>(
&self,
new: Ptr<T>,
ord: Ordering,
_: &'scope Scope
) -> Ptr<'scope, T>
[src]
&self,
new: Ptr<T>,
ord: Ordering,
_: &'scope Scope
) -> Ptr<'scope, T>
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); });
fn compare_and_swap<'scope>(
&self,
current: Ptr<T>,
new: Ptr<T>,
ord: Ordering,
_: &'scope Scope
) -> Result<(), Ptr<'scope, T>>
[src]
&self,
current: Ptr<T>,
new: Ptr<T>,
ord: Ordering,
_: &'scope Scope
) -> Result<(), Ptr<'scope, T>>
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); });
fn compare_and_swap_weak<'scope>(
&self,
current: Ptr<T>,
new: Ptr<T>,
ord: Ordering,
_: &'scope Scope
) -> Result<(), Ptr<'scope, T>>
[src]
&self,
current: Ptr<T>,
new: Ptr<T>,
ord: Ordering,
_: &'scope Scope
) -> Result<(), Ptr<'scope, T>>
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, } } });
fn compare_and_swap_owned<'scope>(
&self,
current: Ptr<T>,
new: Owned<T>,
ord: Ordering,
_: &'scope Scope
) -> Result<Ptr<'scope, T>, (Ptr<'scope, T>, Owned<T>)>
[src]
&self,
current: Ptr<T>,
new: Owned<T>,
ord: Ordering,
_: &'scope Scope
) -> Result<Ptr<'scope, T>, (Ptr<'scope, T>, Owned<T>)>
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); });
fn compare_and_swap_weak_owned<'scope>(
&self,
current: Ptr<T>,
new: Owned<T>,
ord: Ordering,
_: &'scope Scope
) -> Result<Ptr<'scope, T>, (Ptr<'scope, T>, Owned<T>)>
[src]
&self,
current: Ptr<T>,
new: Owned<T>,
ord: Ordering,
_: &'scope Scope
) -> Result<Ptr<'scope, T>, (Ptr<'scope, T>, Owned<T>)>
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; } } } });
fn fetch_and<'scope>(
&self,
val: usize,
ord: Ordering,
_: &'scope Scope
) -> Ptr<'scope, T>
[src]
&self,
val: usize,
ord: Ordering,
_: &'scope Scope
) -> Ptr<'scope, T>
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); });
fn fetch_or<'scope>(
&self,
val: usize,
ord: Ordering,
_: &'scope Scope
) -> Ptr<'scope, T>
[src]
&self,
val: usize,
ord: Ordering,
_: &'scope Scope
) -> Ptr<'scope, T>
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); });
fn fetch_xor<'scope>(
&self,
val: usize,
ord: Ordering,
_: &'scope Scope
) -> Ptr<'scope, T>
[src]
&self,
val: usize,
ord: Ordering,
_: &'scope Scope
) -> Ptr<'scope, T>
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); });