summaryrefslogtreecommitdiff
path: root/controller
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2017-04-26 12:17:43 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2017-04-26 12:17:43 -0700
commite8ab6adf8902dce98b4721e2f4a5382e54bcbcbc (patch)
tree83265f860d94999bbb7d4eb765b779d8a7ab75e5 /controller
parent7c184cf9919fb9d01b8279397e7b20fa756dc981 (diff)
downloadinfinitytier-e8ab6adf8902dce98b4721e2f4a5382e54bcbcbc.tar.gz
infinitytier-e8ab6adf8902dce98b4721e2f4a5382e54bcbcbc.zip
Deadlock fix.
Diffstat (limited to 'controller')
-rw-r--r--controller/JSONDB.cpp11
-rw-r--r--controller/JSONDB.hpp19
2 files changed, 16 insertions, 14 deletions
diff --git a/controller/JSONDB.cpp b/controller/JSONDB.cpp
index 9b0dd836..a2fe7f2a 100644
--- a/controller/JSONDB.cpp
+++ b/controller/JSONDB.cpp
@@ -60,6 +60,15 @@ JSONDB::JSONDB(const std::string &basePath) :
for(std::unordered_map<uint64_t,_NW>::iterator n(_networks.begin());n!=_networks.end();++n)
_recomputeSummaryInfo(n->first);
+ for(;;) {
+ _summaryThread_m.lock();
+ if (_summaryThreadToDo.empty()) {
+ _summaryThread_m.unlock();
+ break;
+ }
+ _summaryThread_m.unlock();
+ Thread::sleep(50);
+ }
}
JSONDB::~JSONDB()
@@ -107,7 +116,7 @@ void JSONDB::saveNetwork(const uint64_t networkId,const nlohmann::json &networkC
Mutex::Lock _l(_networks_m);
_networks[networkId].config = networkConfig;
}
- //_recomputeSummaryInfo(networkId);
+ _recomputeSummaryInfo(networkId);
}
void JSONDB::saveNetworkMember(const uint64_t networkId,const uint64_t nodeId,const nlohmann::json &memberConfig)
diff --git a/controller/JSONDB.hpp b/controller/JSONDB.hpp
index 55ead4ea..f89ff6c9 100644
--- a/controller/JSONDB.hpp
+++ b/controller/JSONDB.hpp
@@ -82,19 +82,12 @@ public:
inline bool getNetworkSummaryInfo(const uint64_t networkId,NetworkSummaryInfo &ns) const
{
- for(;;) {
- {
- Mutex::Lock _l(_networks_m);
- std::unordered_map<uint64_t,_NW>::const_iterator i(_networks.find(networkId));
- if (i == _networks.end())
- return false;
- if (i->second.summaryInfoLastComputed) {
- ns = i->second.summaryInfo;
- return true;
- }
- }
- Thread::sleep(100); // wait for this to be done the first time, which happens when we start
- }
+ Mutex::Lock _l(_networks_m);
+ std::unordered_map<uint64_t,_NW>::const_iterator i(_networks.find(networkId));
+ if (i == _networks.end())
+ return false;
+ ns = i->second.summaryInfo;
+ return true;
}
/**