Struct octopus::atomic::Pointer[][src]

pub struct Pointer<T>(_);

A pointer to an object stored in an AtomicPtr

Methods

impl<T> Pointer<T>
[src]

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

Examples

use octopus::atomic::Pointer;

let ptr = Pointer::new("foo");

Creates and returns a new null pointer.

Examples

use octopus::atomic::Pointer;

let ptr = Pointer::<&str>::null();

Returns the inner raw pointer.

Examples

use octopus::atomic::Pointer;
use std::ptr;

let ptr = Pointer::<&str>::null();

assert_eq!(ptr.inner(), ptr::null_mut());

Returns true if the pointer is null.

Examples

use octopus::atomic::Pointer;

let ptr = Pointer::<&str>::null();

assert!(ptr.is_null());

Converts the pointer to a reference.

Returns None if the pointer is null, or else a reference to the object wrapped in Some. The returned reference is valid for the lifetime 'a.

Safety

Dereferencing a pointer is unsafe because it could be pointing to invalid memory.

Another concern is possibly of data races due to lack of proper synchronization. For example, consider the following scenario:

  1. A thread creates a new object: a_ptr.store(10, Ordering::Relaxed)
  2. Another thread reads it: *a.load(Relaxed).as_ref().unwrap()

The problem is that relaxed orderings don't synchronize initialization of the object with the read from the second thread. This is a data race. A possible solution would be to use Release and Acquire orderings.

Examples

use octopus::AtomicPtr;
use std::sync::atomic::Ordering;

let a_ptr = AtomicPtr::new("foo");
let ptr = a_ptr.load(Ordering::SeqCst);

unsafe {
    assert_eq!(ptr.as_ref(), Some(&"foo"));
}

Dereferences the pointer

Returns a reference to the pointer that is valid during the lifetime 'a.

Safety

Dereferencing a pointer is unsafe because it could be pointing to invalid memory.

Another concern is possibly of data races due to lack of proper synchronization. For example, consider the following scenario:

  1. A thread creates a new object: a_ptr.store(10, Ordering::Relaxed)
  2. Another thread reads it: *a.load(Relaxed).deref()

The problem is that relaxed orderings don't synchronize initialization of the object with the read from the second thread. This is a data race. A possible solution would be to use Release and Acquire orderings.

Examples

use octopus::AtomicPtr;
use std::sync::atomic::Ordering;

let a_ptr = AtomicPtr::new("foo");
let ptr = a_ptr.load(Ordering::SeqCst);

unsafe {
    assert_eq!(ptr.deref(), &"foo");
}

Drops the pointer's inner value.

Warning: don't use this function unless you are sure that you won't use the pointer or any pointer pointing to the same data, ever.

Examples

use octopus::AtomicPtr;
use std::sync::atomic::Ordering;

let a_ptr = AtomicPtr::new("foo");
let ptr = a_ptr.load(Ordering::SeqCst);

unsafe {
    ptr.drop_inner();
}

Trait Implementations

impl<T: PartialEq> PartialEq for Pointer<T>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<T: Eq> Eq for Pointer<T>
[src]

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

Formats the value using the given formatter. Read more

impl<T> From<*mut T> for Pointer<T>
[src]

Performs the conversion.

impl<T> From<T> for Pointer<T>
[src]

Performs the conversion.

impl<T> From<Option<T>> for Pointer<T>
[src]

Performs the conversion.

impl<T> Clone for Pointer<T>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T> Copy for Pointer<T>
[src]

impl<T> Deref for Pointer<T>
[src]

The resulting type after dereferencing.

Dereferences the value.

Auto Trait Implementations

impl<T> !Send for Pointer<T>

impl<T> !Sync for Pointer<T>