CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
cmlabs::MasterMemory Class Reference

Handle to the node's master shared-memory segment (MemoryMasterStruct). More...

#include <MemoryManager.h>

Inheritance diagram for cmlabs::MasterMemory:
[legend]
Collaboration diagram for cmlabs::MasterMemory:
[legend]

Public Member Functions

 MasterMemory ()
 ~MasterMemory ()
bool create (uint16 port)
 Create the master segment for the node instance listening on port.
bool open (uint16 port)
 Attach to an existing master segment created by another process.
uint16 getNodeID ()
bool setNodeID (uint16 id)
 Set the cluster-wide node id.
uint64 getCreatedTime ()
bool setID (uint16 id)
 MemoryController interface: set the node id.
uint16 getID ()
 MemoryController interface:
Segment resize serials

Each subsystem segment has a serial that is incremented whenever the segment is re-created (resized).

Attached processes compare a cached serial to detect that their mapping is stale and must be re-opened.

uint32 getDynamicShmemSerial ()
uint32 getProcessShmemSerial ()
uint32 getComponentShmemSerial ()
uint32 getDataMapsShmemSerial ()
uint32 incrementDynamicShmemSerial ()
 Bump the dynamic segment serial after resize.
uint32 incrementProcessShmemSerial ()
 Bump the process segment serial after resize.
uint32 incrementComponentShmemSerial ()
 Bump the component segment serial after resize.
uint32 incrementDataMapsShmemSerial ()
 Bump the data-maps segment serial after resize.
Segment sizes

Current byte sizes of the four subsystem segments, kept here so any process can map the right amount of memory when (re-)attaching.

uint64 getDynamicShmemSize ()
uint64 getProcessShmemSize ()
uint64 getComponentShmemSize ()
uint64 getDataMapsShmemSize ()
bool setDynamicShmemSize (uint64 size)
 Record a new dynamic segment size.
bool setProcessShmemSize (uint64 size)
 Record a new process segment size.
bool setComponentShmemSize (uint64 size)
 Record a new component segment size.
bool setDataMapsShmemSize (uint64 size)
 Record a new data-maps segment size.
Public Member Functions inherited from cmlabs::MemoryController
 MemoryController ()
virtual ~MemoryController ()

Public Attributes

uint16 port
 Node port this master segment belongs to (names all related segments).

Friends

class MemoryManager

Detailed Description

Handle to the node's master shared-memory segment (MemoryMasterStruct).

Implements the MemoryController interface used by the subsystem memories (TemporalMemory, ProcessMemory, ComponentMemory, DataMapsMemory) to read/bump the resize serials and sizes of their segments. Exactly one process per node calls create(); all others attach via open(). All getters/setters operate directly on the mapped struct under a named cross-process mutex; calls may block briefly on that mutex but never for long. The mapped memory is owned by the OS, not this object.

Definition at line 324 of file MemoryManager.h.

Constructor & Destructor Documentation

◆ MasterMemory()

cmlabs::MasterMemory::MasterMemory ( )

Definition at line 94 of file MemoryManager.cpp.

References port.

◆ ~MasterMemory()

cmlabs::MasterMemory::~MasterMemory ( )

Member Function Documentation

◆ create()

bool cmlabs::MasterMemory::create ( uint16 port)

Create the master segment for the node instance listening on port.

Parameters
portNode port; used to derive the segment's global name.
Returns
true on success.

Definition at line 111 of file MemoryManager.cpp.

References cmlabs::utils::CreateSharedMemorySegment(), cmlabs::GetTimeNow(), port, PSYCLONEMASTERID, and cmlabs::utils::StringFormat().

Referenced by cmlabs::TemporalMemory::UnitTest().

◆ getComponentShmemSerial()

uint32 cmlabs::MasterMemory::getComponentShmemSerial ( )
Returns
Current serial of the component segment.

Definition at line 199 of file MemoryManager.cpp.

◆ getComponentShmemSize()

uint64 cmlabs::MasterMemory::getComponentShmemSize ( )
Returns
Byte size of the component segment.

Definition at line 266 of file MemoryManager.cpp.

◆ getCreatedTime()

uint64 cmlabs::MasterMemory::getCreatedTime ( )
Returns
Creation timestamp (µs) of the master segment.

Definition at line 167 of file MemoryManager.cpp.

◆ getDataMapsShmemSerial()

uint32 cmlabs::MasterMemory::getDataMapsShmemSerial ( )
Returns
Current serial of the data-maps segment.

Definition at line 207 of file MemoryManager.cpp.

◆ getDataMapsShmemSize()

uint64 cmlabs::MasterMemory::getDataMapsShmemSize ( )
Returns
Byte size of the data-maps segment.

Definition at line 274 of file MemoryManager.cpp.

◆ getDynamicShmemSerial()

uint32 cmlabs::MasterMemory::getDynamicShmemSerial ( )
virtual
Returns
Current serial of the dynamic (temporal) segment.

