]> git.neil.brown.name Git - edlib.git/commitdiff
libevent: split out run_list()
authorNeilBrown <neil@brown.name>
Thu, 8 Jun 2023 23:38:14 +0000 (09:38 +1000)
committerNeilBrown <neil@brown.name>
Wed, 28 Jun 2023 05:40:21 +0000 (15:40 +1000)
I'll want more places that run a list of events, so split out this
functionality.

Signed-off-by: NeilBrown <neil@brown.name>
lib-libevent.c

index e8b2912137d77de5eac0bc4409e9eb15e37d01c9..6abf25734815f6b765a26ae67c1170f64c1dc2da 100644 (file)
@@ -243,11 +243,35 @@ DEF_CB(libevent_poll)
        ev->comm = command_get(ci->comm2);
        ev->active = 0;
        ev->event = "event:poll";
+       ev->num = -1;
        pane_add_notify(ei->home, ev->home, "Notify:Close");
        list_add(&ev->lst, &ei->event_list[POLL_LIST]);
        return 1;
 }
 
+static int run_list(struct event_info *ei safe, int list, char *cb safe)
+{
+       bool dont_block = False;
+       struct evt *ev;
+
+       list_for_each_entry(ev, &ei->event_list[list], lst) {
+               ev->active = 1;
+               if (comm_call(ev->comm, cb, ev->home, ev->num) >= 1)
+                       dont_block = True;
+               if (ev->active == 2) {
+                       list_del(&ev->lst);
+                       command_put(ev->comm);
+                       free(ev);
+                       break;
+               } else
+                       ev->active = 0;
+               if (dont_block)
+                       /* Other things might have been removed from list */
+                       break;
+       }
+       return dont_block;
+}
+
 DEF_CB(libevent_run)
 {
        struct event_info *ei = container_of(ci->comm, struct event_info, run);
@@ -268,22 +292,8 @@ DEF_CB(libevent_run)
        }
 
        /* First run any 'poll' events */
-       list_for_each_entry(ev, &ei->event_list[POLL_LIST], lst) {
-               ev->active = 1;
-               if (comm_call(ev->comm, "callback:poll", ev->home,
-                             -1) >= 1)
-                       dont_block = True;
-               if (ev->active == 2) {
-                       list_del(&ev->lst);
-                       command_put(ev->comm);
-                       free(ev);
-                       break;
-               } else
-                       ev->active = 0;
-               if (dont_block)
-                       /* Other things might have been removed from list */
-                       break;
-       }
+       if (run_list(ei, POLL_LIST, "callback:poll"))
+               dont_block = True;
 
        /* Disable any alarm set by python (or other interpreter) */
        alarm(0);