|
MXL : Media eXchange Layer
MXL
|
Non-owning single-producer event ring view safe for concurrent snapshot readers. More...
#include <EventRingBuffer.hpp>

Public Types | |
| enum class | ReadResult { Ready , Pending , Overwritten , Invalid } |
| Outcome of a bounded attempt to copy an entry without waiting. More... | |
Public Member Functions | |
| EventRingBuffer (void *memory, std::uint32_t count, std::uint32_t payloadSize) | |
| Attach a view and validate immutable headers across all slots. | |
| mxlStatus | publish (std::uint64_t index, mxlEventInfo const &info, std::uint8_t const *payload) noexcept |
| Atomically publish metadata and payload under a new sequence tag. | |
| ReadResult | read (std::uint64_t index, mxlEventInfo &info, std::uint8_t *payload) const noexcept |
| Copy one entry with sequence validation before and after the copy. | |
Static Public Member Functions | |
| static std::size_t | bufferSize (std::uint32_t count, std::uint32_t payloadSize) |
| Validate geometry and compute the complete mapping length. | |
| static void | initialize (void *memory, std::uint32_t count, std::uint32_t payloadSize) |
| Construct headers, empty sequence tags and payload words in a fresh mapping. | |
| static std::uint64_t | load (std::uint64_t const &value) noexcept |
| Load a shared 64-bit word with acquire ordering, including from a read-only mapping. | |
| static constexpr std::size_t | slotStride (std::uint32_t payloadSize) noexcept |
| Compute the physical stride between adjacent slots. | |
Static Public Attributes | |
| static constexpr auto | EMPTY = std::numeric_limits<std::uint64_t>::max() |
| Tag identifying a slot with no publication. | |
| static constexpr auto | MAX_INDEX = (EMPTY >> 1) - 1 |
| Largest index whose complete tag does not collide with EMPTY. | |
| static constexpr auto | STORAGE_VERSION = std::uint32_t{1} |
| Version used by immutable ring and slot headers. | |
Private Member Functions | |
| Event & | slot (std::uint64_t index) const noexcept |
| Resolve a logical queue index to a physical slot modulo capacity. | |
Static Private Member Functions | |
| static void | loadBytes (void *destination, std::uint64_t const *source, std::size_t size) noexcept |
| Copy shared words into private bytes using acquire loads. | |
| static std::uint64_t * | payloadWords (Event &event) noexcept |
| Locate the atomic payload words immediately after an event slot header. | |
| static void | storeBytes (std::uint64_t *destination, void const *source, std::size_t size) noexcept |
| Copy private bytes to shared words using release stores. | |
| static void | validateGeometry (std::uint32_t count, std::uint32_t payloadSize) |
| Validate slot count, payload capacity and mapping-size limits. | |
Private Attributes | |
| std::uint32_t | _count |
| Validated physical slot count. | |
| EventRingHeader * | _header |
| Borrowed address of the mapping's immutable ring header. | |
| std::uint32_t | _payloadSize |
| Validated per-entry payload capacity in bytes. | |
| std::size_t | _stride |
| Aligned distance in bytes between slot headers. | |
Non-owning single-producer event ring view safe for concurrent snapshot readers.
Metadata and payload are copied through atomic words; sequence tags detect overwrite during a read. The writer owns head advancement, timestamp validation and notifications. No shared tail or writer reservation cursor is stored here. The mapping must outlive this view and all calls through it.
Inspired by vt-tv/lockfree_ipc_ringbuffer revision ffd97a3cb0162109920af04408b54c2703aa9e4e; see docs/EventFlows.md.
Definition at line 47 of file EventRingBuffer.hpp.
|
strong |
Outcome of a bounded attempt to copy an entry without waiting.
Definition at line 55 of file EventRingBuffer.hpp.
|
inline |
Attach a view and validate immutable headers across all slots.
| memory | Initialized mapping, possibly read-only for a reader. |
| count | Expected slot count from the common flow configuration. |
| payloadSize | Expected per-entry payload capacity. |
| std::invalid_argument | Geometry or a ring/slot header is invalid. |
Definition at line 105 of file EventRingBuffer.hpp.
|
inlinestatic |
Validate geometry and compute the complete mapping length.
| count | Number of slots, from 2 through 65536. |
| payloadSize | Maximum bytes per entry, from 1 through 1048576. |
| std::invalid_argument | Geometry is unsupported or its byte count overflows. |
Definition at line 81 of file EventRingBuffer.hpp.
|
static |
Construct headers, empty sequence tags and payload words in a fresh mapping.
| [out] | memory | Writable storage of at least bufferSize(count, payloadSize) bytes. |
| count | Number of slots to construct. | |
| payloadSize | Maximum bytes per entry. |
| std::invalid_argument | Geometry is invalid. |
Definition at line 9 of file EventRingBuffer.cpp.
|
inlinestaticnoexcept |
Load a shared 64-bit word with acquire ordering, including from a read-only mapping.
| value | Naturally aligned word accessed atomically by concurrent users. |
Definition at line 205 of file EventRingBuffer.hpp.
|
inlinestaticprivatenoexcept |
Copy shared words into private bytes using acquire loads.
| [out] | destination | Private storage covering size bytes. |
| source | Aligned shared words covering size rounded up to eight bytes. | |
| size | Byte count to copy; the final word may be copied partially. |
Definition at line 271 of file EventRingBuffer.hpp.
|
inlinestaticprivatenoexcept |
Locate the atomic payload words immediately after an event slot header.
| event | Slot header inside a live mapping. |
Definition at line 241 of file EventRingBuffer.hpp.
|
inlinenoexcept |
Atomically publish metadata and payload under a new sequence tag.
| index | Queue index selected by the sole producer, normally headIndex + 1. |
| info | Validated entry metadata; eventSize must not exceed the ring capacity. |
| payload | Source of at least info.eventSize bytes, stable for the call. |
| MXL_STATUS_OK | The entry is published; the caller may advance the head. |
| MXL_ERR_OUT_OF_RANGE_TOO_LATE | index exceeds MAX_INDEX. |
| MXL_ERR_FLOW_INVALID | The slot already holds this or a newer sequence tag. |
Definition at line 139 of file EventRingBuffer.hpp.
|
inlinenoexcept |
Copy one entry with sequence validation before and after the copy.
| index | Queue index to read. | |
| [out] | info | Destination for metadata. |
| [out] | payload | Private destination with at least the configured payload capacity. |
Definition at line 169 of file EventRingBuffer.hpp.
|
inlineprivatenoexcept |
Resolve a logical queue index to a physical slot modulo capacity.
| index | Queue index whose slot is needed. |
Definition at line 231 of file EventRingBuffer.hpp.
|
inlinestaticconstexprnoexcept |
Compute the physical stride between adjacent slots.
| payloadSize | Maximum payload bytes per entry. |
Definition at line 68 of file EventRingBuffer.hpp.
|
inlinestaticprivatenoexcept |
Copy private bytes to shared words using release stores.
| [out] | destination | Aligned words with space for size rounded up to eight bytes. |
| source | Stable private bytes to publish. | |
| size | Byte count; zero permits a null source. |
Definition at line 252 of file EventRingBuffer.hpp.
|
inlinestaticprivate |
Validate slot count, payload capacity and mapping-size limits.
| std::invalid_argument | Geometry is unsupported or its byte count overflows. |
Definition at line 217 of file EventRingBuffer.hpp.
|
private |
Validated physical slot count.
Definition at line 283 of file EventRingBuffer.hpp.
|
private |
Borrowed address of the mapping's immutable ring header.
Definition at line 282 of file EventRingBuffer.hpp.
|
private |
Validated per-entry payload capacity in bytes.
Definition at line 284 of file EventRingBuffer.hpp.
|
private |
Aligned distance in bytes between slot headers.
Definition at line 285 of file EventRingBuffer.hpp.
|
staticconstexpr |
Tag identifying a slot with no publication.
Definition at line 51 of file EventRingBuffer.hpp.
|
staticconstexpr |
Largest index whose complete tag does not collide with EMPTY.
Definition at line 52 of file EventRingBuffer.hpp.
|
staticconstexpr |
Version used by immutable ring and slot headers.
Definition at line 50 of file EventRingBuffer.hpp.