|
|
|
@ -11,18 +11,20 @@ |
|
|
|
|
|
|
|
|
|
struct wl_event_loop { |
|
|
|
|
int epoll_fd; |
|
|
|
|
wl_event_loop_idle_func_t idle_func; |
|
|
|
|
void *idle_data; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
struct wl_event_source { |
|
|
|
|
int fd; |
|
|
|
|
wl_event_loop_func_t func; |
|
|
|
|
wl_event_loop_fd_func_t func; |
|
|
|
|
void *data; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
struct wl_event_source * |
|
|
|
|
wl_event_loop_add_fd(struct wl_event_loop *loop, |
|
|
|
|
int fd, uint32_t mask, |
|
|
|
|
wl_event_loop_func_t func, |
|
|
|
|
wl_event_loop_fd_func_t func, |
|
|
|
|
void *data) |
|
|
|
|
{ |
|
|
|
|
struct wl_event_source *source; |
|
|
|
@ -48,16 +50,23 @@ wl_event_loop_add_fd(struct wl_event_loop *loop, |
|
|
|
|
return source; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct wl_event_source idle_source; |
|
|
|
|
|
|
|
|
|
int |
|
|
|
|
wl_event_loop_remove_source(struct wl_event_loop *loop, |
|
|
|
|
struct wl_event_source *source) |
|
|
|
|
{ |
|
|
|
|
int fd; |
|
|
|
|
|
|
|
|
|
fd = source->fd; |
|
|
|
|
free(source); |
|
|
|
|
|
|
|
|
|
return epoll_ctl(loop->epoll_fd, EPOLL_CTL_DEL, fd, NULL); |
|
|
|
|
if (source == &idle_source) { |
|
|
|
|
loop->idle_func = NULL; |
|
|
|
|
return 0; |
|
|
|
|
} else { |
|
|
|
|
fd = source->fd; |
|
|
|
|
free(source); |
|
|
|
|
return epoll_ctl(loop->epoll_fd, |
|
|
|
|
EPOLL_CTL_DEL, fd, NULL); |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int |
|
|
|
@ -103,6 +112,17 @@ wl_event_loop_destroy(struct wl_event_loop *loop) |
|
|
|
|
free(loop); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct wl_event_source * |
|
|
|
|
wl_event_loop_add_idle(struct wl_event_loop *loop, |
|
|
|
|
wl_event_loop_idle_func_t func, |
|
|
|
|
void *data) |
|
|
|
|
{ |
|
|
|
|
loop->idle_func = func; |
|
|
|
|
loop->idle_data = data; |
|
|
|
|
|
|
|
|
|
return &idle_source; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) |
|
|
|
|
|
|
|
|
|
int |
|
|
|
@ -110,10 +130,15 @@ wl_event_loop_wait(struct wl_event_loop *loop) |
|
|
|
|
{ |
|
|
|
|
struct epoll_event ep[32]; |
|
|
|
|
struct wl_event_source *source; |
|
|
|
|
int i, count; |
|
|
|
|
int i, count, timeout; |
|
|
|
|
uint32_t mask; |
|
|
|
|
|
|
|
|
|
count = epoll_wait(loop->epoll_fd, ep, ARRAY_LENGTH(ep), -1); |
|
|
|
|
if (loop->idle_func) |
|
|
|
|
timeout = 0; |
|
|
|
|
else |
|
|
|
|
timeout = -1; |
|
|
|
|
|
|
|
|
|
count = epoll_wait(loop->epoll_fd, ep, ARRAY_LENGTH(ep), timeout); |
|
|
|
|
if (count < 0) |
|
|
|
|
return -1; |
|
|
|
|
|
|
|
|
@ -128,5 +153,10 @@ wl_event_loop_wait(struct wl_event_loop *loop) |
|
|
|
|
source->func(source->fd, mask, source->data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (count == 0 && loop->idle_func != NULL) { |
|
|
|
|
loop->idle_func(loop->idle_data); |
|
|
|
|
loop->idle_func = NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|