← Back to team overview

linuxdcpp-team team mailing list archive

[Bug 713742] Re: TimerManager generate double tick per second on some situations

 

I don't know if this will compile well or not, but basically it replaces
the current code by other more simple that still follows the same
guidelines (i.e. don't mark unmarked past events more than once but
provide a tick count so it can be used to see how long has passed since
the last call). The code is made to ensure that the method will be
called at most once every second (like the original one) which could
cause issues if you trust you will called a fixed amount of times in a
fixed time (i.e. you know that between calls at least one second has
passed, but to know the exact time you will need to check the tick
counter).

The only code that may have issues with this is in ThrottlingManager
since it will not take into account these time variations, if instead
you want to ensure that the event is fired exactly once per second
(which means it may be fired more than once if the clock jumps or the
program get blocked for heavy load) then you need a slightly different
code, basically replace nextSecond = now + seconds(1); inside the if by
nextSecond += seconds(1);

** Patch added: "Lossy timer implementation. Copyright assigned to Jacek Sieka."
   https://bugs.launchpad.net/dcplusplus/+bug/713742/+attachment/3542625/+files/use_lossy_timer.patch

-- 
You received this bug notification because you are a member of
Dcplusplus-team, which is subscribed to DC++.
https://bugs.launchpad.net/bugs/713742

Title:
  TimerManager generate  double tick per second on some situations

Status in DC++:
  Confirmed

Bug description:
  Code to fix this error quote below:

  int TimerManager::run()
  {
  	int nextMin = 0;
  	
  	ptime now = microsec_clock::universal_time();
  	ptime nextSecond = now + seconds(1);
  	while (!mtx.timed_lock(nextSecond))
  	{
  		const uint64_t t = getTick();
  		now = microsec_clock::universal_time();
  		nextSecond += seconds(1);
  		if (nextSecond < now)
  		{
  			nextSecond = now + seconds(1); // [!] IRainman fix TimerManager error: two tick generated in one second.
  		}
  		
  		fire(TimerManagerListener::Second(), t);
  		if (nextMin++ >= 60)
  		{
  			fire(TimerManagerListener::Minute(), t);
  			nextMin = 0;
  		}
  	}
  	
  	dcdebug("TimerManager done\n");
  	return 0;
  }

  autor FlylinkDC++ Team http://code.google.com/p/flylinkdc

To manage notifications about this bug go to:
https://bugs.launchpad.net/dcplusplus/+bug/713742/+subscriptions


References