Implements cmlabs::MemoryController.

Definition at line 183 of file MemoryManager.cpp.

◆ getDynamicShmemSize()

uint64 cmlabs::MasterMemory::getDynamicShmemSize ( )
virtual
Returns
Byte size of the dynamic (temporal) segment.

Implements cmlabs::MemoryController.

Definition at line 250 of file MemoryManager.cpp.

◆ getID()

uint16 cmlabs::MasterMemory::getID ( )
virtual

MemoryController interface:

Returns
the node id.

Implements cmlabs::MemoryController.

Definition at line 319 of file MemoryManager.cpp.

References port.

◆ getNodeID()

uint16 cmlabs::MasterMemory::getNodeID ( )
Returns
The cluster-wide node id stored in the master segment.

Definition at line 159 of file MemoryManager.cpp.

◆ getProcessShmemSerial()

uint32 cmlabs::MasterMemory::getProcessShmemSerial ( )
Returns
Current serial of the process segment.

Definition at line 191 of file MemoryManager.cpp.

◆ getProcessShmemSize()

uint64 cmlabs::MasterMemory::getProcessShmemSize ( )
Returns
Byte size of the process segment.

Definition at line 258 of file MemoryManager.cpp.

◆ incrementComponentShmemSerial()

uint32 cmlabs::MasterMemory::incrementComponentShmemSerial ( )

Bump the component segment serial after resize.

Returns
New serial.

Definition at line 233 of file MemoryManager.cpp.

◆ incrementDataMapsShmemSerial()

uint32 cmlabs::MasterMemory::incrementDataMapsShmemSerial ( )

Bump the data-maps segment serial after resize.

Returns
New serial.

Definition at line 241 of file MemoryManager.cpp.

◆ incrementDynamicShmemSerial()

uint32 cmlabs::MasterMemory::incrementDynamicShmemSerial ( )
virtual

Bump the dynamic segment serial after resize.

Returns
New serial.

Implements cmlabs::MemoryController.

Definition at line 217 of file MemoryManager.cpp.

◆ incrementProcessShmemSerial()

uint32 cmlabs::MasterMemory::incrementProcessShmemSerial ( )

Bump the process segment serial after resize.

Returns
New serial.

Definition at line 225 of file MemoryManager.cpp.

◆ open()

bool cmlabs::MasterMemory::open ( uint16 port)

Attach to an existing master segment created by another process.

Parameters
portNode port identifying the segment.
Returns
true if found and mapped.

Definition at line 138 of file MemoryManager.cpp.

References cmlabs::utils::CloseSharedMemorySegment(), cmlabs::utils::OpenSharedMemorySegment(), port, PSYCLONEMASTERID, and cmlabs::utils::StringFormat().

◆ setComponentShmemSize()

bool cmlabs::MasterMemory::setComponentShmemSize ( uint64 size)

Record a new component segment size.

Parameters
sizeBytes.
Returns
true on success.

Definition at line 298 of file MemoryManager.cpp.

◆ setDataMapsShmemSize()

bool cmlabs::MasterMemory::setDataMapsShmemSize ( uint64 size)

Record a new data-maps segment size.

Parameters
sizeBytes.
Returns
true on success.

Definition at line 306 of file MemoryManager.cpp.

◆ setDynamicShmemSize()

bool cmlabs::MasterMemory::setDynamicShmemSize ( uint64 size)
virtual

Record a new dynamic segment size.

Parameters
sizeBytes.
Returns
true on success.

Implements cmlabs::MemoryController.

Definition at line 282 of file MemoryManager.cpp.

◆ setID()

bool cmlabs::MasterMemory::setID ( uint16 id)
virtual

MemoryController interface: set the node id.

Parameters
idNew id.
Returns
true on success.

Implements cmlabs::MemoryController.

Definition at line 314 of file MemoryManager.cpp.

References port.

◆ setNodeID()

bool cmlabs::MasterMemory::setNodeID ( uint16 id)

Set the cluster-wide node id.

Parameters
idNew node id.
Returns
true on success.

Definition at line 175 of file MemoryManager.cpp.

◆ setProcessShmemSize()

bool cmlabs::MasterMemory::setProcessShmemSize ( uint64 size)

Record a new process segment size.

Parameters
sizeBytes.
Returns
true on success.

Definition at line 290 of file MemoryManager.cpp.

◆ MemoryManager

friend class MemoryManager
friend

Definition at line 325 of file MemoryManager.h.

References MemoryManager, and port.

Referenced by MemoryManager.

Member Data Documentation

◆ port

uint16 cmlabs::MasterMemory::port

Node port this master segment belongs to (names all related segments).

Definition at line 375 of file MemoryManager.h.

Referenced by create(), getID(), MasterMemory(), MemoryManager, open(), and setID().


The documentation for this class was generated from the following files: