MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
EventRingBuffer.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Contributors to the Media eXchange Layer project.
2// SPDX-License-Identifier: Apache-2.0
3
5#include <memory>
6
7namespace mxl::lib
8{
9 void EventRingBuffer::initialize(void* memory, std::uint32_t count, std::uint32_t payloadSize)
10 {
11 validateGeometry(count, payloadSize);
12 auto header = std::construct_at(static_cast<EventRingHeader*>(memory));
13 header->version = STORAGE_VERSION;
14 header->size = sizeof *header;
15 header->eventCount = count;
16 header->payloadSize = payloadSize;
17 auto slotMemory = static_cast<std::uint8_t*>(memory) + sizeof(EventRingHeader);
18 auto const stride = slotStride(payloadSize);
19 auto const payloadWordCount = (payloadSize + sizeof(std::uint64_t) - 1) / sizeof(std::uint64_t);
20 for (auto i = std::size_t{0}; i < count; ++i, slotMemory += stride)
21 {
22 auto event = std::construct_at(reinterpret_cast<Event*>(slotMemory));
23 event->header.version = STORAGE_VERSION;
24 event->header.size = sizeof event->header;
25 event->header.sequence = EMPTY;
26 std::uninitialized_value_construct_n(payloadWords(*event), payloadWordCount);
27 }
28 }
29}
Atomic single-producer event ring storage and snapshot protocol.
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 constexpr auto EMPTY
Tag identifying a slot with no publication.
static std::uint64_t * payloadWords(Event &event) noexcept
Locate the atomic payload words immediately after an event slot header.
static void validateGeometry(std::uint32_t count, std::uint32_t payloadSize)
Validate slot count, payload capacity and mapping-size limits.
static constexpr std::size_t slotStride(std::uint32_t payloadSize) noexcept
Compute the physical stride between adjacent slots.
static constexpr auto STORAGE_VERSION
Version used by immutable ring and slot headers.
std::size_t count(uuids::uuid id) const noexcept
Returns the number of writers registered for flow id 'id'.
Immutable 4 KiB geometry header at the start of the single event ring file.
Fixed part of an event slot; its payload follows immediately in the mapping.
Definition Flow.hpp:90