Skip to main content

SharedRegion

Struct SharedRegion 

Source
pub struct SharedRegion<T: Copy + 'static> { /* private fields */ }

Implementations§

Source§

impl<T: Copy + 'static> SharedRegion<T>

Source

pub fn create( path: impl AsRef<Path>, capacity: usize, ) -> Result<Self, RegionError>

Obtain the region at path, initializing an empty one if the path does not yet exist and attaching to it if it does. Attaching leaves allocated slots and the free list in place, so outstanding OffsetPtrs stay resolvable; a region built with a different capacity or payload type is a LayoutMismatch. reset reinitializes.

Source

pub fn reset( path: impl AsRef<Path>, capacity: usize, ) -> Result<Self, RegionError>

Truncate the region at path and initialize an empty one, invalidating every OffsetPtr live peers hold. For a caller that knows it owns the path.

Source

pub fn open( path: impl AsRef<Path>, expected_capacity: usize, ) -> Result<Self, RegionError>

Source

pub fn capacity(&self) -> usize

Source

pub fn mmap_ptr(&self) -> *const u8

Raw pointer to the start of the MMF. Useful for primitives built on top of SharedRegion that need direct memory access (e.g., SharedLinkedList reads node next/prev/value fields directly at computed offsets instead of copying the whole node).

Source

pub fn len(&self) -> usize

Number of slots currently allocated (bump high-water minus free-list length). This is a snapshot; concurrent alloc/free may race.

Source

pub fn is_empty(&self) -> bool

Source

pub fn free_count(&self) -> usize

Walk the free list (best-effort under concurrent activity) and return its length. O(N_free).

Source

pub fn allocate(&self, value: T) -> Result<OffsetPtr<T>, RegionError>

Allocate a slot. Tries the free list first, then bump allocates. Returns Err(Full) when both are exhausted.

Source

pub fn free(&self, ptr: OffsetPtr<T>) -> Result<T, RegionError>

Free a slot, returning the T it held. Pushes onto the Treiber-stack free list.

Source

pub fn get(&self, ptr: OffsetPtr<T>) -> Result<T, RegionError>

Read the value at ptr. Returns Err(InvalidPtr) for nil or out-of-bounds. Caller is responsible for ensuring the ptr refers to a still-allocated slot (free’d slots may be reallocated and contain a different value).

Source

pub fn set(&self, ptr: OffsetPtr<T>, value: T) -> Result<(), RegionError>

Overwrite the value at ptr. Same caveats as get: caller must hold a still-valid pointer.

Source

pub fn clear(&self)

Reset the region to empty: bump pointer back to 0 and free list back to NIL. Existing OffsetPtr values become stale; callers must drop them. Useful for steady-state benches that need to reset accumulated state between iterations.

Not thread-safe: do not call concurrently with allocate / free from other threads. Intended for single-threaded reset (e.g. test setup, bench iter setup).

Source

pub fn flush(&self) -> Result<(), RegionError>

Source

pub fn flush_async(&self) -> Result<(), RegionError>

Non-blocking flush: schedules a writeback via the OS. Note: Windows is only partially async (sync to page cache, not to disk).

Trait Implementations§

Source§

impl<T: Copy + Send + Sync + 'static> AdaptiveInstance for SharedRegion<T>

Source§

fn header(&self) -> &HandshakeHeader

Source§

fn ring(&self) -> &ObservationRing

Source§

fn make_policy(&self) -> Box<dyn Policy>

Source§

fn apply_migration(&self, new_tag: u32)

Called by the sidecar when the policy returns a new strategy tag. Default implementation: just set the tag on the header. Primitives that need heavier migration (data-layout swap) override this to perform the swap before (or after) updating the tag.
Source§

impl<T: Copy + Send + 'static> Send for SharedRegion<T>

Source§

impl<T: Copy + Sync + 'static> Sync for SharedRegion<T>

Auto Trait Implementations§

§

impl<T> !Freeze for SharedRegion<T>

§

impl<T> !UnwindSafe for SharedRegion<T>

§

impl<T> RefUnwindSafe for SharedRegion<T>

§

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

§

impl<T> UnsafeUnpin for SharedRegion<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> 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 = 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.