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>
impl<P: Payload> ConcurrentMemoryManager<P>
Sourcepub fn new(capacity: usize) -> Self
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.
Sourcepub fn with_memory_class(capacity: usize, mem_class: MemoryClass) -> Self
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.
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.
Borrow a stored message immutably, returning a guard that keeps the slot read-locked for the lifetime of the guard.
Returns:
BadTokenif the token index is out of range,NotAllocatedif the slot is currently empty,Poisonedif the slot lock is poisoned.
Concurrency: read locks allow many concurrent readers for the same slot.
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.
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.
Sourcepub fn available(&self) -> usize
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.
Sourcepub fn memory_class(&self) -> MemoryClass
pub fn memory_class(&self) -> MemoryClass
Return the memory class attached to this manager.
Trait Implementations§
Source§impl<P: Payload> Clone for ConcurrentMemoryManager<P>
impl<P: Payload> Clone for ConcurrentMemoryManager<P>
Source§impl<P: Payload> HeaderStore for ConcurrentMemoryManager<P>
impl<P: Payload> HeaderStore for ConcurrentMemoryManager<P>
Source§fn peek_header(
&self,
token: MessageToken,
) -> Result<Self::HeaderGuard<'_>, MemoryError>
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
type HeaderGuard<'a> = ConcurrentHeaderGuard<'a, P> where Self: 'a
HeaderStore::peek_header. Read moreSource§impl<P: Payload> MemoryManager<P> for ConcurrentMemoryManager<P>
impl<P: Payload> MemoryManager<P> for ConcurrentMemoryManager<P>
Source§type ReadGuard<'a> = ConcurrentReadGuard<'a, P>
where
Self: 'a
type ReadGuard<'a> = ConcurrentReadGuard<'a, P> where Self: 'a
MemoryManager::read. Read moreSource§type WriteGuard<'a> = ConcurrentWriteGuard<'a, P>
where
Self: 'a
type WriteGuard<'a> = ConcurrentWriteGuard<'a, P> where Self: 'a
MemoryManager::read_mut. Read moreSource§fn store(&mut self, value: Message<P>) -> Result<MessageToken, MemoryError>
fn store(&mut self, value: Message<P>) -> Result<MessageToken, MemoryError>
value and return its token. Read moreSource§fn read(&self, token: MessageToken) -> Result<Self::ReadGuard<'_>, MemoryError>
fn read(&self, token: MessageToken) -> Result<Self::ReadGuard<'_>, MemoryError>
Source§fn read_mut(
&mut self,
token: MessageToken,
) -> Result<Self::WriteGuard<'_>, MemoryError>
fn read_mut( &mut self, token: MessageToken, ) -> Result<Self::WriteGuard<'_>, MemoryError>
Source§fn free(&mut self, token: MessageToken) -> Result<(), MemoryError>
fn free(&mut self, token: MessageToken) -> Result<(), MemoryError>
token. Read more