From: Martin Z. <co...@mz...> - 2010-02-09 20:22:32
|
Hi everybody, I have finally implemented and commented the code for syncing all timers. To make it more useful, I have placed this code in timer_inc(), which is now: static void timer_inc( struct timeval *timer, const struct timeval *now, const int interval, const short calculate_upcoming_event) The function is used to calculate the starting point of newly added timers and also to calculate the next triggering event for existing timers. I have tried to describe this behaviour in my last email. In short, it records the moment the first timer was started within "lcd4linux". Then, it uses this moment to quantise timer events using a timer's update interval: first timer: v second timer: * * * * * * quantisation: +---+---+---+---+---+---+--- second timer: * * * * * * This get's rid of the last synching problem, the differences in starting delay. For example, if you have to widgets with update intervals of 250 ms and 500 ms, respectively, you often got: 250 ms: * * * * * * * * * * * * 500 ms: * * * * * * Now you they are completely in sync: 250 ms: * * * * * * * * * * * * 500 ms: * * * * * * As a side note, the parameter "calculate_upcoming_event" is used to tell timer_inc() whether it should calculate the last time the timer triggered or the next time the timer will be triggered. This is all a bit hard to explain, but I hope that I gave you at least an idea of what I'm talking about. The new implementation of timer_inc() has one "problem" though: if you add a timer, the delay to first triggering event will usually be less than its update time. For example, if you add a timer of 400 ms, it might already trigger after 235 ms (afterwards, it will of course stick to the 400 ms). This is needed for quantisation and thus synchronisation of the timers, but I don't know if anybody needs "unsynched" timers that trigger *exactly* after the update time has passed. Which is the reason why I haven't yet committed my code. Actually, this is somewhat theoretical, because when I'm talking of "timing to the microsecond", I mean the times a timer *should* trigger, not the times it *does* trigger. This depends on things we can't influence, such as CPU utilisation and the time widgets need for updating. If you didn't get what the heck I'm talking about, please complain. Otherwise, tell me whether you see a need for "unsynched" timers or not. :) Thanks, Martin -- www.mzuther.de www.radix-musik.de |