Procházet zdrojové kódy

Fix race condition after hio_detach (#755)

Patch authored by @ithewei based on issue #754.
Submitted via PR to track and close the issue.
Alireza před 4 měsíci
rodič
revize
23ff5915aa
2 změnil soubory, kde provedl 10 přidání a 1 odebrání
  1. 8 0
      event/hevent.h
  2. 2 1
      event/hloop.c

+ 8 - 0
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_

+ 2 - 1
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;
 }