AtomicPtr

Struct AtomicPtr 

Source
pub struct AtomicPtr<T> { /* private fields */ }
Expand description

A raw pointer type which can be safely shared between threads.

This type has the same in-memory representation as a *mut T.

Implementations§

Source§

impl<T> AtomicPtr<T>

Source

pub const fn new(p: *mut T) -> AtomicPtr<T>

Creates a new AtomicPtr.

§Examples
use msp430_atomic::AtomicPtr;

let ptr = &mut 5;
let atomic_ptr  = AtomicPtr::new(ptr);
Source

pub fn get_mut(&mut self) -> &mut *mut T

Returns a mutable reference to the underlying pointer.

This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.

§Examples
use msp430_atomic::AtomicPtr;

let mut atomic_ptr = AtomicPtr::new(&mut 10);
*atomic_ptr.get_mut() = &mut 5;
assert_eq!(unsafe { *atomic_ptr.load() }, 5);
Source

pub fn into_inner(self) -> *mut T

Consumes the atomic and returns the contained value.

This is safe because passing self by value guarantees that no other threads are concurrently accessing the atomic data.

§Examples
use msp430_atomic::AtomicPtr;

let atomic_ptr = AtomicPtr::new(&mut 5);
assert_eq!(unsafe { *atomic_ptr.into_inner() }, 5);
Source

pub fn load(&self) -> *mut T

Loads a value from the pointer.

§Examples
use msp430_atomic::AtomicPtr;

let ptr = &mut 5;
let some_ptr  = AtomicPtr::new(ptr);

let value = some_ptr.load();
Source

pub fn store(&self, ptr: *mut T)

Stores a value into the pointer.

§Examples
use msp430_atomic::AtomicPtr;

let ptr = &mut 5;
let some_ptr  = AtomicPtr::new(ptr);

let other_ptr = &mut 10;

some_ptr.store(other_ptr);

Trait Implementations§

Source§

impl<T> Debug for AtomicPtr<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for AtomicPtr<T>

Source§

fn default() -> AtomicPtr<T>

Creates a null AtomicPtr<T>.

Source§

impl<T> Send for AtomicPtr<T>

Source§

impl<T> Sync for AtomicPtr<T>

Auto Trait Implementations§

§

impl<T> !Freeze for AtomicPtr<T>

§

impl<T> !RefUnwindSafe for AtomicPtr<T>

§

impl<T> Unpin for AtomicPtr<T>

§

impl<T> UnwindSafe for AtomicPtr<T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.