Skip to main content

ConcurrentMemoryManager

Struct ConcurrentMemoryManager 

Source
pub struct ConcurrentMemoryManager<P: Payload> { /* private fields */ }
Expand description

Public concurrent manager handle.

This is cheap to clone (clones the Arc), so multiple threads can share a ConcurrentMemoryManager instance and call the *_shared(&self) methods concurrently.

Implementations§

Source§

impl<P: Payload> ConcurrentMemoryManager<P>

Source

pub fn new(capacity: usize) -> Self

Create a new manager with the given capacity. Capacity must be finite and typically small-to-moderate (4..1024) for best performance.

The manager defaults to MemoryClass::Host.

Source

pub fn with_memory_class(capacity: usize, mem_class: MemoryClass) -> Self

Create a new manager with explicit memory_class metadata.

memory_class is useful for telemetry and for future routing decisions when different storage classes exist.

Source

pub fn store_shared( &self, value: Message<P>, ) -> Result<MessageToken, MemoryError>

Store a Message<P> and return its MessageToken.

This method:

  • Pops a free index from the freelist (lock-free).
  • Acquires the slot write lock and sets message = Some(value).

Returns MemoryError::NoFreeSlots if the freelist is empty.

Concurrency: multiple threads may concurrently allocate and store into different slots. Only the chosen slot is write-locked during the store.

Source

pub fn read_shared( &self, token: MessageToken, ) -> Result<ConcurrentReadGuard<'_, P>, MemoryError>

Borrow a stored message immutably, returning a guard that keeps the slot read-locked for the lifetime of the guard.

Returns:

  • BadToken if the token index is out of range,
  • NotAllocated if the slot is currently empty,
  • Poisoned if the slot lock is poisoned.

Concurrency: read locks allow many concurrent readers for the same slot.

Source

pub fn read_mut_shared( &self, token: MessageToken, ) -> Result<ConcurrentWriteGuard<'_, P>, MemoryError>

Borrow a stored message mutably, returning a guard that keeps the slot write-locked for the lifetime of the guard.

This enforces exclusive access to the stored message while the guard is live.

Source

pub fn free_shared(&self, token: MessageToken) -> Result<(), MemoryError>

Free a previously allocated token/slot.

Behavior:

  • Acquire the slot write lock (this will wait for readers/writers).
  • Ensure the slot is allocated; set message = None.
  • Push the index back onto the lock-free freelist.

Returns NotAllocated if slot already empty or BadToken if token invalid.

Source

pub fn available(&self) -> usize

Return the approximate number of free slots. This is updated atomically on each successful freelist push/pop. The value is diagnostic and may be slightly stale if concurrent operations are in-flight.

Source

pub fn capacity(&self) -> usize

Return the configured capacity (number of slots).

Source

pub fn memory_class(&self) -> MemoryClass

Return the memory class attached to this manager.

Trait Implementations§

Source§

impl<P: Payload> Clone for ConcurrentMemoryManager<P>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<P: Payload> HeaderStore for ConcurrentMemoryManager<P>

Source§

fn peek_header( &self, token: MessageToken, ) -> Result<Self::HeaderGuard<'_>, MemoryError>

Peek the header of the stored message identified by token.

This acquires a slot read lock and returns a guard that keeps the lock for the lifetime of the returned guard.

Source§

type HeaderGuard<'a> = ConcurrentHeaderGuard<'a, P> where Self: 'a

Guard type returned by HeaderStore::peek_header. Read more
Source§

impl<P: Payload> MemoryManager<P> for ConcurrentMemoryManager<P>

Source§

type ReadGuard<'a> = ConcurrentReadGuard<'a, P> where Self: 'a

Shared read guard returned by MemoryManager::read. Read more
Source§

type WriteGuard<'a> = ConcurrentWriteGuard<'a, P> where Self: 'a

Exclusive mutable guard returned by MemoryManager::read_mut. Read more
Source§

fn store(&mut self, value: Message<P>) -> Result<MessageToken, MemoryError>

Allocate storage for value and return its token. Read more
Source§

fn read(&self, token: MessageToken) -> Result<Self::ReadGuard<'_>, MemoryError>

Borrow a stored message immutably. Read more
Source§

fn read_mut( &mut self, token: MessageToken, ) -> Result<Self::WriteGuard<'_>, MemoryError>

Borrow a stored message mutably. Read more
Source§

fn free(&mut self, token: MessageToken) -> Result<(), MemoryError>

Free the slot identified by token. Read more
Source§

fn available(&self) -> usize

Return the number of currently free slots. Read more
Source§

fn capacity(&self) -> usize

Return the total slot capacity of the manager.
Source§

fn memory_class(&self) -> MemoryClass

Return the memory class represented by this manager. Read more
Source§

impl<P: Payload + Send + Sync> ScopedManager<P> for ConcurrentMemoryManager<P>

Source§

type Handle<'a> = ConcurrentMemoryManager<P> where Self: 'a

Per-worker handle type.
Source§

fn scoped_handle<'a>(&'a self) -> Self::Handle<'a>
where Self: 'a,

Create a scoped handle for a worker thread.

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.