Page MenuHomePhorge

SystemImpl.cpp
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

SystemImpl.cpp

/*******************************************************************************
*
* File: SystemImpl.cpp
*
* Contents: Implementation of the SystemImpl class.
*
* Copyright 2017
*
* Author: David Juhasz (david.juhasz@tuwien.ac.at)
*
******************************************************************************/
#include "SystemImpl.hpp"
#include "rosa/core/Unit.h"
namespace rosa {
SystemImpl::SystemImpl(const std::string &Name) noexcept : SystemBase(Name) {}
SystemImpl::~SystemImpl(void) {
if (!empty()) {
ROSA_CRITICAL("Trying to destroy a non-empty System (" + Name + ")");
} else {
markCleaned();
}
}
void SystemImpl::registerUnit(Unit &U) noexcept {
// Obtain exclusive access and instert the Unit.
std::lock_guard<std::mutex> L(RegisterMutex);
auto R = Units.insert(&U);
if (!R.second) {
ROSA_CRITICAL("Could not register Unit");
}
}
void SystemImpl::destroyUnit(Unit &U) noexcept {
ASSERT(isUnitRegistered(U));
LOG_TRACE("Destroying Unit (" + U.FullName + ")");
// Scope protected container access.
{
// Obtain exclusive access and remove the Unit.
std::lock_guard<std::mutex> L(RegisterMutex);
auto R = Units.erase(&U);
// NOTE: This case is catched by assertion when that is enabled.
if (!R) {
ROSA_CRITICAL("Trying to remove unregistered Unit");
}
}
delete &U;
}
bool SystemImpl::isUnitRegistered(const Unit &U) const noexcept {
// NOTE: Casting away constness is safe here.
return Units.find(const_cast<Unit *>(&U)) != Units.cend();
}
size_t SystemImpl::numberOfLiveUnits(void) const noexcept {
return Units.size();
}
bool SystemImpl::empty(void) const noexcept { return Units.empty(); }
} // End namespace rosa

File Metadata

Mime Type
text/x-c++
Expires
Sun, Mar 1, 6:53 PM (12 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
280938
Default Alt Text
SystemImpl.cpp (1 KB)

Event Timeline