MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
LiveArena.cpp
Go to the documentation of this file.
1#include "LiveArena.hpp"
2
3namespace MayaFlux {
4
5namespace internal {
6
7 std::atomic<bool> g_live_exposure_enabled { false };
8
9 void enable_live_exposure() noexcept
10 {
11 g_live_exposure_enabled.store(true, std::memory_order_relaxed);
12 }
13
14 bool live_exposure_enabled() noexcept
15 {
16 return g_live_exposure_enabled.load(std::memory_order_relaxed);
17 }
18
19 alignas(std::max_align_t) unsigned char g_live_arena_storage[LIVE_ARENA_CAPACITY] {};
20 uint32_t g_live_arena_bump {};
22
23} // namespace internal
24
25MAYAFLUX_API void* live_cast_impl(const char* key) noexcept
26{
27 auto* hdr = internal::live_arena_header();
28 for (uint32_t i = 0; i < hdr->entry_count; ++i) {
29 auto& entry = hdr->entries[i];
30 if (!entry.occupied) {
31 continue;
32 }
33 if (std::strncmp(entry.key, key, internal::LIVE_ARENA_KEY_MAX) != 0) {
34 continue;
35 }
36 if (entry.offset == UINT32_MAX) {
38 }
39 return internal::live_arena_object_region() + entry.offset;
40 }
41 return nullptr;
42}
43
44MAYAFLUX_API void live_arena_dump() noexcept
45{
46 auto* hdr = internal::live_arena_header();
47 for (uint32_t i = 0; i < hdr->entry_count; ++i) {
48 auto& entry = hdr->entries[i];
49 fprintf(stderr, "[LiveArena] %u: key=\"%s\" occupied=%d offset=%u\n",
50 i, entry.key, (int)entry.occupied, entry.offset);
51 }
52 fprintf(stderr, "[LiveArena] entry_count=%u bump=%u\n",
53 hdr->entry_count, internal::g_live_arena_bump);
54}
55
56} // namespace MayaFlux
void enable_live_exposure() noexcept
Turns on exposure for the MF_LIVE_EXPOSE macros in the linked library.
Definition LiveArena.cpp:9
constexpr std::size_t LIVE_ARENA_KEY_MAX
Maximum length of a live arena key, including null terminator.
Definition LiveArena.hpp:34
constexpr std::size_t LIVE_ARENA_MAX_ENTRIES
Maximum number of objects that can be registered in the live arena.
Definition LiveArena.hpp:29
uint32_t g_live_arena_bump
Byte offset of the bump pointer from the start of the object region.
Definition LiveArena.cpp:20
constexpr std::size_t LIVE_ARENA_CAPACITY
Default capacity of the live arena in bytes.
Definition LiveArena.hpp:39
bool live_exposure_enabled() noexcept
Reports whether live exposure has been enabled.
Definition LiveArena.cpp:14
LiveArenaHeader * live_arena_header() noexcept
Returns a pointer to the header block at the start of arena storage.
unsigned char * live_arena_object_region() noexcept
Returns a pointer to the object region (immediately after the header).
std::atomic< bool > g_live_exposure_enabled
Whether the MF_LIVE_EXPOSE macros publish objects to the arena.
Definition LiveArena.cpp:7
unsigned char g_live_arena_storage[LIVE_ARENA_CAPACITY]
Raw backing storage for the live arena with external linkage.
Definition LiveArena.cpp:19
std::shared_ptr< void > g_live_arena_shared_ptrs[LIVE_ARENA_MAX_ENTRIES]
Shared ownership table for objects registered via expose_live.
Definition LiveArena.cpp:21
MAYAFLUX_API void * live_cast_impl(const char *key) noexcept
Internal implementation for live_cast.
Definition LiveArena.cpp:25
MAYAFLUX_API void live_arena_dump() noexcept
Dumps all live arena entries to stderr.
Definition LiveArena.cpp:44
Main namespace for the Maya Flux audio engine.
Definition Runtime.cpp:12