Hi,

I got the following problem with ev_is_active():

I got a ev_timer, and it gets started, then something which takes a lot of time happens, and I'd stop the timer if ev_is_active claims the timer is still active. But, ev_is_active reports the timer is not active, I do not disable the timer, and the timers callback gets fired afterwards.

Thats the problem.
ev_is_active reports the timer is inactive, and the callback gets fired.
Sounds scary, yes.

I used gdb to verify:

ev_is_active is false:

(gdb) p con->events.dns_timeout
$6 = {active = 0, pending = 1, priority = 0, data = 0x9a2b8c8, cb = 0x805a410 <the_cb>,
  at = -3.4154873266816139, repeat = 0}

but later on, the callback fires:

(gdb) p con->events.dns_timeout
$7 = {active = 0, pending = 0, priority = 0, data = 0x9a2b8c8, cb = 0x805a410 <the_cb>,
  at = -3.4154873266816139, repeat = 0}

I noticed the 'pending' field, so when is a not repeating ev_timer inactive?
If I ask to disable an ev_timer in the same ev_loop iteration which would fire the callback (ev_timer.pending = 1), is the ev_is_active(ev_timer) meant to be true or false?

I'd expect it to be true - as I did not call ev_timer_stop on it yet, and the callback did not come in yet, but I think I'm wrong.

Attached is a sample program, t1_cb is expected to stop t2, so t2_cb never gets called, but t2_cb is called always.

./timertest
called t1_cb loop 0x7fd720899200 w 0x601100 revents 256
called t2_cb loop 0x7fd720899200 w 0x601080 revents 256



Thanks,
Markus
/*
gcc -Wall -o timertest timertest.c -lev
*/

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

struct ev_timer t1;
struct ev_timer t2;
struct ev_signal s1;

void waste(time_t s)
{
	time_t now = time(NULL);
	int i = 0;
	while((now + s) > time(NULL))
		i++;
}
	

void t1_cb(struct ev_loop *loop, struct ev_timer *w, int revents)
{
	printf("called %s loop %p w %p revents %i\n", __PRETTY_FUNCTION__, loop, w, revents);	
	if( ev_is_active(&t2) )
	{
		printf("stopping t2\n");
		ev_timer_stop(loop, &t2);
	}
}

void t2_cb(struct ev_loop *loop, struct ev_timer *w, int revents)
{
	printf("called %s loop %p w %p revents %i\n", __PRETTY_FUNCTION__, loop, w, revents);
}

int main()
{
	struct ev_loop *loop = ev_default_loop (0);
	ev_timer_init(&t1, t1_cb, 1.0, 0);
	ev_timer_init(&t2, t2_cb, 5.0, 0); 
	ev_timer_start(loop, &t1);
	ev_timer_start(loop, &t2);	
	waste(6);
	ev_loop (loop, 0);
	return 0;
}
_______________________________________________
libev mailing list
[email protected]
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev

Reply via email to