From c29017ebe753d461771cc7a1f1878c7920ea23ea Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 13 Nov 2005 16:13:30 +0000 Subject: [PATCH] Made main_loop() exit if there is nothing to do. Also added a guard against multiple inclusion. --- lib/mainloop.c | 17 ++++++++++++++--- lib/mainloop.h | 7 ++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/mainloop.c b/lib/mainloop.c index 7986944e..544a7b7d 100644 --- a/lib/mainloop.c +++ b/lib/mainloop.c @@ -345,7 +345,7 @@ main_rebuild_poll_table(void) main_poll_table_obsolete = 0; } -void +int main_loop(void) { DBG("MAIN: Entering main_loop"); @@ -357,7 +357,7 @@ main_loop(void) struct main_process *pr; cnode *tmp; - while (!main_shutdown) + for (;;) { main_get_time(); timestamp_t wake = main_now + 1000000000; @@ -395,8 +395,19 @@ main_loop(void) wake = 0; } } + if (clist_empty(&main_file_list) && + clist_empty(&main_timer_list) && + clist_empty(&main_hook_list) && + clist_empty(&main_process_list)) + { + DBG("MAIN: Nothing to do, exiting"); + return 0; + } if (main_shutdown) - break; + { + DBG("MAIN: Shutdown"); + return 1; + } /* FIXME: Here is a small race window where SIGCHLD can come unnoticed. */ if ((tm = clist_head(&main_timer_list)) && tm->expires < wake) wake = tm->expires; diff --git a/lib/mainloop.h b/lib/mainloop.h index 1e1adf38..a8626f03 100644 --- a/lib/mainloop.h +++ b/lib/mainloop.h @@ -7,6 +7,9 @@ * of the GNU Lesser General Public License. */ +#ifndef _UCW_MAINLOOP_H +#define _UCW_MAINLOOP_H + #include "lib/clists.h" typedef s64 timestamp_t; /* We measure time in milliseconds */ @@ -93,5 +96,7 @@ int process_fork(struct main_process *mp); /* The main loop */ void main_init(void); -void main_loop(void); +int main_loop(void); void main_debug(void); + +#endif -- 2.39.2