[PATCH v2] client: check for error before prepare/read
Marek Chalupa
mchqwerty at gmail.com
Fri Aug 22 04:17:35 PDT 2014
This prevents from blocking shown in one display test. Also, it
makes sense to not proceed further in the code of these function
when an error occurred.
v2. set errno
put note about the errno into doc
check for error with mutex locked
Signed-off-by: Marek Chalupa <mchqwerty at gmail.com>
---
src/wayland-client.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/wayland-client.c b/src/wayland-client.c
index 2252424..fae44c3 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -1206,6 +1206,14 @@ wl_display_read_events(struct wl_display *display)
pthread_mutex_lock(&display->mutex);
+ if (display->last_error) {
+ pthread_mutex_unlock(&display->mutex);
+
+ errno = ECANCELED;
+ return -1;
+ }
+
+
ret = read_events(display);
pthread_mutex_unlock(&display->mutex);
@@ -1252,6 +1260,13 @@ wl_display_prepare_read_queue(struct wl_display *display,
pthread_mutex_lock(&display->mutex);
+ if (display->last_error) {
+ pthread_mutex_unlock(&display->mutex);
+
+ errno = ECANCELED;
+ return -1;
+ }
+
if (!wl_list_empty(&queue->event_list)) {
errno = EAGAIN;
ret = -1;
@@ -1268,7 +1283,7 @@ wl_display_prepare_read_queue(struct wl_display *display,
/** Prepare to read events after polling file descriptor
*
* \param display The display context object
- * \return 0 on success or -1 if event queue was not empty
+ * \return 0 on success or -1 with errno set accordingly
*
* This function must be called before reading from the file
* descriptor using wl_display_read_events(). Calling
@@ -1277,7 +1292,8 @@ wl_display_prepare_read_queue(struct wl_display *display,
* calls wl_display_read_events(), no other thread will read from the
* file descriptor. This only succeeds if the event queue is empty
* though, and if there are undispatched events in the queue, -1 is
- * returned and errno set to EAGAIN.
+ * returned and errno set to EAGAIN. If an error ocurred on the display,
+ * -1 is returned and errno is set to ECANCELED.
*
* If a thread successfully calls wl_display_prepare_read(), it must
* either call wl_display_read_events() when it's ready or cancel the
--
2.0.4
More information about the wayland-devel
mailing list