summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2015-09-23 14:01:41 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2015-09-23 14:01:41 -0700
commit2a527ea82e597759433d9bb3c8e884463c81fc2b (patch)
tree13c802fb7d8eda4ccb2590147e3b10e49d203523
parent367ffde00cf6eecbca0f9fff391dcaf7faf72c6e (diff)
downloadinfinitytier-2a527ea82e597759433d9bb3c8e884463c81fc2b.tar.gz
infinitytier-2a527ea82e597759433d9bb3c8e884463c81fc2b.zip
Fix for timer jitter problem.
-rw-r--r--node/Node.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/node/Node.cpp b/node/Node.cpp
index f9559ab4..7aad54b8 100644
--- a/node/Node.cpp
+++ b/node/Node.cpp
@@ -233,7 +233,9 @@ ZT1_ResultCode Node::processBackgroundTasks(uint64_t now,volatile uint64_t *next
_now = now;
Mutex::Lock bl(_backgroundTasksLock);
- if ((now - _lastPingCheck) >= ZT_PING_CHECK_INVERVAL) {
+ unsigned long timeUntilNextPingCheck = ZT_PING_CHECK_INVERVAL;
+ const uint64_t timeSinceLastPingCheck = now - _lastPingCheck;
+ if (timeSinceLastPingCheck >= ZT_PING_CHECK_INVERVAL) {
try {
_lastPingCheck = now;
@@ -278,6 +280,8 @@ ZT1_ResultCode Node::processBackgroundTasks(uint64_t now,volatile uint64_t *next
} catch ( ... ) {
return ZT1_RESULT_FATAL_ERROR_INTERNAL;
}
+ } else {
+ timeUntilNextPingCheck -= (unsigned long)timeSinceLastPingCheck;
}
if ((now - _lastHousekeepingRun) >= ZT_HOUSEKEEPING_PERIOD) {
@@ -292,7 +296,7 @@ ZT1_ResultCode Node::processBackgroundTasks(uint64_t now,volatile uint64_t *next
}
try {
- *nextBackgroundTaskDeadline = now + (uint64_t)std::max(std::min((unsigned long)ZT_PING_CHECK_INVERVAL,RR->sw->doTimerTasks(now)),(unsigned long)ZT_CORE_TIMER_TASK_GRANULARITY);
+ *nextBackgroundTaskDeadline = now + (uint64_t)std::max(std::min(timeUntilNextPingCheck,RR->sw->doTimerTasks(now)),(unsigned long)ZT_CORE_TIMER_TASK_GRANULARITY);
} catch ( ... ) {
return ZT1_RESULT_FATAL_ERROR_INTERNAL;
}