40 bool empty(
int treeId,
int stackId)
const;
90 void clear(
int spacetree);
120 bool holdsStack(
int treeId,
int stackId)
const;
134 if ( _data.count( key )==0 ) {
136 std::pair< StackKey, T* >(
147 return _data.count(
StackKey(treeId,stackId) )==0
148 or _data.at(
StackKey(treeId,stackId) )->empty();
154 return getForPush(
StackKey(treeId,stackId) );
168 return getForPop(
StackKey(treeId,stackId) );
176 return _data.at( key );
182 std::ostringstream msg;
183 msg <<
"(" << _data.size();
184 for (
auto& p: _data) {
186 << p.first.first <<
"x" << p.first.second <<
":" << p.second->size();
196 std::set<peano4::maps::StackKey> result;
197 for (
auto& p: _data) {
198 result.insert(p.first);
206 return holdsStack(
StackKey(treeId,stackId) );
212 return _data.count(key)==1;
218 for (
auto& p: _data) {
228 assertionMsg( _data.empty(),
"forgot to call clear()" );
235 for (
auto& p: _data) {
236 bool isCorrectOwner = p.first.first==localTreeId;
237 bool isEmptyTemporaryStack = isCorrectOwner
244 if ( isEmptyTemporaryStack ) {
245 logDebug(
"garbageCollection(...)",
"remove stack " << p.first.first <<
"x" << p.first.second <<
": " << p.second->toString() );
256 for (
auto& p: _data) {
258 p.first.first==localTreeId
260 logDebug(
"garbageCollection(...)",
"remove stack " << p.first.first <<
"x" << p.first.second <<
": " << p.second->toString() );
#define assertionMsg(expr, message)
#define logDebug(methodName, logMacroMessageStream)
T * getForPush(int treeId, int stackId)
Get the stack belonging to a tree.
void garbageCollection(int spacetree)
Invoke garbage collection.
std::set< StackKey > getKeys()
This one should be const, but I might need a semaphore, so I have to omit the const qualifier.
T * getForPop(int treeId, int stackId)
bool empty(int treeId, int stackId) const
void createStack(const StackKey &key)
This routine is not thread-safe, i.e.
void clear()
Clear the whole stack map.
std::map< StackKey, T * > _data
bool holdsStack(int treeId, int stackId) const
For debugging/assertions.
tarch::multicore::BooleanSemaphore _semaphore
Semaphore to protect _data.
static tarch::logging::Log _log
std::string toString() const
int getLocalTreeId(int treeId) const
static bool isStorageStackNumber(int number)
There are communication stacks and storage stacks.
static Node & getInstance()
This operation returns the singleton instance.
Create a lock around a boolean semaphore region.
std::pair< int, int > StackKey
Unique key identifying a stack.