mirror of
				https://gitlab.freedesktop.org/wayland/wayland.git
				synced 2025-11-03 09:01:42 -05:00 
			
		
		
		
	event-loop: Make idle handlers work again
This commit is contained in:
		
							parent
							
								
									b6fdded54b
								
							
						
					
					
						commit
						ff20a0417a
					
				
					 1 changed files with 18 additions and 19 deletions
				
			
		| 
						 | 
				
			
			@ -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 {
 | 
			
		||||
| 
						 | 
				
			
			@ -328,33 +329,16 @@ struct wl_event_source_idle {
 | 
			
		|||
	wl_event_loop_idle_func_t func;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue