mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
deal correctly with deleting an event, now that we allow multiple callbacks
for signal delivery. svn:r20
This commit is contained in:
parent
06630e3116
commit
59137c119f
16
event.c
16
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);
|
||||
}
|
||||
|
||||
|
1
event.h
1
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;
|
||||
|
||||
|
2
select.c
2
select.c
@ -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 *);
|
||||
|
Loading…
x
Reference in New Issue
Block a user