Skip to content

EntropyEngine::Networking::SharedMemory::PlatformOps

EntropyEngine::Networking::SharedMemory::PlatformOps

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

Platform-specific shared memory operations. More…

#include <SharedMemoryPlatform.h>

Name
voidwakeAll(std::atomic< uint32_t > * addr)
Wake all threads waiting on an atomic flag.
voidwake(std::atomic< uint32_t > * addr)
Wake threads waiting on an atomic flag.
boolwaitUntilChanged(std::atomic< uint32_t > * addr, uint32_t expected, int timeoutMs)
Wait until an atomic flag changes from expected value.
voidunmapRegion(void * ptr, size_t size)
Unmap a previously mapped region.
NativeHandleopenRegion(const char * name)
Open an existing shared memory region.
void *mapRegion(NativeHandle handle, size_t size)
Map a shared memory region into process address space.
boolisAvailable()
Check if shared memory is available on this platform.
std::stringgetLastErrorString()
Get the last platform error as a string.
voiddestroyRegion(const char * name)
Destroy a shared memory region.
NativeHandlecreateRegion(const char * name, size_t size)
Create a new shared memory region.
voidcloseRegion(NativeHandle handle)
Close a region handle.
struct EntropyEngine::Networking::SharedMemory::PlatformOps;

Platform-specific shared memory operations.

All methods are static and thread-safe. Each platform provides its own implementation in SharedMemoryPlatformUnix.cpp or SharedMemoryPlatformWin32.cpp.

static void wakeAll(
std::atomic< uint32_t > * addr
)

Wake all threads waiting on an atomic flag.

Parameters:

  • addr Address of the atomic flag
static void wake(
std::atomic< uint32_t > * addr
)

Wake threads waiting on an atomic flag.

Parameters:

  • addr Address of the atomic flag

Uses platform-specific futex (Linux), ulock (macOS), or WaitOnAddress (Windows).

static bool waitUntilChanged(
std::atomic< uint32_t > * addr,
uint32_t expected,
int timeoutMs
)

Wait until an atomic flag changes from expected value.

Parameters:

  • addr Address of the atomic flag
  • expected Value to wait for change from
  • timeoutMs Maximum wait time in milliseconds (-1 for infinite)

Return: true if value changed, false if timed out

Blocks until the value at addr is no longer equal to expected, or timeout expires.

static void unmapRegion(
void * ptr,
size_t size
)

Unmap a previously mapped region.

Parameters:

  • ptr Pointer returned by mapRegion
  • size Size of the mapped region
static NativeHandle openRegion(
const char * name
)

Open an existing shared memory region.

Parameters:

  • name Region name (must match createRegion name)

Return: Handle to the opened region, or INVALID_HANDLE_VALUE_SHM on failure

Opens a shared memory region previously created by another process.

static void * mapRegion(
NativeHandle handle,
size_t size
)

Map a shared memory region into process address space.

Parameters:

  • handle Handle from createRegion or openRegion
  • size Size of the region to map

Return: Pointer to mapped memory, or nullptr on failure

static bool isAvailable()

Check if shared memory is available on this platform.

Return: true if shared memory operations are supported

static std::string getLastErrorString()

Get the last platform error as a string.

Return: Error description

Returns a human-readable string for the last platform-specific error.

static void destroyRegion(
const char * name
)

Destroy a shared memory region.

Parameters:

  • name Region name

Removes the region from the filesystem/namespace. Existing mappings remain valid until unmapped.

static NativeHandle createRegion(
const char * name,
size_t size
)

Create a new shared memory region.

Parameters:

  • name Region name (platform-specific prefixing is handled internally)
  • size Size of the region in bytes

Return: Handle to the created region, or INVALID_HANDLE_VALUE_SHM on failure

Creates a new shared memory region with the given name. The region is created with read/write permissions for the owner.

static void closeRegion(
NativeHandle handle
)

Close a region handle.

Parameters:

  • handle Handle to close

Does not destroy the region if other processes have it open.


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