Make the server event loop embeddable

By exposing the epoll fd, we can embed the server event loop in other
main loops suchs as Qt or GTK+.
dev
Kristian Høgsberg 14 years ago
parent 67f4ffdf03
commit b163cef6e7
  1. 45
      wayland/event-loop.c
  2. 2
      wayland/wayland-server.c
  3. 3
      wayland/wayland-server.h

@ -409,36 +409,13 @@ wl_event_loop_destroy(struct wl_event_loop *loop)
free(loop); free(loop);
} }
static void
dispatch_idles(struct wl_event_loop *loop)
{
struct wl_event_source_idle *source, *next;
source = container_of(loop->idle_list.next,
struct wl_event_source_idle, link);
while (&source->link != &loop->idle_list) {
source->func(source->data);
next = container_of(source->link.next,
struct wl_event_source_idle, link);
free(source);
source = next;
}
wl_list_init(&loop->idle_list);
}
WL_EXPORT int WL_EXPORT int
wl_event_loop_wait(struct wl_event_loop *loop) wl_event_loop_dispatch(struct wl_event_loop *loop, int timeout)
{ {
struct epoll_event ep[32]; struct epoll_event ep[32];
struct wl_event_source *source; struct wl_event_source *source;
int i, count, timeout; struct wl_event_source_idle *idle;
int i, count;
if (wl_list_empty(&loop->idle_list))
timeout = -1;
else
timeout = 0;
count = epoll_wait(loop->epoll_fd, ep, ARRAY_LENGTH(ep), timeout); count = epoll_wait(loop->epoll_fd, ep, ARRAY_LENGTH(ep), timeout);
if (count < 0) if (count < 0)
@ -449,9 +426,19 @@ wl_event_loop_wait(struct wl_event_loop *loop)
source->interface->dispatch(source, &ep[i]); source->interface->dispatch(source, &ep[i]);
} }
if (count == 0) while (!wl_list_empty(&loop->idle_list)) {
dispatch_idles(loop); idle = container_of(loop->idle_list.next,
struct wl_event_source_idle, link);
wl_list_remove(&idle->link);
idle->func(idle->data);
free(idle);
}
return 0; return 0;
} }
WL_EXPORT int
wl_event_loop_get_fd(struct wl_event_loop *loop)
{
return loop->epoll_fd;
}

@ -436,7 +436,7 @@ WL_EXPORT void
wl_display_run(struct wl_display *display) wl_display_run(struct wl_display *display)
{ {
while (1) while (1)
wl_event_loop_wait(display->loop); wl_event_loop_dispatch(display->loop, -1);
} }
static void static void

@ -70,10 +70,11 @@ int wl_event_source_timer_update(struct wl_event_source *source,
int wl_event_source_remove(struct wl_event_source *source); int wl_event_source_remove(struct wl_event_source *source);
int wl_event_loop_wait(struct wl_event_loop *loop); int wl_event_loop_dispatch(struct wl_event_loop *loop, int timeout);
struct wl_event_source *wl_event_loop_add_idle(struct wl_event_loop *loop, struct wl_event_source *wl_event_loop_add_idle(struct wl_event_loop *loop,
wl_event_loop_idle_func_t func, wl_event_loop_idle_func_t func,
void *data); void *data);
int wl_event_get_fd(struct wl_event_loop *loop);
struct wl_client; struct wl_client;
struct wl_display; struct wl_display;

Loading…
Cancel
Save