Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
Merge pull request eventmachine#229 from renekalff/oversleeping
Browse files Browse the repository at this point in the history
Modified TimeTilNextEvent to calculate based on current time
  • Loading branch information
tmm1 committed Oct 5, 2011
2 parents ef82847 + 7828e5e commit 07fc8c7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions ext/em.cpp
Expand Up @@ -673,7 +673,13 @@ EventMachine_t::_TimeTilNextEvent

timeval EventMachine_t::_TimeTilNextEvent()
{
// 29jul11: Changed calculation base from MyCurrentLoopTime to the
// real time. As MyCurrentLoopTime is set at the beginning of an
// iteration and this calculation is done at the end, evenmachine
// will potentially oversleep by the amount of time the iteration
// took to execute.
uint64_t next_event = 0;
uint64_t current_time = GetRealTime();

if (!Heartbeats.empty()) {
multimap<uint64_t,EventableDescriptor*>::iterator heartbeats = Heartbeats.begin();
Expand All @@ -687,16 +693,16 @@ timeval EventMachine_t::_TimeTilNextEvent()
}

if (!NewDescriptors.empty() || !ModifiedDescriptors.empty()) {
next_event = MyCurrentLoopTime;
next_event = current_time;
}

timeval tv;

if (next_event == 0 || NumCloseScheduled > 0) {
tv = Quantum;
} else {
if (next_event > MyCurrentLoopTime) {
uint64_t duration = next_event - MyCurrentLoopTime;
if (next_event > current_time) {
uint64_t duration = next_event - current_time;
tv.tv_sec = duration / 1000000;
tv.tv_usec = duration % 1000000;
} else {
Expand Down

0 comments on commit 07fc8c7

Please sign in to comment.