diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2017-08-07 14:13:08 -0700 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2017-08-07 14:13:08 -0700 |
commit | 7e6598e9ca28da7047176907f5cacbc53ab60afe (patch) | |
tree | b8a30a7a172674cb2db345705699fe9f45ccff41 /node/Node.cpp | |
parent | e4823381c66917746abb0f8d13281d61daa2f112 (diff) | |
download | infinitytier-7e6598e9ca28da7047176907f5cacbc53ab60afe.tar.gz infinitytier-7e6598e9ca28da7047176907f5cacbc53ab60afe.zip |
Possible deadlock fix.
Diffstat (limited to 'node/Node.cpp')
-rw-r--r-- | node/Node.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/node/Node.cpp b/node/Node.cpp index f3339068..0df3a97a 100644 --- a/node/Node.cpp +++ b/node/Node.cpp @@ -250,20 +250,23 @@ ZT_ResultCode Node::processBackgroundTasks(void *tptr,uint64_t now,volatile uint _lastPingCheck = now; // Get networks that need config without leaving mutex locked - std::vector< SharedPtr<Network> > needConfig; { - Mutex::Lock _l(_networks_m); - Hashtable< uint64_t,SharedPtr<Network> >::Iterator i(_networks); - uint64_t *k = (uint64_t *)0; - SharedPtr<Network> *v = (SharedPtr<Network> *)0; - while (i.next(k,v)) { - if (((now - (*v)->lastConfigUpdate()) >= ZT_NETWORK_AUTOCONF_DELAY)||(!(*v)->hasConfig())) - needConfig.push_back(*v); - (*v)->sendUpdatesToMembers(tptr); + std::vector< std::pair< SharedPtr<Network>,bool > > nwl; + { + Mutex::Lock _l(_networks_m); + nwl.reserve(_networks.size()+1); + Hashtable< uint64_t,SharedPtr<Network> >::Iterator i(_networks); + uint64_t *k = (uint64_t *)0; + SharedPtr<Network> *v = (SharedPtr<Network> *)0; + while (i.next(k,v)) + nwl.push_back( std::pair< SharedPtr<Network>,bool >(*v,(((now - (*v)->lastConfigUpdate()) >= ZT_NETWORK_AUTOCONF_DELAY)||(!(*v)->hasConfig()))) ); + } + for(std::vector< std::pair< SharedPtr<Network>,bool > >::const_iterator n(nwl.begin());n!=nwl.end();++n) { + if (n->second) + n->first->requestConfiguration(tptr); + n->first->sendUpdatesToMembers(tptr); } } - for(std::vector< SharedPtr<Network> >::const_iterator n(needConfig.begin());n!=needConfig.end();++n) - (*n)->requestConfiguration(tptr); // Do pings and keepalives Hashtable< Address,std::vector<InetAddress> > upstreamsToContact; |