Skip to content

EntropyEngine::Networking::SharedMemory::SharedMemoryControlBlock

EntropyEngine::Networking::SharedMemory::SharedMemoryControlBlock

Section titled “EntropyEngine::Networking::SharedMemory::SharedMemoryControlBlock”

Control block structure placed at the start of each shared memory region. More…

#include <SharedMemoryPlatform.h>

Name
boolvalidate() const
Validate control block was initialized correctly.
voidinitializeServer(size_t regionSize)
Initialize control block for server.
Name
uint32_tversion
Must be <= SHM_VERSION.
uint64_tvalidationToken
Random token for connection validation.
uint64_ttotalSize
Total region size.
std::atomic< uint32_t >shutdown
Shutdown requested.
std::atomic< uint32_t >serverReady
Server has initialized region.
uint32_tserverPid
Server process ID.
std::atomic< uint64_t >s2cWritePos
Server write position.
std::atomic< uint32_t >s2cWakeFlag
Wake flag for client.
std::atomic< uint64_t >s2cReadPos
Client read position.
uint64_tringBufferSize
Size of each ring buffer.
uint32_treserved2
Reserved for alignment.
uint32_treserved1
Reserved for alignment.
uint32_treserved0
Reserved for alignment.
uint8_t[40]padding2
Pad to 64 bytes.
uint8_t[40]padding1
Pad to 64 bytes.
uint8_t[24]padding0
Pad to 64 bytes.
uint32_tmagic
Must be SHM_MAGIC.
std::atomic< uint32_t >clientReady
Client has connected.
uint32_tclientPid
Client process ID (set after connect).
std::atomic< uint64_t >c2sWritePos
Client write position.
std::atomic< uint32_t >c2sWakeFlag
Wake flag for server.
std::atomic< uint64_t >c2sReadPos
Server read position.
struct EntropyEngine::Networking::SharedMemory::SharedMemoryControlBlock;

Control block structure placed at the start of each shared memory region.

Layout is fixed and must match across all platforms. Structure is organized into cache lines to prevent false sharing:

Cache line 0 [0-63]: Header + connection state (read-mostly) Cache line 1 [64-127]: Server-to-Client ring buffer atomics Cache line 2 [128-191]: Client-to-Server ring buffer atomics Cache line 3 [192-255]: Reserved for future use

inline bool validate() const

Validate control block was initialized correctly.

Return: true if magic and version are valid

inline void initializeServer(
size_t regionSize
)

Initialize control block for server.

Parameters:

  • regionSize Total size of the shared memory region
uint32_t version;

Must be <= SHM_VERSION.

uint64_t validationToken;

Random token for connection validation.

uint64_t totalSize;

Total region size.

std::atomic< uint32_t > shutdown;

Shutdown requested.

std::atomic< uint32_t > serverReady;

Server has initialized region.

uint32_t serverPid;

Server process ID.

std::atomic< uint64_t > s2cWritePos;

Server write position.

std::atomic< uint32_t > s2cWakeFlag;

Wake flag for client.

std::atomic< uint64_t > s2cReadPos;

Client read position.

uint64_t ringBufferSize;

Size of each ring buffer.

uint32_t reserved2;

Reserved for alignment.

uint32_t reserved1;

Reserved for alignment.

uint32_t reserved0;

Reserved for alignment.

uint8_t[40] padding2;

Pad to 64 bytes.

uint8_t[40] padding1;

Pad to 64 bytes.

uint8_t[24] padding0;

Pad to 64 bytes.

uint32_t magic;

Must be SHM_MAGIC.

std::atomic< uint32_t > clientReady;

Client has connected.

uint32_t clientPid;

Client process ID (set after connect).

std::atomic< uint64_t > c2sWritePos;

Client write position.

std::atomic< uint32_t > c2sWakeFlag;

Wake flag for server.

std::atomic< uint64_t > c2sReadPos;

Server read position.


Updated on 2026-01-26 at 17:14:35 -0500