diff --git a/event/hevent.h b/event/hevent.h index be0389738..1650b22a5 100644 --- a/event/hevent.h +++ b/event/hevent.h @@ -291,5 +291,13 @@ void hio_memmove_readbuf(hio_t* io); EVENT_ACTIVE(ev);\ ev->pending = 0;\ } while(0) + +#define EVENT_UNPENDING(ev) \ + do {\ + if (ev->pending) {\ + ev->pending = 0;\ + ev->loop->npendings--;\ + }\ + } while(0) #endif // HV_EVENT_H_ diff --git a/event/hloop.c b/event/hloop.c index 9f3133172..bd0d9e179 100644 --- a/event/hloop.c +++ b/event/hloop.c @@ -117,7 +117,7 @@ static int hloop_process_pendings(hloop_t* loop) { cur = loop->pendings[i]; while (cur) { next = cur->pending_next; - if (cur->pending) { + if (cur->pending && cur->loop == loop) { if (cur->active && cur->cb) { cur->cb(cur); ++ncbs; @@ -875,6 +875,7 @@ int hio_del(hio_t* io, int events) { io->loop->nios--; // NOTE: not EVENT_DEL, avoid free EVENT_INACTIVE(io); + EVENT_UNPENDING(io); } return 0; }