X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Fmainloop.c;h=b2b07c5082476bedbdc023e094f49f6feb02a28b;hb=f17e4350dcf0c033891e52b30b0c32a4a4fed5e0;hp=454ea81c2776c7316d4a651889e3fcddd54444af;hpb=69492f375d4700edd9e309ebc57b5438d38f903f;p=libucw.git diff --git a/ucw/mainloop.c b/ucw/mainloop.c index 454ea81c..b2b07c50 100644 --- a/ucw/mainloop.c +++ b/ucw/mainloop.c @@ -1,7 +1,7 @@ /* * UCW Library -- Main Loop * - * (c) 2004--2011 Martin Mares + * (c) 2004--2012 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -9,11 +9,13 @@ #undef LOCAL_DEBUG -#include "ucw/lib.h" -#include "ucw/heap.h" -#include "ucw/mainloop.h" -#include "ucw/threads.h" -#include "ucw/gary.h" +#include +#include +#include +#include +#include +#include +#include #include #include @@ -49,10 +51,7 @@ static void signal_del_ctx(struct main_context *m, struct main_signal *ms); static void main_get_time_ctx(struct main_context *m) { - struct timeval tv; - gettimeofday(&tv, NULL); - m->now_seconds = tv.tv_sec; - m->now = (timestamp_t)tv.tv_sec * 1000 + tv.tv_usec / 1000; + m->now = get_timestamp(); } static struct main_context * @@ -355,7 +354,8 @@ file_del_ctx(struct main_context *m, struct main_file *fi) // XXX: Can be called on a non-current context DBG("MAIN: Deleting file %p (fd=%d)", fi, fi->fd); - ASSERT(file_is_active(fi)); + if (!file_is_active(fi)) + return; clist_unlink(&fi->n); m->file_cnt--; #ifdef CONFIG_UCW_EPOLL @@ -378,7 +378,8 @@ hook_add(struct main_hook *ho) struct main_context *m = main_current(); DBG("MAIN: Adding hook %p", ho); - ASSERT(!hook_is_active(ho)); + if (hook_is_active(ho)) + clist_unlink(&ho->n); clist_add_tail(&m->hook_list, &ho->n); } @@ -386,8 +387,8 @@ void hook_del(struct main_hook *ho) { DBG("MAIN: Deleting hook %p", ho); - ASSERT(hook_is_active(ho)); - clist_unlink(&ho->n); + if (hook_is_active(ho)) + clist_unlink(&ho->n); } static void @@ -436,8 +437,8 @@ void process_del(struct main_process *mp) { DBG("MAIN: Deleting process %p (pid=%d)", mp, mp->pid); - ASSERT(process_is_active(mp)); - clist_unlink(&mp->n); + if (process_is_active(mp)) + clist_unlink(&mp->n); } int @@ -568,7 +569,8 @@ signal_del_ctx(struct main_context *m, struct main_signal *ms) // XXX: Can be called on a non-current context DBG("MAIN: Deleting signal %p (sig=%d)", ms, ms->signum); - ASSERT(signal_is_active(ms)); + if (!signal_is_active(ms)) + return; clist_unlink(&ms->n); int another = 0; @@ -594,7 +596,7 @@ signal_del(struct main_signal *ms) signal_del_ctx(main_current(), ms); } -#ifdef CONFIG_DEBUG +#ifdef CONFIG_UCW_DEBUG void file_debug(struct main_file *fi)