Patch for timer problem in glib 1.2.6



I found a problem with the timer code in glib 1.2.6.  If the time
moves around in unexpected ways, either being set back slightly or
jumping forward, the timer code chokes.  This time moving happens on
my laptop when it enters APM suspend mode, and resets the clock when
it comes back up.

This bug was causing asclock-gtk to hang for what appears to be
indefinitely (although further investigation showed it to be a mere 40
days), ignoring X events and not updating the clock.  A small sample
program that just set the timer to go off every second and printed the
time whenever it went off didn't receive any timer events for at least
an hour after suspending and waking up my laptop.

The fix is to simply do some sanity checking on the times.  In the
code in gmain.c:g_timeout_prepare which sets the timer expiration,
it checks if the time it has calculated it should wait is longer than
the interval, which should never happen in normal operation.  If it
finds this, it sets the time to wait to the timer interval.  And in the
code in gtimer.c:g_timer_elapsed which calculates the difference
between two times, if the difference is negative, it sets it to zero.
This also shouldn't happen in normal operation.

Patch is attached.

Let me know if there are any problems with this,

-----ScottG.

glib-timer.patch



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]