|
CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
|
Static algorithms shared by all bitfield-indexed maps in the data-maps segment. More...
#include <DataMapsMemory.h>
Static Public Member Functions | |
| static T * | CreateEntry (char *data, ID id, const char *name) |
| Reserve entry id with name (status 1). | |
| static T * | CreateFirstFreeEntry (char *data, ID &id, const char *name) |
| Reserve the first free id. | |
| static T * | GetEntry (char *data, ID id) |
| Fetch the confirmed entry at index id. | |
| static bool | ConfirmEntry (char *data, ID id) |
| Mark entry ready (status 2). | |
| static bool | CancelEntry (char *data, ID id) |
| Roll back a reserved entry. | |
| static bool | DeleteEntry (char *data, ID id) |
| Free the entry and its bit. | |
| static uint64 | GetEntryTime (char *data, ID id) |
| Creation timestamp of entry id. | |
| static bool | GetEntryName (char *data, ID id, char *name, uint32 maxSize) |
| Copy the entry name. | |
| static ID | GetEntryID (char *data, const char *name, bool force=false) |
| Case-insensitive reverse lookup: find the id registered under name. | |
| static uint8 | LookupEntryID (char *data, const char *name, ID &id) |
| Case-insensitive lookup returning the entry's sync status rather than filtering by it. | |
| static uint32 | GetCount (char *data) |
| Number of entries currently registered in the map (from the header's count field). | |
| static uint32 | GetUsage (char *data) |
| Approximate bytes in use by entry payloads (count * sizeof(T)); excludes the header and bitfield. | |
| static std::string | PrintAllEntries (char *data) |
| Human-readable text dump of all occupied entries, one per line ("id = name (time)"; unconfirmed entries prefixed with '*'). | |
| static std::string | PrintAllEntriesHTML (char *data) |
| Dump all occupied entries as HTML table rows (no surrounding table element); used by the node's monitoring pages. | |
| static std::string | ToXML (char *data) |
| Serialize all occupied entries as XML by delegating to each entry's toXML(), wrapped in the outer element named by T::GetOuterXMLName() with a count attribute. | |
| static bool | WriteAllEntriesToMsg (char *data, DataMessage *msg) |
| Serialize all entries into msg. | |
| static bool | WriteAllIDsToMsg (const char *arrayname, char *data, DataMessage *msg) |
| Write just names into msg under arrayname. | |
| static uint32 | GetCount (char *data) |
| static T * | CreateEntry (char *data, ID id, const char *name) |
| Reserve entry id. | |
| static T * | GetEntry (char *data, ID id) |
| static bool | DeleteEntry (char *data, ID id) |
| Free the entry. | |
| static uint64 | GetEntryTime (char *data, ID id) |
| static const char * | GetEntryName (char *data, ID id, uint32 &size) |
| static ID | GetEntryID (char *data, const char *name) |
Static algorithms shared by all bitfield-indexed maps in the data-maps segment.
Legacy generic map algorithms (3-parameter variant with unused KEY type).
| T | Entry struct (TypeMapEntry, TagMapEntry, ...), |
| ID | its id type. All functions take the raw mapped map address (data = GenericMapHeader*); callers must hold the segment mutex. Returned entry pointers point into shared memory and are only valid while the segment mapping and lock are held. Implemented in MemoryMaps.tpl.h. |
| T | Entry type. |
| ID | Id type. |
| KEY | Unused key type (historical). Superseded by the 2-parameter GenericMemoryMap in DataMapsMemory.h; bodies live in MemoryMaps.tpl.h. Entry pointers returned point into shared memory. |
Definition at line 379 of file DataMapsMemory.h.
|
static |
Roll back a reserved entry.
Roll back a reserved-but-unconfirmed entry (status 1 or less), clearing its status and timestamp so the slot can be reused.
Definition at line 265 of file MemoryMaps.tpl.h.
References cmlabs::GenericMapHeader::bitFieldSize, and cmlabs::GenericMapHeader::size.
Referenced by cmlabs::DataMapsMemory::cancelContextLevelID(), cmlabs::DataMapsMemory::cancelCrankID(), cmlabs::DataMapsMemory::cancelTagID(), and cmlabs::DataMapsMemory::cancelTypeLevelID().
|
static |
Mark entry ready (status 2).
Commit a reserved entry: promote status from 1 (assigned) to 2 (ready).
Second phase of the two-phase id allocation used for cluster-wide agreement: once confirmed, the entry becomes visible to GetEntry()/GetEntryID() in every process.
Definition at line 237 of file MemoryMaps.tpl.h.
References cmlabs::GenericMapHeader::bitFieldSize, and cmlabs::GenericMapHeader::size.
Referenced by cmlabs::DataMapsMemory::confirmContextLevelID(), cmlabs::DataMapsMemory::confirmCrankID(), cmlabs::DataMapsMemory::confirmTagID(), and cmlabs::DataMapsMemory::confirmTypeLevelID().
|
static |
Reserve entry id with name (status 1).
Reserve the map entry at index id and stamp it with name.
Sets the occupancy bit, initialises the entry (status 1 = assigned/unconfirmed, creation time = now) and increments the map's count. If the slot is already occupied by an entry with the same name, that existing entry is returned instead (idempotent re-registration); a name clash on an occupied slot returns NULL.
| data | Raw mapped map region (GenericMapHeader at offset 0). |
| id | Fixed index to reserve; must be less than GenericMapHeader::maxID. |
| name | Entry name (truncated to MAXKEYNAMELEN); may be NULL to skip naming. |
Definition at line 46 of file MemoryMaps.tpl.h.
References cmlabs::GenericMapHeader::bitFieldSize, BITOCCUPIED, cmlabs::GenericMapHeader::count, cmlabs::utils::GetBit(), GetEntry(), cmlabs::GetTimeNow(), cmlabs::GenericMapHeader::maxID, MAXKEYNAMELEN, cmlabs::utils::SetBit(), cmlabs::GenericMapHeader::size, and cmlabs::utils::strcpyavail().
Referenced by cmlabs::DataMapsMemory::createNewContextLevel(), cmlabs::DataMapsMemory::createNewCrank(), cmlabs::DataMapsMemory::createNewTag(), and cmlabs::DataMapsMemory::createNewTypeLevel().
|
static |
Reserve entry id.
|
static |
Reserve the first free id.
Reserve the lowest free index in the map and stamp it with name.
| data | Mapped map region. |
| id | Receives it. |
| name | Entry name. |
Same two-phase semantics as CreateEntry(), but the index is chosen by scanning the occupancy bitfield for the first free bit instead of being supplied by the caller. Used when the id value carries no meaning and only uniqueness matters.
Operates on the raw mapped map region passed in data. Receives the allocated index in id; name is the entry name (may be NULL).
Definition at line 117 of file MemoryMaps.tpl.h.
References cmlabs::GenericMapHeader::bitFieldSize, BITOCCUPIED, cmlabs::GenericMapHeader::count, cmlabs::utils::GetFirstFreeBitLoc(), cmlabs::GetTimeNow(), cmlabs::GenericMapHeader::maxID, MAXKEYNAMELEN, cmlabs::utils::SetBit(), cmlabs::GenericMapHeader::size, and cmlabs::utils::strcpyavail().
Referenced by cmlabs::DataMapsMemory::createNewRequest().
|
static |
Free the entry and its bit.
Free the entry at index id.
Verifies the slot actually holds entry id (matching id field and non-zero time) before zeroing its timestamp, decrementing the count and clearing the occupancy bit. The entry bytes themselves are not wiped; the slot may be recycled by a later CreateEntry()/CreateFirstFreeEntry().
Definition at line 171 of file MemoryMaps.tpl.h.
References cmlabs::GenericMapHeader::bitFieldSize, BITFREE, cmlabs::GenericMapHeader::count, cmlabs::utils::SetBit(), and cmlabs::GenericMapHeader::size.
Referenced by cmlabs::MemoryMaps::DeleteContextLevel(), cmlabs::MemoryMaps::DeleteContextLevel(), cmlabs::DataMapsMemory::deleteContextLevel(), cmlabs::DataMapsMemory::deleteContextLevel(), cmlabs::MemoryMaps::DeleteCrank(), cmlabs::MemoryMaps::DeleteCrank(), cmlabs::DataMapsMemory::deleteCrank(), cmlabs::DataMapsMemory::deleteCrank(), cmlabs::DataMapsMemory::deleteRequest(), cmlabs::DataMapsMemory::deleteTag(), cmlabs::DataMapsMemory::deleteTag(), cmlabs::MemoryMaps::DeleteTopic(), cmlabs::MemoryMaps::DeleteTopic(), cmlabs::MemoryMaps::DeleteTypeLevel(), cmlabs::MemoryMaps::DeleteTypeLevel(), cmlabs::DataMapsMemory::deleteTypeLevel(), and cmlabs::DataMapsMemory::deleteTypeLevel().
|
static |
Free the entry.
|
static |
Number of entries currently registered in the map (from the header's count field).
Definition at line 480 of file MemoryMaps.tpl.h.
References cmlabs::GenericMapHeader::count.
Referenced by cmlabs::DataMapsMemory::getRequestCount().
|
static |
|
static |
Fetch the confirmed entry at index id.
Only returns entries that are fully committed (status greater than 1, i.e. past ConfirmEntry()); entries still in the reserved/unconfirmed state are treated as absent. This is what makes the two-phase create-then-confirm protocol race-safe for readers.
Definition at line 213 of file MemoryMaps.tpl.h.
References cmlabs::GenericMapHeader::bitFieldSize, and cmlabs::GenericMapHeader::size.
Referenced by CreateEntry(), cmlabs::DataMapsMemory::createNewTypeLevel(), cmlabs::DataMapsMemory::getCrankCompID(), cmlabs::DataMapsMemory::getCrankFunction(), cmlabs::DataMapsMemory::getCrankLanguage(), cmlabs::DataMapsMemory::getCrankLibraryFilename(), cmlabs::DataMapsMemory::getCrankScript(), GetEntryName(), GetEntryTime(), cmlabs::DataMapsMemory::getRequestInfo(), cmlabs::DataMapsMemory::getRequestStatus(), cmlabs::DataMapsMemory::setRequestStatus(), cmlabs::DataMapsMemory::setRequestStatus(), and cmlabs::DataMapsMemory::waitForRequestReply().
|
static |
|
static |
|
static |
Case-insensitive reverse lookup: find the id registered under name.
Linearly scans every entry slot (freed slots keep their bytes but are filtered by status), so cost is O(maxID); hold the segment mutex while calling.
| data | Raw mapped map region. |
| name | Name to look up (case-insensitive). |
| force | When true, also match reserved-but-unconfirmed entries (status 1); used during id negotiation. |
Definition at line 311 of file MemoryMaps.tpl.h.
References cmlabs::GenericMapHeader::bitFieldSize, cmlabs::GenericMapHeader::size, and stricmp.
Referenced by cmlabs::DataMapsMemory::createNewContextLevel(), cmlabs::DataMapsMemory::createNewCrank(), cmlabs::DataMapsMemory::createNewTag(), cmlabs::DataMapsMemory::createNewTypeLevel(), cmlabs::MemoryMaps::DeleteContextLevel(), cmlabs::DataMapsMemory::deleteContextLevel(), cmlabs::MemoryMaps::DeleteCrank(), cmlabs::DataMapsMemory::deleteCrank(), cmlabs::DataMapsMemory::deleteTag(), cmlabs::MemoryMaps::DeleteTopic(), cmlabs::MemoryMaps::DeleteTypeLevel(), cmlabs::DataMapsMemory::deleteTypeLevel(), cmlabs::MemoryMaps::GetContextLevelID(), cmlabs::DataMapsMemory::getContextLevelID(), cmlabs::MemoryMaps::GetCrankID(), cmlabs::DataMapsMemory::getCrankID(), cmlabs::DataMapsMemory::getTagID(), cmlabs::MemoryMaps::GetTopicID(), cmlabs::MemoryMaps::GetTypeLevelID(), and cmlabs::DataMapsMemory::getTypeLevelID().
|
static |
Copy the entry name.
Copy the name of confirmed entry id into the caller's buffer.
| data | Raw mapped map region. |
| id | Entry index. |
| name | Destination buffer (caller-owned). |
| maxSize | Buffer capacity in bytes. |
Definition at line 292 of file MemoryMaps.tpl.h.
References GetEntry(), and cmlabs::utils::strcpyavail().
Referenced by cmlabs::MemoryMaps::GetContextLevelName(), cmlabs::DataMapsMemory::getContextLevelName(), cmlabs::MemoryMaps::GetCrankName(), cmlabs::DataMapsMemory::getCrankName(), cmlabs::DataMapsMemory::getTagName(), cmlabs::MemoryMaps::GetTopicName(), cmlabs::MemoryMaps::GetTypeLevelName(), and cmlabs::DataMapsMemory::getTypeLevelName().
|
static |
|
static |
Creation timestamp of entry id.
Definition at line 196 of file MemoryMaps.tpl.h.
References GetEntry().
Referenced by cmlabs::DataMapsMemory::getContextLevelCreateTime(), cmlabs::DataMapsMemory::getCrankCreateTime(), cmlabs::DataMapsMemory::getTagCreateTime(), and cmlabs::DataMapsMemory::getTypeLevelCreateTime().
|
static |
|
static |
Approximate bytes in use by entry payloads (count * sizeof(T)); excludes the header and bitfield.
Definition at line 489 of file MemoryMaps.tpl.h.
|
static |
Case-insensitive lookup returning the entry's sync status rather than filtering by it.
Unlike GetEntryID(), this reports reserved entries too, letting callers distinguish "absent" from "being negotiated" from "ready".
| data | Raw mapped map region. |
| name | Name to look up (case-insensitive). |
| id | Receives the matching entry's id when found. |
Definition at line 339 of file MemoryMaps.tpl.h.
References cmlabs::GenericMapHeader::bitFieldSize, cmlabs::GenericMapHeader::size, and stricmp.
Referenced by cmlabs::DataMapsMemory::lookupContextLevelID(), cmlabs::DataMapsMemory::lookupCrankID(), cmlabs::DataMapsMemory::lookupTagID(), and cmlabs::DataMapsMemory::lookupTypeLevelID().
|
static |
Human-readable text dump of all occupied entries, one per line ("id = name (time)"; unconfirmed entries prefixed with '*').
Diagnostic use.
Definition at line 361 of file MemoryMaps.tpl.h.
References cmlabs::GenericMapHeader::bitFieldSize, cmlabs::PrintTimeString(), cmlabs::GenericMapHeader::size, and cmlabs::utils::StringFormat().
Referenced by cmlabs::DataMapsMemory::printAllContexts(), and cmlabs::DataMapsMemory::printAllTypes().
|
static |
Dump all occupied entries as HTML table rows (no surrounding table element); used by the node's monitoring pages.
Definition at line 384 of file MemoryMaps.tpl.h.
References cmlabs::GenericMapHeader::bitFieldSize, cmlabs::PrintTimeString(), cmlabs::GenericMapHeader::size, and cmlabs::utils::StringFormat().
Referenced by cmlabs::DataMapsMemory::printFriendlyHTML().
|
static |
Serialize all occupied entries as XML by delegating to each entry's toXML(), wrapped in the outer element named by T::GetOuterXMLName() with a count attribute.
Definition at line 407 of file MemoryMaps.tpl.h.
References cmlabs::GenericMapHeader::bitFieldSize, cmlabs::GenericMapHeader::size, and cmlabs::utils::StringFormat().
Referenced by cmlabs::DataMapsMemory::toXML().
|
static |
Serialize all entries into msg.
Serialize all occupied entries (full fields) into msg via each entry's writeToMsg(), indexed 0..n-1.
Used to ship whole maps to remote nodes for syncing.
Definition at line 458 of file MemoryMaps.tpl.h.
References cmlabs::GenericMapHeader::bitFieldSize, and cmlabs::GenericMapHeader::size.
Referenced by cmlabs::DataMapsMemory::writeContextLevelsToMsg(), cmlabs::DataMapsMemory::writeCranksToMsg(), cmlabs::DataMapsMemory::writeTagsToMsg(), and cmlabs::DataMapsMemory::writeTypeLevelsToMsg().
|
static |
Write just names into msg under arrayname.
Write just the names of all occupied entries into msg as array arrayname, via each entry's writeIDToMsg().
Used for lightweight cluster synchronisation.
Definition at line 434 of file MemoryMaps.tpl.h.
References cmlabs::GenericMapHeader::bitFieldSize, and cmlabs::GenericMapHeader::size.
Referenced by cmlabs::DataMapsMemory::writeIDsToMsg().