deal correctly with deleting an event, now that we allow multiple callbacks

for signal delivery.


svn:r20
This commit is contained in:
Niels Provos 2002-04-10 03:15:19 +00:00
parent 06630e3116
commit 59137c119f
3 changed files with 18 additions and 1 deletions

16
event.c
View File

@ -138,13 +138,20 @@ void
event_process_active(void)
{
struct event *ev;
short ncalls;
for (ev = TAILQ_FIRST(&activequeue); ev;
ev = TAILQ_FIRST(&activequeue)) {
event_queue_remove(ev, EVLIST_ACTIVE);
while (ev->ev_ncalls--)
/* Allows deletes to work */
ncalls = ev->ev_ncalls;
ev->ev_pncalls = &ncalls;
while (ncalls) {
ncalls--;
ev->ev_ncalls = ncalls;
(*ev->ev_callback)(ev->ev_fd, ev->ev_res, ev->ev_arg);
}
}
}
@ -307,6 +314,12 @@ event_del(struct event *ev)
assert(!(ev->ev_flags & ~EVLIST_ALL));
/* See if we are just active executing this event in a loop */
if (ev->ev_ncalls && ev->ev_pncalls) {
/* Abort loop */
*ev->ev_pncalls = 0;
}
if (ev->ev_flags & EVLIST_TIMEOUT)
event_queue_remove(ev, EVLIST_TIMEOUT);
@ -329,6 +342,7 @@ event_active(struct event *ev, int res, short ncalls)
{
ev->ev_res = res;
ev->ev_ncalls = ncalls;
ev->ev_pncalls = NULL;
event_queue_insert(ev, EVLIST_ACTIVE);
}

View File

@ -78,6 +78,7 @@ struct event {
int ev_fd;
short ev_events;
short ev_ncalls;
short *ev_pncalls; /* Allows deletes in callback */
struct timeval ev_timeout;

View File

@ -38,6 +38,7 @@
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <err.h>
#ifdef USE_LOG
#include "log.h"
@ -68,6 +69,7 @@ struct selectop {
void signal_process(void);
int signal_recalc(void);
int signal_deliver(void);
void *select_init (void);
int select_add (void *, struct event *);