Skip to content

Commit

Permalink
Don't use C++ 17 features/syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Jan 22, 2025
1 parent 080fced commit e00f89e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
20 changes: 11 additions & 9 deletions lib/base/dependencygraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ DependencyGraph::DependencyMap DependencyGraph::m_Dependencies;
void DependencyGraph::AddDependency(ConfigObject* child, ConfigObject* parent)
{
std::unique_lock<std::mutex> lock(m_Mutex);
if (auto [it, inserted] = m_Dependencies.insert(Edge(parent, child)); !inserted) {
m_Dependencies.modify(it, [](Edge& e) { e.count++; });
auto pair = m_Dependencies.insert(Edge(parent, child));
if (!pair.second) {
m_Dependencies.modify(pair.first, [](Edge& e) { e.count++; });
}
}

void DependencyGraph::RemoveDependency(ConfigObject* child, ConfigObject* parent)
{
std::unique_lock<std::mutex> lock(m_Mutex);

if (auto it(m_Dependencies.find(Edge(parent, child))); it != m_Dependencies.end()) {
auto it(m_Dependencies.find(Edge(parent, child)));
if (it != m_Dependencies.end()) {
if (it->count > 1) {
// Remove a duplicate edge from child to node, i.e. decrement the corresponding counter.
m_Dependencies.modify(it, [](Edge& e) { e.count--; });
Expand All @@ -44,9 +46,9 @@ std::vector<ConfigObject::Ptr> DependencyGraph::GetParents(const ConfigObject::P

std::unique_lock<std::mutex> lock(m_Mutex);
auto [begin, end] = m_Dependencies.get<2>().equal_range(child.get());
std::transform(begin, end, std::back_inserter(objects), [](const Edge& edge) {
return edge.parent;
});
for (auto it(begin); it != end; ++it) {
objects.emplace_back(it->parent);
}

return objects;
}
Expand All @@ -64,9 +66,9 @@ std::vector<ConfigObject::Ptr> DependencyGraph::GetChildren(const ConfigObject::

std::unique_lock<std::mutex> lock(m_Mutex);
auto [begin, end] = m_Dependencies.get<1>().equal_range(parent.get());
std::transform(begin, end, std::back_inserter(objects), [](const Edge& edge) {
return edge.child;
});
for (auto it(begin); it != end; ++it) {
objects.emplace_back(it->child);
}

return objects;
}
3 changes: 2 additions & 1 deletion lib/remote/apilistener-configsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,8 @@ void ApiListener::SendRuntimeConfigObjects(const JsonRpcConnection::Ptr& aclient

std::unordered_set<ConfigObject*> syncedObjects;
for (const Type::Ptr& type : Type::GetAllTypes()) {
if (auto *ctype = dynamic_cast<ConfigType *>(type.get())) {
auto *ctype = dynamic_cast<ConfigType *>(type.get());
if (ctype) {
for (const auto& object : ctype->GetObjects()) {
// All objects must be synced sorted by their dependency graph.
// Otherwise, downtimes/comments etc. might get synced before their respective Checkables, which will
Expand Down

0 comments on commit e00f89e

Please sign in to comment.