Re: glib: GTimer patch for elapsed time



Gavin Baker <gavinb antonym org> writes:

> Hi,
> 
> I recently worked on a project that used Gtk+ and timers, and I was
> quite surprised to find that the GTimer does not properly track elapsed
> time.
> 
> The GTimer in glib resets the clock at each call to gtk_timer_start(). 
> Thus it is incapable of tracking true elapsed time across consecutive
> calls to start-stop.  This rather defeats the purpose of having a timer
> object, since you then have to implement elapsed time tracking yourself.
> 
> The GTimer code has been revisited for v2.0, but it is still effectively
> broken.  I have written a patch (for the v2 code) to address this.  So
> multiple calls to start-stop will now correctly count total elapsed
> time, and it is not zeroed until you call reset.
> 
> I believe the interface is correct; it is modelled after a stopwatch,
> with which we are all familiar.  The implementation just doesn't reflect
> this design.
> 
> I presume the correct procedure is to file a bug and attach the patch?
> 
> Since this is my first contribution to gtk/glib, I have attached the
> patch, for feedback first (Owen?).

This isn't a change we can make. 

 http://developer.gnome.org/doc/API/2.0/glib/glib-timers.html#g-timer-start

Describes the current behavior, and even if it didn't people would
be very likely relying on the current behavior. An incompatible change
could only be made for GLib-3.0, and even then we try very hard
to avoid incompatible changes, or to make them in a way that is
caught by the compiler.

On the other hand adding a g_timer_continue() that doesn't reset the
timer to zero sounds reasonable to me.
 
> Having gone this far, I would like to do some more work on streamlining
> the implementation, and adding support to handle time manipulation (just
> as the date support does), as well as some sort of call like:
> 
>     g_time_snprintf( elapsed, buf, sizeof(buf), "%h:%m:%s" );
> 
>     ==>
> 
>     "15:32:47"
> 
> I have started work on this, and will post more soon.

There is a bug for this:

 http://bugzilla.gnome.org/show_bug.cgi?id=50076

Regards,
                                        Owen



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