[RFC wayland 10/12] wayland-client: link all event-queues of each display into a list

David Herrmann dh.herrmann at googlemail.com
Thu Oct 11 14:37:51 PDT 2012


We need access to all event-queues of a single wl_display object. For
instance during connection-errors, we need to be able to wake up all event
queues. Otherwise, they will be stuck waiting for incoming events.

The API user is responsible to keep a wl_display object around until all
event-queues that were created on it are destroyed.

Signed-off-by: David Herrmann <dh.herrmann at googlemail.com>
---
 src/wayland-client.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/wayland-client.c b/src/wayland-client.c
index 2e9681c..c17cea3 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -58,7 +58,9 @@ struct wl_global {
 };
 
 struct wl_event_queue {
+	struct wl_list link;
 	struct wl_list event_list;
+	struct wl_display *display;
 	pthread_cond_t cond;
 };
 
@@ -71,16 +73,18 @@ struct wl_display {
 	pthread_t display_thread;
 	struct wl_map objects;
 	struct wl_event_queue queue;
+	struct wl_list event_queues;
 	pthread_mutex_t mutex;
 };
 
 static int wl_debug = 0;
 
 static void
-wl_event_queue_init(struct wl_event_queue *queue)
+wl_event_queue_init(struct wl_event_queue *queue, struct wl_display *display)
 {
 	wl_list_init(&queue->event_list);
 	pthread_cond_init(&queue->cond, NULL);
+	queue->display = display;
 }
 
 static void
@@ -100,8 +104,13 @@ wl_event_queue_release(struct wl_event_queue *queue)
 WL_EXPORT void
 wl_event_queue_destroy(struct wl_event_queue *queue)
 {
+	struct wl_display *display = queue->display;
+
+	pthread_mutex_lock(&display->mutex);
+	wl_list_remove(&queue->link);
 	wl_event_queue_release(queue);
 	free(queue);
+	pthread_mutex_unlock(&display->mutex);
 }
 
 WL_EXPORT struct wl_event_queue *
@@ -113,7 +122,11 @@ wl_display_create_queue(struct wl_display *display)
 	if (queue == NULL)
 		return NULL;
 
-	wl_event_queue_init(queue);
+	wl_event_queue_init(queue, display);
+
+	pthread_mutex_lock(&display->mutex);
+	wl_list_insert(&display->event_queues, &queue->link);
+	pthread_mutex_unlock(&display->mutex);
 
 	return queue;
 }
@@ -354,7 +367,8 @@ wl_display_connect_to_fd(int fd)
 
 	display->fd = fd;
 	wl_map_init(&display->objects);
-	wl_event_queue_init(&display->queue);
+	wl_event_queue_init(&display->queue, display);
+	wl_list_init(&display->event_queues);
 
 	wl_map_insert_new(&display->objects, WL_MAP_CLIENT_SIDE, NULL);
 
-- 
1.7.12.2



More information about the wayland-devel mailing list