summaryrefslogtreecommitdiff
path: root/node/Switch.hpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2017-08-23 15:19:26 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2017-08-23 15:19:26 -0700
commitb1d94c9f9324a31887dc6edc99ed58d4f9b187db (patch)
tree2aa0f48dd903453b3f12d8ef1240841b5f46ec90 /node/Switch.hpp
parenta156a4dbe2ffe5fc5f870144fe80efc172901d8e (diff)
downloadinfinitytier-b1d94c9f9324a31887dc6edc99ed58d4f9b187db.tar.gz
infinitytier-b1d94c9f9324a31887dc6edc99ed58d4f9b187db.zip
Performance improvement to RX queue ring buffer.
Diffstat (limited to 'node/Switch.hpp')
-rw-r--r--node/Switch.hpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/node/Switch.hpp b/node/Switch.hpp
index 114bc5e1..88415541 100644
--- a/node/Switch.hpp
+++ b/node/Switch.hpp
@@ -174,19 +174,20 @@ private:
// Returns matching or next available RX queue entry
inline RXQueueEntry *_findRXQueueEntry(uint64_t packetId)
{
- unsigned int ptr = static_cast<unsigned int>(_rxQueuePtr.load());
- for(unsigned int k=0;k<ZT_RX_QUEUE_SIZE;++k) {
- RXQueueEntry *rq = &(_rxQueue[--ptr % ZT_RX_QUEUE_SIZE]);
+ const unsigned int current = static_cast<unsigned int>(_rxQueuePtr.load());
+ for(unsigned int k=1;k<=ZT_RX_QUEUE_SIZE;++k) {
+ RXQueueEntry *rq = &(_rxQueue[(current - k) % ZT_RX_QUEUE_SIZE]);
if ((rq->packetId == packetId)&&(rq->timestamp))
return rq;
}
- return &(_rxQueue[static_cast<unsigned int>(++_rxQueuePtr) % ZT_RX_QUEUE_SIZE]);
+ ++_rxQueuePtr;
+ return &(_rxQueue[static_cast<unsigned int>(current) % ZT_RX_QUEUE_SIZE]);
}
- // Returns next RX queue entry in ring buffer and increments ring counter
+ // Returns current entry in rx queue ring buffer and increments ring pointer
inline RXQueueEntry *_nextRXQueueEntry()
{
- return &(_rxQueue[static_cast<unsigned int>(++_rxQueuePtr) % ZT_RX_QUEUE_SIZE]);
+ return &(_rxQueue[static_cast<unsigned int>((++_rxQueuePtr) - 1) % ZT_RX_QUEUE_SIZE]);
}
// ZeroTier-layer TX queue entry