From e3c000d00d2f441088498adc4579e0c28b3b3ac1 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Tue, 1 Mar 2011 14:07:51 +0100 Subject: [PATCH] Main: Add main_step() --- ucw/mainloop.c | 29 ++++++++++++++++++++++++----- ucw/mainloop.h | 12 ++++++++++-- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/ucw/mainloop.c b/ucw/mainloop.c index 1d213c03..7eb8c8ac 100644 --- a/ucw/mainloop.c +++ b/ucw/mainloop.c @@ -787,10 +787,15 @@ main_loop(void) break; default: ; } - if (count_timers(m)) - wake = MIN(wake, m->timer_table[1]->expires); - main_get_time_ctx(m); - int timeout = ((wake > m->now) ? wake - m->now : 0); + + int timeout = 0; + if (!m->single_step) + { + if (count_timers(m)) + wake = MIN(wake, m->timer_table[1]->expires); + main_get_time_ctx(m); + timeout = ((wake > m->now) ? wake - m->now : 0); + } #ifdef CONFIG_UCW_EPOLL recalc_files(m); @@ -811,7 +816,12 @@ main_loop(void) m->idle_time += m->now - old_now; if (n <= 0) - continue; + { + if (m->single_step) + return; + else + continue; + } // Relink all files with a pending event to file_active_list #ifdef CONFIG_UCW_EPOLL @@ -867,3 +877,12 @@ main_loop(void) } } } + +void +main_step(void) +{ + struct main_context *m = main_current(); + m->single_step = 1; + main_loop(); + m->single_step = 0; +} diff --git a/ucw/mainloop.h b/ucw/mainloop.h index a1d4e24d..ae1c1e4a 100644 --- a/ucw/mainloop.h +++ b/ucw/mainloop.h @@ -24,10 +24,10 @@ /** The main loop context **/ struct main_context { - timestamp_t now; /* [*] Current time in milliseconds since the UNIX epoch. See @main_get_time(). */ + timestamp_t now; /* [*] Current time in milliseconds since the UNIX epoch. See main_get_time(). */ ucw_time_t now_seconds; /* [*] Current time in seconds since the epoch. */ timestamp_t idle_time; /* [*] Total time in milliseconds spent by waiting for events. */ - uns shutdown; /* [*] Setting this to nonzero forces the @main_loop() function to terminate. */ + uns shutdown; /* [*] Setting this to nonzero forces the main_loop() function to terminate. */ clist file_list; clist file_active_list; clist hook_list; @@ -35,6 +35,7 @@ struct main_context { clist process_list; clist signal_list; uns file_cnt; + uns single_step; #ifdef CONFIG_UCW_EPOLL int epoll_fd; /* File descriptor used for epoll */ struct epoll_event *epoll_events; @@ -95,6 +96,13 @@ void main_teardown(void); **/ void main_loop(void); +/** + * Perform a single iteration of the main loop. + * Check if there are any events ready and process them. + * If there are none, do not wait. + **/ +void main_step(void); + /** Ask the main loop to terminate at the nearest occasion. **/ static inline void main_shut_down(void) { -- 2.39.2