Disko Forum logo Login  |  Register  |  Lost Password
Re:Improvements on MMSTimer

Duran
Posts: 37
graphgraph

Improvements on MMSTimer 5 Years, 10 Months ago  
Dear all,

Reviewing code in the MMSTimer.c I've seen that the condition to check that the range of ns is valid, should be modified: instead of use a condition, a 'while' should be used.

The code:

Code:

if(absTime.tv_nsec > 999999999) { absTime.tv_sec += 1; absTime.tv_nsec -= 999999999; }
should be replaced by:
Code:

while (absTime.tv_nsec > 999999999) { absTime.tv_sec += 1; absTime.tv_nsec -= 999999999; }
Also, this is not a bug, but an optimization of resources. In the current implementation, a thread is created for each timer. My suggestion is to use a thread with a static queue to dispatch all timers. Each time a timer is started, it is inserted in the static queue to be dispatched by the thread. Joaquim Duran
 
  The administrator has disabled public write access.
Re:Improvements on MMSTimer

Stefan
Posts: 91
graph

Re:Improvements on MMSTimer 5 Years, 10 Months ago  
Hi Joaquim,

I don't get the ideal with the while instead of if, but can agree to the idea of using a single thread to handle all the timer issues.

kind regards
Stefan
 
  The administrator has disabled public write access.
Re:Improvements on MMSTimer

Duran
Posts: 37
graphgraph

Re:Improvements on MMSTimer 5 Years, 10 Months ago  
Stefan,

Simply maths: 0xffffffff / 1000000000 = 4,294 so the loop will be executed at much 4 times, and the condition at much 5 times.

When the timer expires, the slot is called by the timer thread, isn't it? It this is true, it is important update the documentation of the class and explain it. It could be the source of errors because the users of the library will not use syncronization objects (mutex,...)

Joaquim Duran
 
  The administrator has disabled public write access.
Powered by FireBoard
get the latest posts directly to your desktop