From: Kristian Høgsberg Date: Thu, 23 Jun 2011 10:43:47 +0000 (-0400) Subject: event-loop: Make idle handlers work again X-Git-Tag: 0.85.0~111 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ff20a0417af35a1614ec761a67160963de6471e0;p=profile%2Fivi%2Fwayland.git event-loop: Make idle handlers work again --- diff --git a/wayland/event-loop.c b/wayland/event-loop.c index 0f41034..615ec1d 100644 --- a/wayland/event-loop.c +++ b/wayland/event-loop.c @@ -38,6 +38,7 @@ struct wl_event_loop { int epoll_fd; struct wl_list check_list; + struct wl_list idle_list; }; struct wl_event_source_interface { @@ -329,32 +330,15 @@ struct wl_event_source_idle { }; static int -wl_event_source_idle_dispatch(struct wl_event_source *source, - struct epoll_event *ep) -{ - struct wl_event_source_idle *idle_source = - (struct wl_event_source_idle *) source; - - idle_source->func(idle_source->base.data); - wl_event_source_remove(&idle_source->base); - - return 1; -} - -static int wl_event_source_idle_remove(struct wl_event_source *source) { - struct wl_event_source_idle *idle_source = - (struct wl_event_source_idle *) source; - - wl_list_remove(&idle_source->base.link); free(source); return 0; } struct wl_event_source_interface idle_source_interface = { - wl_event_source_idle_dispatch, + NULL, wl_event_source_idle_remove }; @@ -374,7 +358,8 @@ wl_event_loop_add_idle(struct wl_event_loop *loop, source->func = func; source->base.data = data; - wl_event_source_check(&source->base); + + wl_list_insert(loop->idle_list.prev, &source->base.link); return &source->base; } @@ -411,6 +396,7 @@ wl_event_loop_create(void) return NULL; } wl_list_init(&loop->check_list); + wl_list_init(&loop->idle_list); return loop; } @@ -437,6 +423,17 @@ post_dispatch_check(struct wl_event_loop *loop) return n; } +static void +dispatch_idle_sources(struct wl_event_loop *loop) +{ + struct wl_event_source_idle *source, *next; + + wl_list_for_each_safe(source, next, &loop->idle_list, base.link) { + source->func(source->base.data); + wl_event_source_remove(&source->base); + } +} + WL_EXPORT int wl_event_loop_dispatch(struct wl_event_loop *loop, int timeout) { @@ -444,6 +441,8 @@ wl_event_loop_dispatch(struct wl_event_loop *loop, int timeout) struct wl_event_source *source; int i, count, n; + dispatch_idle_sources(loop); + count = epoll_wait(loop->epoll_fd, ep, ARRAY_LENGTH(ep), timeout); if (count < 0) return -1;