]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Flush deferred calls directly after the loop finished its one run
authorMaria Matejka <mq@ucw.cz>
Thu, 27 Jun 2024 06:37:05 +0000 (08:37 +0200)
committerMaria Matejka <mq@ucw.cz>
Fri, 28 Jun 2024 20:03:45 +0000 (22:03 +0200)
lib/defer.h
lib/io-loop.h
sysdep/unix/io-loop.c
sysdep/unix/io-loop.h

index b53d1efa9814e9eb9710699f5a6a21e87dc18a44..69128ef678c7492dcc7950547b95e4ae3fd03031 100644 (file)
@@ -39,7 +39,7 @@ static inline void defer_call(struct deferred_call *call, size_t actual_size) {
 
   /* If first, send the actual event to the local thread */
   if (local_deferred.last == &local_deferred.first)
-    ev_send_this_thread(&local_deferred.e);
+    ev_send_defer(&local_deferred.e);
 
   /* Add to list */
   a->next = NULL;
index b893aa4531aa4e6b08c0943e2ab38681ba9af29d..9f08420a60227bb4e545eeebe18ffd776a4616b3 100644 (file)
@@ -19,6 +19,9 @@ extern struct birdloop main_birdloop;
 /* Currently running birdloop */
 extern _Thread_local struct birdloop *this_birdloop;
 
+/* Lowest entered birdloop */
+extern _Thread_local struct birdloop *birdloop_current;
+
 /* Check that the task has enough time to do a bit more */
 bool task_still_in_limit(void);
 bool task_before_halftime(void);
@@ -40,8 +43,8 @@ void birdloop_stop(struct birdloop *loop, void (*stopped)(void *data), void *dat
 void birdloop_stop_self(struct birdloop *loop, void (*stopped)(void *data), void *data);
 void birdloop_free(struct birdloop *loop);
 
-/* Run this event in this thread's priority event list */
-void ev_send_this_thread(event *e);
+/* Run this event in the running loop's priority event list to run asap */
+void ev_send_defer(event *e);
 
 /* Get birdloop's time heap */
 struct timeloop *birdloop_time_loop(struct birdloop *loop);
index c332b5df8533699cd300539c62a5f87b6578231b..d2a60562e0bb0b494bb04c1726b8f5327a3e463d 100644 (file)
@@ -1543,6 +1543,10 @@ birdloop_run(void *_loop)
     /* Process socket RX */
     sockets_fire(loop, 1, 0);
 
+    /* Flush deferred events */
+    while (ev_run_list(&loop->defer_list))
+      repeat++;
+
     /* Check end time */
   } while (repeat && task_still_in_limit());
 
@@ -1750,10 +1754,10 @@ birdloop_yield(void)
 }
 
 void
-ev_send_this_thread(event *e)
+ev_send_defer(event *e)
 {
   if (this_thread == &main_thread)
     ev_send_loop(&main_birdloop, e);
   else
-    ev_send(&this_thread->priority_events, e);
+    ev_send(&this_birdloop->defer_list, e);
 }
index 9c7c3718246710d592e1fe49cef1c2071f7aeeb3..f7fde411b6c817d3d0e62baeab4f294aac5f5c84 100644 (file)
@@ -48,6 +48,7 @@ struct birdloop
 
   struct timeloop time;
   event_list event_list;
+  event_list defer_list;
   list sock_list;
   struct birdsock *sock_active;
   int sock_num;