From: Martin Z. <co...@mz...> - 2010-11-28 18:12:56
|
Hello everybody! I finally had the time to beautify, streamline and fully comment both the timer and timer group code. It's been quite a bit of work, but I can only encourage everyone to do it. Commenting your code will not only enable others to help fixing bugs much more efficiently because the code is much easier to understand. On "re-thinking" the code I and others wrote, I have also found three to four would-be problems or even bugs per C file. That being said, here come the two things in "timer.c" I didn't want to change without asking in advance. First, I think that CLOCK_SKEW_DETECT_TIME_IN_S should be set to a much higher value: /* delay in seconds between timer events that is considered as being induced by clock skew */ #define CLOCK_SKEW_DETECT_TIME_IN_S 1 Imagine you only have timers that trigger every two seconds (think of a rather slow processor and/or LCD with data that rarely change). Right now, the timers always trigger immediately instead of every two seconds because the code assumes the delay (two seconds) is being caused by clock skew instead of the timer. Of course, increasing CLOCK_SKEW_DETECT_TIME_IN_S won't get rid of the problem completely. But it will lower the chances that a user will stumble upon the "clock skew problem" (which might be totally obscure to him or her). I propose a value of 61 seconds (just above one minute). This should be a sane value that is able to efficiently spot clock skew while not needlessly constraining the users' freedom. :) But I'm open to comments -- that's why I'm writing all this. The other "thing" seems like a real bug to me (and is of course related to clock skew). In case a clock skew has been detected, the next upcoming timer (and *only* that) is updated to the new time. Now imagine two timers of different intervals and a clock skew of one hour (think of the transitions between summer and winter time). The next upcoming timer (let's say number 1) is updated and triggers on. But what about the second? If I get that right, it will not trigger for at least a whole hour while the user awes in wonder! So I think we should update *all* timers: for (timer = 0; timer < nTimers; timer++) Timers[timer].when = now; instead of only the next upcoming one: Timers[next_timer].when = now; Again, I'm open for discussion. Maybe I even got something wrong as I tried to bend my brain around the PROBLEM OF TIME -- me not being a philosopher... :) Have a nice Sunday, Martin -- www.mzuther.de www.radix-musik.de |