[Xcb] [PATCH 3/3] fix pthread_cond_wait and get_socket_back dependency

Christian König deathsimple at vodafone.de
Wed May 15 02:21:37 PDT 2013


From: Christian König <christian.koenig at amd.com>

Both functions may drop the iolock, so it is possible that somebody else has
acquired the socket or started writing data.

Signed-off-by: Christian König <christian.koenig at amd.com>
---
 src/xcb_out.c |   16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/xcb_out.c b/src/xcb_out.c
index 429fa99..b9901ca 100644
--- a/src/xcb_out.c
+++ b/src/xcb_out.c
@@ -239,10 +239,12 @@ unsigned int xcb_send_request(xcb_connection_t *c, int flags, struct iovec *vect
 
     /* get a sequence number and arrange for delivery. */
     pthread_mutex_lock(&c->iolock);
+    get_socket_back(c);
     /* wait for other writing threads to get out of my way. */
-    while(c->out.writing)
+    while(c->out.writing) {
         pthread_cond_wait(&c->out.cond, &c->iolock);
-    get_socket_back(c);
+        get_socket_back(c);
+    }
 
     /* send GetInputFocus (sync_req) when 64k-2 requests have been sent without
      * a reply. */
@@ -357,10 +359,12 @@ int _xcb_out_send(xcb_connection_t *c, struct iovec *vector, int count)
 
 void _xcb_out_send_sync(xcb_connection_t *c)
 {
+    get_socket_back(c);
     /* wait for other writing threads to get out of my way. */
-    while(c->out.writing)
+    while(c->out.writing) {
         pthread_cond_wait(&c->out.cond, &c->iolock);
-    get_socket_back(c);
+        get_socket_back(c);
+    }
     send_sync(c);
 }
 
@@ -377,8 +381,10 @@ int _xcb_out_flush_to(xcb_connection_t *c, uint64_t request)
         c->out.queue_len = 0;
         return _xcb_out_send(c, &vec, 1);
     }
-    while(c->out.writing)
+    while(c->out.writing) {
         pthread_cond_wait(&c->out.cond, &c->iolock);
+        get_socket_back(c);
+    }
     assert(XCB_SEQUENCE_COMPARE(c->out.request_written, >=, request));
     return 1;
 }
-- 
1.7.9.5



More information about the Xcb mailing list