]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/mainloop.c
fb-grow: Renamed fbgrow_read_all() to fbgrow_get_buf().
[libucw.git] / ucw / mainloop.c
index 03cff677a980c13d4adc3b83d6e4cd75542a1721..7eb8c8acdf35fe59861dc0fccb76a0a6ac0b9971 100644 (file)
@@ -124,7 +124,6 @@ main_prepare_delete(struct main_context *m)
 
   // Close epoll descriptor early enough, it might be shared after fork!
 #ifdef CONFIG_UCW_EPOLL
-  ASSERT(clist_empty(&m->file_recalc_list));
   xfree(m->epoll_events);
   close(m->epoll_fd);
   m->epoll_fd = -1;
@@ -166,6 +165,9 @@ main_delete(struct main_context *m)
   main_prepare_delete(m);
   ASSERT(clist_empty(&m->file_list));
   ASSERT(clist_empty(&m->file_active_list));
+#ifdef CONFIG_UCW_EPOLL
+  ASSERT(clist_empty(&m->file_recalc_list));
+#endif
   ASSERT(clist_empty(&m->hook_list));
   ASSERT(clist_empty(&m->hook_done_list));
   ASSERT(clist_empty(&m->process_list));
@@ -707,7 +709,7 @@ process_hooks(struct main_context *m)
     hook_min == HOOK_DONE && hook_max == HOOK_DONE ||
     m->shutdown)
     {
-      DBG("MAIN: Shut down by %s", m->shutdown ? "main_shutdown" : "a hook");
+      DBG("MAIN: Shut down by %s", m->shutdown ? "main_shut_down" : "a hook");
       return HOOK_SHUTDOWN;
     }
   if (hook_max == HOOK_RETRY)
@@ -770,6 +772,8 @@ main_loop(void)
   struct main_context *m = main_current();
 
   main_get_time_ctx(m);
+  m->shutdown = 0;
+
   for (;;)
     {
       timestamp_t wake = m->now + 1000000000;
@@ -783,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);
@@ -807,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
@@ -863,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;
+}