|
CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
|
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. | |
| DataMessage * | getCopyOfMessage (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. | |
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.
Definition at line 110 of file TemporalMemory.h.
| cmlabs::TemporalMemory::TemporalMemory | ( | MemoryController * | master | ) |
| master | Segment bookkeeping interface (borrowed, not owned). |
Definition at line 10 of file TemporalMemory.cpp.
Referenced by UnitTest().
| cmlabs::TemporalMemory::~TemporalMemory | ( | ) |
Definition at line 20 of file TemporalMemory.cpp.
References cmlabs::utils::CloseSharedMemorySegment().
| 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).
| slotCount | Message slots. |
| binCount | Number of block-size bins. |
| minBlockSize | Smallest bin block size (bytes). |
| maxBlockSize | Largest bin block size (bytes). |
| initSize | Initial segment bytes. |
| maxSize | Growth ceiling in bytes. |
| growSteps | Number of growth increments between initSize and maxSize. |
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().
| DataMessage * cmlabs::TemporalMemory::getCopyOfMessage | ( | uint64 | id | ) |
Retrieve a private copy of a stored message.
| id | Id from insertMessage() (any process). |
Definition at line 379 of file TemporalMemory.cpp.
References CHECKTEMPORALMEMORYSERIAL, and GETMSGNODE.
Referenced by UnitTest().
| bool cmlabs::TemporalMemory::getMemoryUsage | ( | uint64 & | alloc, |
| uint64 & | usage ) |
Report allocation/usage of the temporal segment.
| alloc | Receives allocated bytes. |
| usage | Receives used bytes. |
Definition at line 32 of file TemporalMemory.cpp.
References CHECKTEMPORALMEMORYSERIAL.
Referenced by UnitTest().
| bool cmlabs::TemporalMemory::insertMessage | ( | DataMessage * | msg, |
| uint64 & | id ) |
Copy msg into shared memory until its EOL passes.
| msg | Message to store; caller retains ownership. |
| id | Receives the packed node|serial|slot id. |
Definition at line 289 of file TemporalMemory.cpp.
References cmlabs::SlotEntryStruct::bin, cmlabs::BinHeaderStruct::bitFieldSize, BITOCCUPIED, cmlabs::BinHeaderStruct::blockCount, cmlabs::BinHeaderStruct::blocksInUse, cmlabs::BinHeaderStruct::blockSize, cmlabs::SlotEntryStruct::blockUsage, CHECKTEMPORALMEMORYSERIAL, cmlabs::DataMessage::data, cmlabs::SlotEntryStruct::eol, cmlabs::DataMessage::getEOL(), cmlabs::utils::GetFirstFreeBitLoc(), cmlabs::utils::GetFirstFreeBitLocN(), cmlabs::DataMessage::getSize(), cmlabs::GetTimeNow(), LOG_MEMORY, LogPrint, cmlabs::SlotEntryStruct::offset, cmlabs::SlotEntryStruct::serial, cmlabs::utils::SetBit(), cmlabs::utils::SetBitN(), SETMSGID, cmlabs::SlotEntryStruct::size, cmlabs::SlotEntryStruct::startBlock, cmlabs::BinHeaderStruct::usage, and cmlabs::SlotEntryStruct::usage.
Referenced by UnitTest().
| bool cmlabs::TemporalMemory::logUsage | ( | ) |
Write current usage statistics to the log.
Definition at line 742 of file TemporalMemory.cpp.
References cmlabs::BinHeaderStruct::blockCount, cmlabs::BinHeaderStruct::blocksInUse, cmlabs::BinHeaderStruct::blockSize, cmlabs::utils::BytifySize(), LOG_MEMORY, LogPrint, cmlabs::BinHeaderStruct::size, cmlabs::utils::StringFormat(), and cmlabs::BinHeaderStruct::usage.
| bool cmlabs::TemporalMemory::maintenance | ( | ) |
Expire slots whose EOL has passed and reclaim their blocks.
Called periodically by the master's management thread.
Definition at line 44 of file TemporalMemory.cpp.
References CHECKTEMPORALMEMORYSERIAL, and cmlabs::GetTimeNow().
Referenced by UnitTest().
| bool cmlabs::TemporalMemory::open | ( | ) |
Attach to the existing temporal segment (size/serial from the master).
Definition at line 209 of file TemporalMemory.cpp.
References cmlabs::TemporalMemoryStruct::cid, cmlabs::utils::CloseSharedMemorySegment(), cmlabs::utils::OpenSharedMemorySegment(), cmlabs::utils::StringFormat(), and TEMPORALMEMORYID.
| bool cmlabs::TemporalMemory::setNodeID | ( | uint16 | id | ) |
Set the node id used when composing message ids.
Definition at line 246 of file TemporalMemory.cpp.
|
static |
Self-test of the temporal store.
Definition at line 765 of file TemporalMemory.cpp.
References cmlabs::utils::BytifySize(), cmlabs::MasterMemory::create(), create(), cmlabs::unittest::detail(), cmlabs::unittest::fail(), getCopyOfMessage(), getMemoryUsage(), cmlabs::DataMessage::getSerial(), cmlabs::DataMessage::getSize(), cmlabs::GetTimeAge(), cmlabs::GetTimeNow(), insertMessage(), cmlabs::DataMessage::isValid(), maintenance(), cmlabs::unittest::metric(), cmlabs::unittest::progress(), cmlabs::utils::RandomValue(), cmlabs::DataMessage::setCreatedTime(), cmlabs::DataMessage::setData(), cmlabs::DataMessage::setSerial(), cmlabs::DataMessage::setTTL(), cmlabs::utils::Sleep(), and TemporalMemory().
Referenced by cmlabs::Register_TemporalMemory_Tests().