From: Niels Provos Date: Wed, 10 Apr 2002 03:15:19 +0000 (+0000) Subject: deal correctly with deleting an event, now that we allow multiple callbacks X-Git-Tag: release-1.1b~149 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=59137c119f9deaca9244811040aa3fee2f7b293c;p=libevent deal correctly with deleting an event, now that we allow multiple callbacks for signal delivery. svn:r20 --- diff --git a/event.c b/event.c index 882830d8..aa5f295d 100644 --- a/event.c +++ b/event.c @@ -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); } diff --git a/event.h b/event.h index 03eeb576..6079f9ad 100644 --- a/event.h +++ b/event.h @@ -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; diff --git a/select.c b/select.c index afafb444..e89f807f 100644 --- a/select.c +++ b/select.c @@ -38,6 +38,7 @@ #include #include #include +#include #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 *);