Added a lock-free queue to lwIP driver for RX packet processing. Added checks to force strict ordering of callback events

This commit is contained in:
Joseph Henry
2019-02-07 14:11:17 -08:00
parent 52a7e9229e
commit 1f8d3030c8
4 changed files with 89 additions and 70 deletions

View File

@@ -827,6 +827,9 @@ public:
inline void generateEventMsgs()
{
if (!lwip_is_up()) {
return; // Don't process peer status events unless the stack is up.
}
// Generate messages to be dequeued by the callback message thread
#if ZTS_NETWORK_CALLBACKS
Mutex::Lock _l(_nets_m);
@@ -870,7 +873,7 @@ public:
ZT_PeerList *pl = _node->peers();
if (pl) {
for(unsigned long i=0;i<pl->peerCount;++i) {
if (!peerCache.count(pl->peers[i].address)) { // Add first entry
if (!peerCache.count(pl->peers[i].address)) {
if (pl->peers[i].pathCount > 0) {
_callbackMsgQueue.enqueue(new std::pair<uint64_t,int>(pl->peers[i].address, ZTS_EVENT_PEER_P2P));
}
@@ -885,6 +888,7 @@ public:
_callbackMsgQueue.enqueue(new std::pair<uint64_t,int>(pl->peers[i].address, ZTS_EVENT_PEER_RELAY));
}
}
// Update our cache with most recently observed path count
peerCache[pl->peers[i].address] = pl->peers[i].pathCount;
}
}