summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Ådahl <jadahl@gmail.com>2015-10-02 17:11:13 +0800
committerJonas Ådahl <jadahl@gmail.com>2016-01-16 16:37:36 +0800
commit689fff36ca7d2967b4f2724f731df1391df4f337 (patch)
tree107ce590e43c1c19751d578a7f047eb25744ef61
parentc767f35b122737d282125f0b864caf552c21e0eb (diff)
downloadwayland-689fff36ca7d2967b4f2724f731df1391df4f337.tar.gz
client: Use read preparation API in wl_display_dispatch_queue()
Instead of doing things that do the equivalent of using wl_display_prepare_read() and friends, just use the public API. The only semantical difference is that we will now unlock and lock the mutex more times compared to before. Signed-off-by: Jonas Ådahl <jadahl@gmail.com> Reviewed-by: Daniel Stone <daniels@collabora.com>
-rw-r--r--src/wayland-client.c45
1 files changed, 10 insertions, 35 deletions
diff --git a/src/wayland-client.c b/src/wayland-client.c
index 69f91a6..18a837a 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -1488,30 +1488,17 @@ wl_display_dispatch_queue(struct wl_display *display,
struct pollfd pfd[2];
int ret;
- pthread_mutex_lock(&display->mutex);
-
- ret = dispatch_queue(display, queue);
- if (ret == -1)
- goto err_unlock;
- if (ret > 0) {
- pthread_mutex_unlock(&display->mutex);
- return ret;
- }
+ if (wl_display_prepare_read_queue(display, queue) == -1)
+ return wl_display_dispatch_queue_pending(display, queue);
- /* We ignore EPIPE here, so that we try to read events before
- * returning an error. When the compositor sends an error it
- * will close the socket, and if we bail out here we don't get
- * a chance to process the error. */
- ret = wl_connection_flush(display->connection);
+ /* Don't stop if flushing hits an EPIPE; continue so we can read any
+ * protocol error that may have triggered it. */
+ ret = wl_display_flush(display);
if (ret < 0 && errno != EAGAIN && errno != EPIPE) {
- display_fatal_error(display, errno);
- goto err_unlock;
+ wl_display_cancel_read(display);
+ return -1;
}
- display->reader_count++;
-
- pthread_mutex_unlock(&display->mutex);
-
pfd[0].fd = display->fd;
pfd[0].events = POLLIN;
do {
@@ -1523,22 +1510,10 @@ wl_display_dispatch_queue(struct wl_display *display,
return -1;
}
- pthread_mutex_lock(&display->mutex);
-
- if (read_events(display) == -1)
- goto err_unlock;
-
- ret = dispatch_queue(display, queue);
- if (ret == -1)
- goto err_unlock;
-
- pthread_mutex_unlock(&display->mutex);
-
- return ret;
+ if (wl_display_read_events(display) == -1)
+ return -1;
- err_unlock:
- pthread_mutex_unlock(&display->mutex);
- return -1;
+ return wl_display_dispatch_queue_pending(display, queue);
}
/** Dispatch pending events in an event queue