new 4-heap code - please give it a try

Brandon Black blblack at gmail.com
Thu May 8 00:22:03 CEST 2008


Brandon Black wrote:
> Brandon Black wrote:
>> Marc Lehmann wrote:
>>> I just committed code to use a 4-heap instead of a 2-heap to libev.
>> [...]
>>
>> I've just tried it against my code, looks pretty good from here.  My 
>> test suite passes with the new code, so no breakage.
>>
> 
> I spoke too soon (I guess my test suite still needs some work), I'm 
> having a timer-related issue with cvs that didn't happen with 3.31. 
> Specifically, if (in a single event loop) I start a repeating timer of 
> 20 seconds, and then a one-shot timer of 3 seconds, they both fire at 
> the 20-second mark.  I'm still in the process of making sure I didn't do 
> something dumb to cause this, and making a simpler piece of test code 
> for it, but just a heads up in case you have an obvious answer.

Here's some simple demo code that seems to exhibit the issue I'm seeing 
with cvs's timers, using two single-shot timers of 3 and 10 seconds. 
Switching the order of the ev_timer_start()s makes it behave better.

--------------------------------------

#include <stdio.h>
#include <time.h>
#include "ev.h"

static void ten_cb(struct ev_loop* loop, struct ev_timer* t, int revents) {
     fprintf(stderr, "The 10-sec timer fired @ %li\n", time(NULL));
     ev_unloop(loop, EVUNLOOP_ALL);
}

static void three_cb(struct ev_loop* loop, struct ev_timer* t, int 
revents) {
     fprintf(stderr, "The 3-sec timer fired @ %li\n", time(NULL));
     ev_unloop(loop, EVUNLOOP_ALL);
}

int main(int argc, char* argv[]) {
     struct ev_timer ten;
     struct ev_timer three;
     struct ev_loop* def_loop = ev_default_loop(EVFLAG_AUTO);

     ev_timer_init(&ten, &ten_cb, 10., 0.);
     ev_timer_init(&three, &three_cb, 3., 0.);

     ev_timer_start(def_loop, &ten);
     ev_timer_start(def_loop, &three);

     fprintf(stderr, "Starting loop @ %li\n", time(NULL));
     ev_loop(def_loop, 0);

     return 0;
}




More information about the libev mailing list