[−][src]Struct reclaim::Owned
A pointer type for heap allocated values similar to Box
.
Owned
values function like marked pointers and are also guaranteed to
allocate the appropriate RecordHeader
type
for its generic Reclaim
parameter alongside their actual content.
Methods
impl<T, R: Reclaim, N: Unsigned> Owned<T, R, N>
[src]
pub fn new(owned: T) -> Self
[src]
Allocates memory for a Record<T>
on the heap and then
places a record with a default header and owned
into it.
This does only allocate memory if at least one of
RecordHeader
or T
are not zero-sized.
If the RecordHeader
is a ZST, this behaves
identically to Box::new
.
pub fn with_tag(owned: T, tag: usize) -> Self
[src]
Creates a new Owned
like new
but composes the
returned pointer with an initial tag
value.
Example
The primary use case for this is to pre-mark newly allocated values.
use core::sync::atomic::Ordering; use reclaim::typenum::U1; use reclaim::Shared; type Atomic<T> = reclaim::leak::Atomic<T, U1>; type Owned<T> = reclaim::leak::Owned<T, U1>; let atomic = Atomic::null(); let owned = Owned::with_tag("string", 0b1); atomic.store(owned, Ordering::Relaxed); let shared = atomic.load_shared(Ordering::Relaxed); assert_eq!((&"string", 0b1), Shared::decompose_ref(shared.unwrap()));
pub fn none() -> Option<Self>
[src]
Creates a None
variant for an Option<Self>
.
This is useful for calls to store
, swap
or
compare_exchange_*
, when a null
pointer
needs to be inserted.
These methods accept values of various non-nullable pointer types
(Shared
, Owned
, Unlinked
and
Unprotected
) and Option
types thereof as
argument.
However, the compiler is usually not able to infer the concrete
type, when a None
is inserted, and this function is intended for
these cases.
Example
use std::sync::atomic::Ordering; type Atomic<T> = reclaim::leak::Atomic<T, reclaim::typenum::U0>; type Owned<T> = reclaim::leak::Owned<T, reclaim::typenum::U0>; type Unlinked<T> = reclaim::leak::Unlinked<T, reclaim::typenum::U0>; let atomic = Atomic::new(1); let swap = atomic.swap(Owned::none(), Ordering::Relaxed).unwrap(); assert_eq!(swap.as_ref(), &1); unsafe { Unlinked::retire(swap) }; // leaks memory
pub fn null() -> Marked<Self>
[src]
Creates an unmarked Null
variant
for a Marked<Self>
.
pub fn null_with_tag(tag: usize) -> Marked<Self>
[src]
Creates a marked Null
variant for
a Marked<Self>
with the given tag
.
pub fn compose(owned: Self, tag: usize) -> Self
[src]
Consumes the given Self
and returns the same value but with the
specified tag
.
Any previous tag is overwritten.
pub fn decompose_ref(owned: &Self) -> (&T, usize)
[src]
Decomposes the internal marked pointer, returning a reference and the separated tag.
Example
use core::sync::atomic::Ordering::Relaxed; use reclaim::typenum::U1; use reclaim::leak::Owned; type Atomic<T> = reclaim::leak::Atomic<T, U1>; let mut atomic = Atomic::from(Owned::with_tag("string", 0b1)); // ... potential operations by other threads ... let owned = atomic.take(); // after all threads have joined assert_eq!((&"string", 0b1), Owned::decompose_ref(owned.as_ref().unwrap()));
pub fn decompose_mut(owned: &mut Self) -> (&mut T, usize)
[src]
Decomposes the internal marked pointer, returning a mutable reference and the separated tag.
pub fn leak<'a>(owned: Self) -> (&'a mut T, usize) where
T: 'a,
[src]
T: 'a,
Consumes and leaks the Owned
, returning a mutable reference
&'a mut T
and the decomposed tag.
Note that the type T
must outlive the chosen lifetime 'a
.
If the type has only static references, or none at all, then this may
chosen to be 'static
.
pub fn leak_unprotected(owned: Self) -> Unprotected<T, R, N>
[src]
Leaks the owned
value and turns it into an Unprotected
value,
which has copy semantics, but can no longer be safely dereferenced.
Example
use core::sync::atomic::Ordering::Relaxed; use reclaim::typenum::U0; use reclaim::{Owned, Shared}; type Atomic<T> = reclaim::leak::Atomic<T, U0>; let atomic = Atomic::null(); let unprotected = Owned::leak_unprotected(Owned::new("string")); loop { // `unprotected` is simply copied in every loop iteration if atomic.compare_exchange_weak(Shared::none(), unprotected, Relaxed, Relaxed).is_ok() { break; } }
pub unsafe fn leak_shared<'a>(owned: Self) -> Shared<'a, T, R, N>
[src]
Leaks the owned
value and turns it into a "protected" Shared
value with arbitrary lifetime 'a
.
Note, that the protection of the Shared
value in this case
stems from the fact, that the given owned
could not have previously
been part of a concurrent data structure (barring unsafe construction).
This rules out concurrent reclamation by other threads.
Safety
Once a leaked Shared
has been successfully inserted into a
concurrent data structure, it must not be accessed any more, if there is
the possibility for concurrent reclamation of the record.
Example
The use case for this method is similar to leak_unprotected
but the leaked value can be safely dereferenced before being
inserted into a shared data structure.
use core::sync::atomic::Ordering::Relaxed; use reclaim::typenum::U0; use reclaim::{Owned, Shared}; type Atomic<T> = reclaim::leak::Atomic<T, U0>; let atomic = Atomic::null(); let shared = unsafe { Owned::leak_shared(Owned::new("string")) }; assert_eq!(&"string", &*shared); loop { // `shared` is simply copied in every loop iteration if atomic.compare_exchange_weak(Shared::none(), shared, Relaxed, Relaxed).is_ok() { // if (non-leaking) reclamation is going on, `shared` must not be accessed // anymore after successful insertion! break; } }
Trait Implementations
impl<T, R: Reclaim, N: Unsigned> MarkedPointer for Owned<T, R, N>
[src]
type Pointer = Self
The pointer type.
type Item = T
The pointed-to type.
type MarkBits = N
Number of bits available for tagging.
fn as_marked_ptr(&self) -> MarkedPtr<T, N>
[src]
fn into_marked_ptr(self) -> MarkedPtr<Self::Item, Self::MarkBits>
[src]
fn marked(owned: Self, tag: usize) -> Marked<Self::Pointer>
[src]
fn unmarked(owned: Self) -> Self
[src]
fn decompose(owned: Self) -> (Self, usize)
[src]
unsafe fn from_marked_ptr(marked: MarkedPtr<Self::Item, Self::MarkBits>) -> Self
[src]
unsafe fn from_marked_non_null(
marked: MarkedNonNull<Self::Item, Self::MarkBits>
) -> Self
[src]
marked: MarkedNonNull<Self::Item, Self::MarkBits>
) -> Self
impl<T, R: Reclaim, N: Unsigned> NonNullable for Owned<T, R, N>
[src]
type Item = T
The pointed-to type.
type MarkBits = N
Number of bits available for tagging.
fn into_marked_non_null(self) -> MarkedNonNull<T, N>
[src]
impl<T: Ord, R: Ord + Reclaim, N: Ord + Unsigned> Ord for Owned<T, R, N>
[src]
fn cmp(&self, other: &Owned<T, R, N>) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
fn clamp(self, min: Self, max: Self) -> Self
[src]
clamp
)Restrict a value to a certain interval. Read more
impl<T: Clone, R: Reclaim, N: Unsigned> Clone for Owned<T, R, N>
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<T, R: Reclaim, N: Unsigned> Sync for Owned<T, R, N> where
T: Sync,
[src]
T: Sync,
impl<T, R: Reclaim, N: Unsigned> Drop for Owned<T, R, N>
[src]
impl<T: Eq, R: Eq + Reclaim, N: Eq + Unsigned> Eq for Owned<T, R, N>
[src]
impl<T, R: Reclaim, N: Unsigned> From<Owned<T, R, N>> for Atomic<T, R, N>
[src]
impl<T, R: Reclaim, N: Unsigned> From<T> for Owned<T, R, N>
[src]
impl<T, R: Reclaim, N: Unsigned> AsMut<T> for Owned<T, R, N>
[src]
impl<T: Default, R: Reclaim, N: Unsigned> Default for Owned<T, R, N>
[src]
impl<T: PartialEq, R: PartialEq + Reclaim, N: PartialEq + Unsigned> PartialEq<Owned<T, R, N>> for Owned<T, R, N>
[src]
impl<T, R: Reclaim, N: Unsigned> AsRef<T> for Owned<T, R, N>
[src]
impl<T, R: Reclaim, N: Unsigned> Send for Owned<T, R, N> where
T: Send,
[src]
T: Send,
impl<T: PartialOrd, R: PartialOrd + Reclaim, N: PartialOrd + Unsigned> PartialOrd<Owned<T, R, N>> for Owned<T, R, N>
[src]
fn partial_cmp(&self, other: &Owned<T, R, N>) -> Option<Ordering>
[src]
fn lt(&self, other: &Owned<T, R, N>) -> bool
[src]
fn le(&self, other: &Owned<T, R, N>) -> bool
[src]
fn gt(&self, other: &Owned<T, R, N>) -> bool
[src]
fn ge(&self, other: &Owned<T, R, N>) -> bool
[src]
impl<T, R: Reclaim, N: Unsigned> DerefMut for Owned<T, R, N>
[src]
impl<T, R: Reclaim, N: Unsigned> Debug for Owned<T, R, N> where
T: Debug,
[src]
T: Debug,
impl<T, R: Reclaim, N: Unsigned> Deref for Owned<T, R, N>
[src]
impl<T, R: Reclaim, N: Unsigned> Pointer for Owned<T, R, N>
[src]
impl<T, R: Reclaim, N: Unsigned> BorrowMut<T> for Owned<T, R, N>
[src]
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, R: Reclaim, N: Unsigned> Borrow<T> for Owned<T, R, N>
[src]
Auto Trait Implementations
impl<T, R, N> Unpin for Owned<T, R, N> where
N: Unpin,
R: Unpin,
T: Unpin,
N: Unpin,
R: Unpin,
T: Unpin,
impl<T, R, N> RefUnwindSafe for Owned<T, R, N> where
N: RefUnwindSafe,
R: RefUnwindSafe,
T: RefUnwindSafe,
N: RefUnwindSafe,
R: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, R, N> UnwindSafe for Owned<T, R, N> where
N: UnwindSafe,
R: UnwindSafe,
T: RefUnwindSafe + UnwindSafe,
N: UnwindSafe,
R: UnwindSafe,
T: RefUnwindSafe + UnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Same<T> for T
[src]
type Output = T
Should always be Self