bugfix for etimer in 9libs-1.0

  • From: Tommy Pettersson <ptp@xxxxxxxxxxxxxx>
  • To: wilyfans@xxxxxxxxxxxxx
  • Date: Thu, 14 Oct 2004 20:46:24 +0200

I am trying out different ways to make wily time aware,
so I can invoke an autosave function periodically, and I
discovered a bug in 9libs' etimer functions.

When an etimer is started, an X time out is issued and its
id is saved.  When the etimer is stopped, the X time out with
this id is canceled.

The callback gottimeout in 9libs gets the X time out, puts
an etimer event on the queue, and issues a new X time out
(X time outs are one time triggers).  However, gottimeout
does not save the new X time out id.

So, if I stop the etimer after a while, the wrong X time out
is canceled, and gottimeout will still get the last time out.
Since the etimer is now off, it will just be ignored.

UNLESS I have rushed to started a new etimer.  Then the
last time out from the old etimer will be accepted and keep
repeating, at its old pace.

Autosaves every SCROLLTIME milliseconds is a bit too often.

The X time out id:s get reused by X.  There is usually just two
of them in use.  In that case every second issued X time out
have the originally saved id, so by 50% chance the X time out
will get canceled.  Therefore the bug seems to happen randomly.

I don't think this bug can happen to wily as it is, and if it
did, it would probably manifest itself as scrolling with double
speed when holding button in scrollbar or selecting text.

The bugfix is simple: make gottimeout update the id.  There's a
patch at end of this e-mail.  I also made it drop unexpected
id:s, just in case.

Tommy Pettersson <ptp@xxxxxxxxxxxxxx>

diff -rN -u diff-old/9libs-1.0/libXg/xtbinit.c 
--- diff-old/9libs-1.0/libXg/xtbinit.c  Thu Oct 14 20:38:17 2004
+++ diff-new/9libs-1.0/libXg/xtbinit.c  Thu Oct 14 20:38:02 2004
@@ -332,7 +332,7 @@
 static void
 gottimeout(XtPointer cldata, XtIntervalId *id)
-       if(!einitcalled || Stimer == -1)
+       if(!einitcalled || Stimer == -1 || esrc[Stimer].id != *(XtInputId*) id)
         * Don't queue up timeouts, because there's
@@ -341,7 +341,7 @@
        esrc[Stimer].head = (Ebuf *)1;
        esrc[Stimer].count = 1;
-       XtAppAddTimeOut(app, (long)cldata, gottimeout, cldata);
+       esrc[Stimer].id = (XtInputId) XtAppAddTimeOut(app, (long)cldata, 
gottimeout, cldata);
 static int

Other related posts: