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

Accessor for the temporal (dynamic) message store in shared memory. More...

#include <TemporalMemory.h>

Public Member Functions

 TemporalMemory (MemoryController *master)
 ~TemporalMemory ()
bool getMemoryUsage (uint64 &alloc, uint64 &usage)
 Report allocation/usage of the temporal segment.
bool open ()
 Attach to the existing temporal segment (size/serial from the master).
bool create (uint32 slotCount, uint16 binCount, uint32 minBlockSize, uint32 maxBlockSize, uint64 initSize, uint64 maxSize, uint32 growSteps=8)
 Create the temporal segment (master process only).
bool setNodeID (uint16 id)
 Set the node id used when composing message ids.
bool insertMessage (DataMessage *msg, uint64 &id)
 Copy msg into shared memory until its EOL passes.
DataMessagegetCopyOfMessage (uint64 id)
 Retrieve a private copy of a stored message.
bool logUsage ()
 Write current usage statistics to the log.
bool maintenance ()
 Expire slots whose EOL has passed and reclaim their blocks.

Static Public Member Functions

static bool UnitTest ()
 Self-test of the temporal store.

Detailed Description

Accessor for the temporal (dynamic) message store in shared memory.

One instance per process, created by MemoryManager. The master process calls create(); other processes call open(). All operations take the segment's named cross-process mutex and transparently re-attach when the segment was resized by another process (serial check). Backing memory is owned by the OS; master is borrowed from MemoryManager.

uint64 id;
temporalMemory->insertMessage(msg, id); // copy msg into shared memory
DataMessage* copy = temporalMemory->getCopyOfMessage(id); // any process; delete after use
The central Psyclone data container: a self-contained binary message with typed, named user entries.

Definition at line 110 of file TemporalMemory.h.

Constructor & Destructor Documentation

◆ TemporalMemory()

cmlabs::TemporalMemory::TemporalMemory ( MemoryController * master)
Parameters
masterSegment bookkeeping interface (borrowed, not owned).

Definition at line 10 of file TemporalMemory.cpp.

Referenced by UnitTest().

◆ ~TemporalMemory()

cmlabs::TemporalMemory::~TemporalMemory ( )

Definition at line 20 of file TemporalMemory.cpp.

References cmlabs::utils::CloseSharedMemorySegment().

Member Function Documentation

◆ create()

bool cmlabs::TemporalMemory::create ( uint32 slotCount,
uint16 binCount,
uint32 minBlockSize,
uint32 maxBlockSize,
uint64 initSize,
uint64 maxSize,
uint32 growSteps = 8 )

Create the temporal segment (master process only).

Parameters
slotCountMessage slots.
binCountNumber of block-size bins.
minBlockSizeSmallest bin block size (bytes).
maxBlockSizeLargest bin block size (bytes).
initSizeInitial segment bytes.
maxSizeGrowth ceiling in bytes.
growStepsNumber of growth increments between initSize and maxSize.
Returns
true on success.

Definition at line 53 of file TemporalMemory.cpp.

References cmlabs::BinHeaderStruct::bitFieldSize, cmlabs::utils::Calc32BitFieldSize(), cmlabs::utils::CreateSharedMemorySegment(), cmlabs::GetTimeNow(), cmlabs::utils::StringFormat(), TEMPORALMEMORYID, and cmlabs::BinHeaderStruct::usage.

Referenced by UnitTest().

◆ getCopyOfMessage()

DataMessage * cmlabs::TemporalMemory::getCopyOfMessage ( uint64 id)

Retrieve a private copy of a stored message.

Parameters
idId from insertMessage() (any process).
Returns
Caller-owned DataMessage (delete after use), or NULL if unknown/expired/recycled.

Definition at line 379 of file TemporalMemory.cpp.

References CHECKTEMPORALMEMORYSERIAL, and GETMSGNODE.

Referenced by UnitTest().

◆ getMemoryUsage()

bool cmlabs::TemporalMemory::getMemoryUsage ( uint64 & alloc,
uint64 & usage )

Report allocation/usage of the temporal segment.

Parameters
allocReceives allocated bytes.
usageReceives used bytes.
Returns
true on success.

Definition at line 32 of file TemporalMemory.cpp.

References CHECKTEMPORALMEMORYSERIAL.

Referenced by UnitTest().

◆ insertMessage()

◆ logUsage()

bool cmlabs::TemporalMemory::logUsage ( )

◆ maintenance()

bool cmlabs::TemporalMemory::maintenance ( )

Expire slots whose EOL has passed and reclaim their blocks.

Called periodically by the master's management thread.

Returns
true on success.

Definition at line 44 of file TemporalMemory.cpp.

References CHECKTEMPORALMEMORYSERIAL, and cmlabs::GetTimeNow().

Referenced by UnitTest().

◆ open()

bool cmlabs::TemporalMemory::open ( )

Attach to the existing temporal segment (size/serial from the master).

Returns
true on success.

Definition at line 209 of file TemporalMemory.cpp.

References cmlabs::TemporalMemoryStruct::cid, cmlabs::utils::CloseSharedMemorySegment(), cmlabs::utils::OpenSharedMemorySegment(), cmlabs::utils::StringFormat(), and TEMPORALMEMORYID.

◆ setNodeID()

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

Set the node id used when composing message ids.

Returns
true on success.

Definition at line 246 of file TemporalMemory.cpp.

◆ UnitTest()


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