0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-22 01:31:55 +00:00

Flush deferred calls directly after the loop finished its one run

This commit is contained in:
Maria Matejka 2024-06-27 08:37:05 +02:00
parent 865bab6237
commit 1e77e6e1b2
4 changed files with 13 additions and 5 deletions

View 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;

View 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);

View 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);
}

View 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;