Skip to main content

SyncRegionToken

Struct SyncRegionToken 

Source
pub struct SyncRegionToken<'brand> { /* private fields */ }
Expand description

A brand owner that is Send + Sync and may be handed across thread boundaries to relocate exclusive write capability.

SyncRegionToken carries the same permit semantics as ExclusiveToken but names the region pattern explicitly: a contiguous branded region (e.g. an allocator’s slab) whose ownership migrates between worker threads. Moving the token to a thread transfers the right to mutate every cell of the region; sharing &token across threads (via crate::MelinoeCell’s Sync impl) grants concurrent read access.

Because the token is move-only for writes yet freely borrowable for reads, the borrow checker enforces single-writer / multi-reader discipline over the whole region without a single atomic instruction or lock.

§Device-buffer ownership transfer

A device-buffer owner can store the backend’s real buffer handle in a MelinoeCell and require SyncRegionToken<'brand> by value on the host/device boundary. Moving the token into that boundary transfers the sole write capability to the code that records the stream or queue operation. Returning the token after submission or synchronization restores host-side exclusive capability; borrowing it immutably, or calling share, switches to shared readback/observer capability.

Implementations§

Source§

impl<'brand> SyncRegionToken<'brand>

Source

pub const unsafe fn new_unchecked() -> SyncRegionToken<'brand>

Construct a token without proving brand uniqueness.

§Safety

The caller must guarantee that no other token for the same 'brand exists for the lifetime of the returned value. Violating this allows two write permits of one brand to coexist, which is undefined behaviour.

Source§

impl<'brand> SyncRegionToken<'brand>

Source

pub fn share<'a>(&'a self) -> SharedReadToken<'a, 'brand>

Mint a Copy, read-only SharedReadToken tied to this borrow.

The returned token borrows self immutably for 'a, so while any copy of it is live the owning token cannot be borrowed mutably and no write permit can be formed.

Trait Implementations§

Source§

impl<'brand> Debug for SyncRegionToken<'brand>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'brand> Freeze for SyncRegionToken<'brand>

§

impl<'brand> RefUnwindSafe for SyncRegionToken<'brand>

§

impl<'brand> Send for SyncRegionToken<'brand>

§

impl<'brand> Sync for SyncRegionToken<'brand>

§

impl<'brand> Unpin for SyncRegionToken<'brand>

§

impl<'brand> UnsafeUnpin for SyncRegionToken<'brand>

§

impl<'brand> UnwindSafe for SyncRegionToken<'brand>

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 = !

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.