I've written a kind of simple test case in C. But of course this still assumes that I'm using the timeout interface in a correct way... correct me if not, please.
The test app provides you with a button that when clicked schedules
two timeouts. One with ival=1000 and another one with ival=2000 in
this order. When the callbacks are executed, they print their name.
The test case code is attached (I hope this works on this mailing
list, else I'm going to send another Email). Here it's output with
Agar 1.3.4 unpatched (the code is the same in svn trunk):
$ ./agar-timeouts
schedule timeout1 ival=1000
schedule timeout2 ival=2000
timeout queue:
---- obj 13569952 : -- timeout timeout2 at 6058 ticks -- timeout
timeout1 at 5058 ticks
timeout 2
timeout 1
schedule timeout1 ival=1000
schedule timeout2 ival=2000
timeout queue:
---- obj 13569952 : -- timeout timeout2 at 11593 ticks -- timeout
timeout1 at 10593 ticks
timeout 2
timeout 1
If I apply a patch (you'll find it at the bottom), the result is
correct, for what I want:
$ ./agar-timeouts
schedule timeout1 ival=1000
schedule timeout2 ival=2000
timeout queue:
---- obj 9781152 : -- timeout timeout1 at 3620 ticks -- timeout
timeout2 at 4620 ticks
timeout 1
timeout 2
schedule timeout1 ival=1000
schedule timeout2 ival=2000
timeout queue:
---- obj 9781152 : -- timeout timeout1 at 7991 ticks -- timeout
timeout2 at 8991 ticks
timeout 1
timeout 2
The timeouts are now executed in correct order and at the correct time.
But you know Agar a lot better than me... maybe there are reasons
which I don't know why the timeout order should be like it is
implemented in 1.3.4. And I don't know how to thoroughly test my
patch, whether it breaks something else in Agar.
With best regards,
Jakob
My little patch:
--- timeout.c 2010-03-16 18:46:30.702559589 +0100
+++ timeout.c_ 2010-03-16 18:46:01.618561465 +0100
@@ -77,13 +77,13 @@
TAILQ_REMOVE(&ob->timeouts, to, timeouts);
}
TAILQ_FOREACH(toAfter, &ob->timeouts, timeouts) {
- if (dt < toAfter->ticks) {
+ if (t < toAfter->ticks) {
TAILQ_INSERT_BEFORE(toAfter, to, timeouts);
break;
}
}
if (toAfter == TAILQ_END(&ob->timeouts)) {
- TAILQ_INSERT_HEAD(&ob->timeouts, to, timeouts);
+ TAILQ_INSERT_TAIL(&ob->timeouts, to, timeouts);
}
to->ticks = t;
agar-timeouts.c
Description: Binary data
_______________________________________________ Agar mailing list [email protected] http://libagar.org/lists.html
