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>
impl<T: Primitive> Orbital<T>
pub fn load(&self) -> T
pub fn store(&self, value: T)
Sourcepub fn compare_exchange(&self, current: T, new: T) -> Result<T, T>
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.
Sourcepub fn wait(&self, current: T) -> Result<T>
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.
Sourcepub fn wait_until(
&self,
current: T,
interrupt: &AtomicBool,
) -> Result<Option<T>>
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§impl Orbital<i64>
impl Orbital<i64>
Sourcepub fn fetch_add(&self, value: i64) -> i64
pub fn fetch_add(&self, value: i64) -> i64
Add, wrapping on overflow, and return the previous value.
Sourcepub fn fetch_sub(&self, value: i64) -> i64
pub fn fetch_sub(&self, value: i64) -> i64
Subtract, wrapping on overflow, and return the previous value.
pub fn fetch_and(&self, value: i64) -> i64
pub fn fetch_or(&self, value: i64) -> i64
pub fn fetch_xor(&self, value: i64) -> i64
Source§impl Orbital<u64>
impl Orbital<u64>
Sourcepub fn fetch_add(&self, value: u64) -> u64
pub fn fetch_add(&self, value: u64) -> u64
Add, wrapping on overflow, and return the previous value.
Sourcepub fn fetch_sub(&self, value: u64) -> u64
pub fn fetch_sub(&self, value: u64) -> u64
Subtract, wrapping on overflow, and return the previous value.