mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2025-01-15 05:21:54 +00:00
Minimalist mainloop implementation
This commit is contained in:
parent
20d8eaa7d3
commit
96f357c5d6
@ -82,5 +82,7 @@ struct thread_config {
|
||||
|
||||
void bird_thread_commit(struct thread_config *new);
|
||||
|
||||
/* Minimalist main */
|
||||
void birdloop_minimalist_main(void) NORET;
|
||||
|
||||
#endif /* _BIRD_IO_LOOP_H_ */
|
||||
|
@ -1594,3 +1594,41 @@ ev_send_defer(event *e)
|
||||
else
|
||||
ev_send(&this_birdloop->defer_list, e);
|
||||
}
|
||||
|
||||
/*
|
||||
* Minimalist mainloop with no sockets
|
||||
*/
|
||||
|
||||
void
|
||||
birdloop_minimalist_main(void)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
times_update();
|
||||
ev_run_list(&global_event_list);
|
||||
ev_run_list(&global_work_list);
|
||||
ev_run_list(&main_birdloop.event_list);
|
||||
timers_fire(&main_birdloop.time);
|
||||
|
||||
bool events =
|
||||
!ev_list_empty(&global_event_list) ||
|
||||
!ev_list_empty(&global_work_list) ||
|
||||
!ev_list_empty(&main_birdloop.event_list);
|
||||
|
||||
int poll_tout = (events ? 0 : 3000); /* Time in milliseconds */
|
||||
timer *t;
|
||||
if (t = timers_first(&main_birdloop.time))
|
||||
{
|
||||
times_update();
|
||||
int timeout = (tm_remains(t) TO_MS) + 1;
|
||||
poll_tout = MIN(poll_tout, timeout);
|
||||
}
|
||||
|
||||
struct pollfd pfd = {
|
||||
.fd = main_birdloop.thread->wakeup.fd[0],
|
||||
.events = POLLIN,
|
||||
};
|
||||
|
||||
poll(&pfd, 1, poll_tout);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user