diff options
author | Johan Hedberg <johan.hedberg@nokia.com> | 2006-08-20 22:31:34 +0000 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@nokia.com> | 2006-08-20 22:31:34 +0000 |
commit | d93952ad4b8e6ae7e212037ed1b37940560e814c (patch) | |
tree | ca5425fdfc7c889651f08615eae2529c9da91939 /common/glib-ectomy.c | |
parent | ec3ac41ca8876f36cc8869ab1c384980f793c40f (diff) |
Fix processing of the timeout list in GMainContext
Diffstat (limited to 'common/glib-ectomy.c')
-rw-r--r-- | common/glib-ectomy.c | 65 |
1 files changed, 43 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; } |