left_right

Struct WriteHandle

Source
pub struct WriteHandle<T, O>
where T: Absorb<O>,
{ /* private fields */ }
Expand description

A writer handle to a left-right guarded data structure.

All operations on the underlying data should be enqueued as operations of type O using append. The effect of this operations are only exposed to readers once publish is called.

§Reading through a WriteHandle

WriteHandle allows access to a ReadHandle through Deref<Target = ReadHandle>. Note that since the reads go through a ReadHandle, those reads are subject to the same visibility restrictions as reads that do not go through the WriteHandle: they only see the effects of operations prior to the last call to publish.

Implementations§

Source§

impl<T, O> WriteHandle<T, O>
where T: Absorb<O>,

Source

pub fn publish(&mut self) -> &mut Self

Publish all operations append to the log to reads.

This method needs to wait for all readers to move to the “other” copy of the data so that it can replay the operational log onto the stale copy the readers used to use. This can take some time, especially if readers are executing slow operations, or if there are many of them.

Source

pub fn flush(&mut self)

Publish as necessary to ensure that all operations are visible to readers.

WriteHandle::publish will always wait for old readers to depart and swap the maps. This method will only do so if there are pending operations.

Source

pub fn has_pending_operations(&self) -> bool

Returns true if there are operations in the operational log that have not yet been exposed to readers.

Source

pub fn append(&mut self, op: O) -> &mut Self

Append the given operation to the operational log.

Its effects will not be exposed to readers until you call publish.

Source

pub fn raw_write_handle(&mut self) -> NonNull<T>

Returns a raw pointer to the write copy of the data (the one readers are not accessing).

Note that it is only safe to mutate through this pointer if you know that there are no readers still present in this copy. This is not normally something you know; even after calling publish, readers may still be in the write copy for some time. In general, the only time you know this is okay is before the first call to publish (since no readers ever entered the write copy).

Source

pub fn take(self) -> Taken<T, O>

Returns the backing data structure.

Makes sure that all the pending operations are applied and waits till all the read handles have departed. Then it uses Absorb::drop_first to drop one of the copies of the data and returns the other copy as a Taken smart pointer.

Methods from Deref<Target = ReadHandle<T>>§

Source

pub fn factory(&self) -> ReadHandleFactory<T>

Create a ReadHandleFactory which is Send & Sync and can be shared across threads to create additional ReadHandle instances.

Source

pub fn enter(&self) -> Option<ReadGuard<'_, T>>

Take out a guarded live reference to the read copy of the T.

While the guard lives, the WriteHandle cannot proceed with a call to WriteHandle::publish, so no queued operations will become visible to any reader.

If the WriteHandle has been dropped, this function returns None.

Source

pub fn was_dropped(&self) -> bool

Returns true if the WriteHandle has been dropped.

Source

pub fn raw_handle(&self) -> Option<NonNull<T>>

Returns a raw pointer to the read copy of the data.

Note that it is only safe to read through this pointer if you know that the writer will not start writing into it. This is most likely only the case if you are calling this method from inside a method that holds &mut WriteHandle.

Casting this pointer to &mut is never safe.

Trait Implementations§

Source§

impl<T, O> Debug for WriteHandle<T, O>
where T: Absorb<O> + Debug, O: Debug,

Source§

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

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

impl<T, O> Deref for WriteHandle<T, O>
where T: Absorb<O>,

Source§

type Target = ReadHandle<T>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T, O> Drop for WriteHandle<T, O>
where T: Absorb<O>,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T, O> Extend<O> for WriteHandle<T, O>
where T: Absorb<O>,

Source§

fn extend<I>(&mut self, ops: I)
where I: IntoIterator<Item = O>,

Add multiple operations to the operational log.

Their effects will not be exposed to readers until you call publish

Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<T, O> Send for WriteHandle<T, O>
where T: Absorb<O> + Send, O: Send, ReadHandle<T>: Send,

Auto Trait Implementations§

§

impl<T, O> !Freeze for WriteHandle<T, O>

§

impl<T, O> !RefUnwindSafe for WriteHandle<T, O>

§

impl<T, O> !Sync for WriteHandle<T, O>

§

impl<T, O> Unpin for WriteHandle<T, O>
where O: Unpin,

§

impl<T, O> UnwindSafe for WriteHandle<T, O>

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.