Skip to main content

Orbital

Struct Orbital 

Source
pub struct Orbital<T: Primitive> { /* private fields */ }
Expand description

One shared value, typed. Cheap to clone; every clone, and every handle any process opens from the same id, is the same 64 bits.

The operations are those of std::sync::atomic and cannot fail. The memory ordering is not a parameter: every write is sequentially consistent, which is what lets Self::wait never miss one.

Implementations§

Source§

impl<T: Primitive> Orbital<T>

Source

pub fn id(&self) -> OrbitalId

The address to hand to another process.

Source

pub fn load(&self) -> T

Source

pub fn store(&self, value: T)

Source

pub fn swap(&self, value: T) -> T

Replace the value and return what it was.

Source

pub fn compare_exchange(&self, current: T, new: T) -> Result<T, T>

Store new only if the value is still current: Ok(previous) when it was, Err(actual) when it held something else. An f64 is compared by its bits, so 0.0 is not -0.0 and a NaN equals only the same NaN.

Source

pub fn wait(&self, current: T) -> Result<T>

Park until the value is no longer current, then return what it is. Returns at once when it already differs.

Coalescing: any number of writes while parked are one wake, and a value that left current and came back before the caller looked is no change. An f64 is compared by its bits. Blocking; an async runtime runs it where blocking is allowed.

Source

pub fn wait_until( &self, current: T, interrupt: &AtomicBool, ) -> Result<Option<T>>

Self::wait, which a second word can end: Ok(Some(value)) is a change, Ok(None) is the interrupt.

This is not a timeout; nothing here measures time. The canceller sets interrupt and then calls Self::notify, in that order, on any handle to the same value.

Source

pub fn notify(&self)

Wake everyone parked on this value without writing to it. A waiter whose value has not changed and whose interrupt is not set parks again.

Source§

impl Orbital<i64>

Source

pub fn fetch_add(&self, value: i64) -> i64

Add, wrapping on overflow, and return the previous value.

Source

pub fn fetch_sub(&self, value: i64) -> i64

Subtract, wrapping on overflow, and return the previous value.

Source

pub fn fetch_and(&self, value: i64) -> i64

Source

pub fn fetch_or(&self, value: i64) -> i64

Source

pub fn fetch_xor(&self, value: i64) -> i64

Source

pub fn fetch_max(&self, value: i64) -> i64

Keep the larger of the two and return the previous value.

Source

pub fn fetch_min(&self, value: i64) -> i64

Keep the smaller of the two and return the previous value.

Source§

impl Orbital<u64>

Source

pub fn fetch_add(&self, value: u64) -> u64

Add, wrapping on overflow, and return the previous value.

Source

pub fn fetch_sub(&self, value: u64) -> u64

Subtract, wrapping on overflow, and return the previous value.

Source

pub fn fetch_and(&self, value: u64) -> u64

Source

pub fn fetch_or(&self, value: u64) -> u64

Source

pub fn fetch_xor(&self, value: u64) -> u64

Source

pub fn fetch_max(&self, value: u64) -> u64

Keep the larger of the two and return the previous value.

Source

pub fn fetch_min(&self, value: u64) -> u64

Keep the smaller of the two and return the previous value.

Source§

impl Orbital<f64>

Source

pub fn fetch_add(&self, value: f64) -> f64

Add and return the previous value. A compare-and-swap loop: floats have no fetch-add of their own.

Source§

impl Orbital<bool>

Source

pub fn fetch_and(&self, value: bool) -> bool

Source

pub fn fetch_or(&self, value: bool) -> bool

Source

pub fn fetch_xor(&self, value: bool) -> bool

Trait Implementations§

Source§

impl<T: Primitive> Clone for Orbital<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Primitive> Debug for Orbital<T>

Source§

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

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

impl<T: Primitive> Send for Orbital<T>

Source§

impl<T: Primitive> Sync for Orbital<T>

Auto Trait Implementations§

§

impl<T> Forget for Orbital<T>

§

impl<T> Freeze for Orbital<T>
where PhantomData<T>: Freeze,

§

impl<T> Move for Orbital<T>

§

impl<T> RefUnwindSafe for Orbital<T>

§

impl<T> Unpin for Orbital<T>
where PhantomData<T>: Unpin,

§

impl<T> UnsafeUnpin for Orbital<T>

§

impl<T> UnwindSafe for Orbital<T>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.