diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/glib-ectomy.c | 65 | ||||
-rw-r--r-- | common/glib-ectomy.h | 1 |
2 files changed, 44 insertions, 22 deletions
diff --git a/common/glib-ectomy.c b/common/glib-ectomy.c index f90973ba..f4e552cd 100644 --- a/common/glib-ectomy.c +++ b/common/glib-ectomy.c @@ -230,21 +230,26 @@ static int timeout_cmp(const void *t1, const void *t2) static void timeout_handlers_check(GMainContext *context) { - struct slist *l = context->ltimeout; struct timeout *t; struct timeval tv; gettimeofday(&tv, NULL); - while (l) { + context->processed = NULL; + + while (context->ltimeout) { struct slist *match; + glong secs, msecs; gboolean ret; - t = l->data; - l = l->next; + t = context->ltimeout->data; + + context->ltimeout = slist_remove(context->ltimeout, t); - if (timercmp(&tv, &t->expiration, <)) + if (timercmp(&tv, &t->expiration, <)) { + context->processed = slist_append(context->processed, t); continue; + } ret = t->function(t->data); @@ -255,26 +260,27 @@ static void timeout_handlers_check(GMainContext *context) if (!match) continue; - /* Update next pointer if callback changed the list */ - l = match->next; - - if (ret == FALSE) { - context->ltimeout = slist_remove(context->ltimeout, t); + if (!ret) { free(t); - } else { - glong secs, msecs; - /* update the next expiration time */ - secs = t->interval / 1000; - msecs = t->interval - secs * 1000; - - t->expiration.tv_sec = tv.tv_sec + secs; - t->expiration.tv_usec = tv.tv_usec + msecs * 1000; - if (t->expiration.tv_usec >= 1000000) { - t->expiration.tv_usec -= 1000000; - t->expiration.tv_sec++; - } + continue; } + + /* update the next expiration time */ + secs = t->interval / 1000; + msecs = t->interval - secs * 1000; + + t->expiration.tv_sec = tv.tv_sec + secs; + t->expiration.tv_usec = tv.tv_usec + msecs * 1000; + if (t->expiration.tv_usec >= 1000000) { + t->expiration.tv_usec -= 1000000; + t->expiration.tv_sec++; + } + + context->processed = slist_append(context->processed, t); } + + context->ltimeout = context->processed; + context->processed = NULL; } void g_main_loop_run(GMainLoop *loop) @@ -420,5 +426,20 @@ gint g_timeout_remove(const guint id) return 0; } + l = default_context->processed; + + while (l) { + t = l->data; + l = l->next; + + if (t->id != id) + continue; + + default_context->processed = slist_remove(default_context->processed, t); + free(t); + + return 0; + } + return -1; } diff --git a/common/glib-ectomy.h b/common/glib-ectomy.h index f52a9ce2..af6f4fbb 100644 --- a/common/glib-ectomy.h +++ b/common/glib-ectomy.h @@ -48,6 +48,7 @@ typedef struct _GMainContext { guint next_id; glong timeout; struct slist *ltimeout; + struct slist *processed; } GMainContext; typedef struct _GMainLoop { |