Corium 1.1.0
High-Performance Zero-Heap C++20 MPSC Application Runtime
Loading...
Searching...
No Matches
corium::ipc::ShmMpscQueue< T, Capacity > Class Template Reference

Lock-free, zero-allocation multi-producer single-consumer ring buffer layout for shared memory. Compatible with POD and trivially copyable types (or serialized payloads). More...

#include <ShmMpscQueue.hpp>

+ Inheritance diagram for corium::ipc::ShmMpscQueue< T, Capacity >:
+ Collaboration diagram for corium::ipc::ShmMpscQueue< T, Capacity >:

Classes

struct  Cell
 
struct  Layout
 

Public Member Functions

void bind (void *mappedAddress, bool initializeMemory=false) noexcept
 Bind to a mapped shared memory region.
 
constexpr std::size_t capacity () const noexcept
 Get configured capacity of the queue.
 
bool empty () const noexcept
 Check if queue is currently empty.
 
bool isValid () const noexcept
 Validate that the mapped shared memory contains a compatible ShmMpscQueue header.
 
 ShmMpscQueue ()=default
 
 ShmMpscQueue (void *mappedAddress, bool initializeMemory=false) noexcept
 Construct queue bound to a mapped shared memory address.
 
bool tryPop (T &outItem) noexcept
 Lock-free pop from shared memory queue (single-consumer safe).
 
template<typename U >
bool tryPush (U &&item) noexcept
 Lock-free push into shared memory queue (multi-producer safe).
 

Static Public Member Functions

static constexpr std::size_t requiredMemorySize () noexcept
 Required byte size of the shared memory layout.
 

Static Public Attributes

static constexpr std::size_t BufferCapacity = Capacity
 
static constexpr std::size_t BufferMask = Capacity - 1
 

Detailed Description

template<typename T, std::size_t Capacity = 256>
class corium::ipc::ShmMpscQueue< T, Capacity >

Lock-free, zero-allocation multi-producer single-consumer ring buffer layout for shared memory. Compatible with POD and trivially copyable types (or serialized payloads).

Template Parameters
TValue type stored in each ring cell.
CapacityNumber of slots (must be a power of 2).

Constructor & Destructor Documentation

◆ ShmMpscQueue() [1/2]

template<typename T , std::size_t Capacity = 256>
corium::ipc::ShmMpscQueue< T, Capacity >::ShmMpscQueue ( )
default

◆ ShmMpscQueue() [2/2]

template<typename T , std::size_t Capacity = 256>
corium::ipc::ShmMpscQueue< T, Capacity >::ShmMpscQueue ( void *  mappedAddress,
bool  initializeMemory = false 
)
inlineexplicitnoexcept

Construct queue bound to a mapped shared memory address.

+ Here is the call graph for this function:

Member Function Documentation

◆ bind()

template<typename T , std::size_t Capacity = 256>
void corium::ipc::ShmMpscQueue< T, Capacity >::bind ( void *  mappedAddress,
bool  initializeMemory = false 
)
inlinenoexcept

Bind to a mapped shared memory region.

Parameters
mappedAddressPointer to shared memory.
initializeMemoryIf true, resets header and cell sequences (creator process).
+ Here is the caller graph for this function:

◆ capacity()

template<typename T , std::size_t Capacity = 256>
constexpr std::size_t corium::ipc::ShmMpscQueue< T, Capacity >::capacity ( ) const
inlineconstexprnoexcept

Get configured capacity of the queue.

◆ empty()

template<typename T , std::size_t Capacity = 256>
bool corium::ipc::ShmMpscQueue< T, Capacity >::empty ( ) const
inlinenoexcept

Check if queue is currently empty.

+ Here is the caller graph for this function:

◆ isValid()

template<typename T , std::size_t Capacity = 256>
bool corium::ipc::ShmMpscQueue< T, Capacity >::isValid ( ) const
inlinenoexcept

Validate that the mapped shared memory contains a compatible ShmMpscQueue header.

+ Here is the caller graph for this function:

◆ requiredMemorySize()

template<typename T , std::size_t Capacity = 256>
static constexpr std::size_t corium::ipc::ShmMpscQueue< T, Capacity >::requiredMemorySize ( )
inlinestaticconstexprnoexcept

Required byte size of the shared memory layout.

+ Here is the caller graph for this function:

◆ tryPop()

template<typename T , std::size_t Capacity = 256>
bool corium::ipc::ShmMpscQueue< T, Capacity >::tryPop ( T &  outItem)
inlinenoexcept

Lock-free pop from shared memory queue (single-consumer safe).

Parameters
outItemReference populated with popped value.
Returns
true if popped, false if queue is empty.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tryPush()

template<typename T , std::size_t Capacity = 256>
template<typename U >
bool corium::ipc::ShmMpscQueue< T, Capacity >::tryPush ( U &&  item)
inlinenoexcept

Lock-free push into shared memory queue (multi-producer safe).

Parameters
itemValue to push.
Returns
true if pushed, false if queue is full.
+ Here is the caller graph for this function:

Member Data Documentation

◆ BufferCapacity

template<typename T , std::size_t Capacity = 256>
constexpr std::size_t corium::ipc::ShmMpscQueue< T, Capacity >::BufferCapacity = Capacity
staticconstexpr

◆ BufferMask

template<typename T , std::size_t Capacity = 256>
constexpr std::size_t corium::ipc::ShmMpscQueue< T, Capacity >::BufferMask = Capacity - 1
staticconstexpr

The documentation for this class was generated from the following file: