Factor out pthread_mutex_lock and unlock calls for the iolock.
authorJamey Sharp <jamey@minilop.net>
Wed, 4 Oct 2006 19:23:45 +0000 (12:23 -0700)
committerJamey Sharp <jamey@minilop.net>
Wed, 4 Oct 2006 21:52:49 +0000 (14:52 -0700)
src/xcb_conn.c
src/xcb_in.c
src/xcb_out.c
src/xcbint.h

index 9aa7cdf..3d18369 100644 (file)
@@ -97,12 +97,12 @@ static int write_setup(xcb_connection_t *c, xcb_auth_info_t *auth_info)
     }
     assert(count <= sizeof(parts) / sizeof(*parts));
 
-    pthread_mutex_lock(&c->iolock);
+    _xcb_lock_io(c);
     {
         struct iovec *parts_ptr = parts;
         ret = _xcb_out_send(c, &parts_ptr, &count);
     }
-    pthread_mutex_unlock(&c->iolock);
+    _xcb_unlock_io(c);
     return ret;
 }
 
@@ -255,6 +255,16 @@ void _xcb_conn_shutdown(xcb_connection_t *c)
     c->has_error = 1;
 }
 
+void _xcb_lock_io(xcb_connection_t *c)
+{
+    pthread_mutex_lock(&c->iolock);
+}
+
+void _xcb_unlock_io(xcb_connection_t *c)
+{
+    pthread_mutex_unlock(&c->iolock);
+}
+
 int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vector, int *count)
 {
     int ret;
@@ -278,7 +288,7 @@ int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vec
         ++c->out.writing;
     }
 
-    pthread_mutex_unlock(&c->iolock);
+    _xcb_unlock_io(c);
     do {
        ret = select(c->fd + 1, &rfds, &wfds, 0, 0);
     } while (ret == -1 && errno == EINTR);
@@ -287,7 +297,7 @@ int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vec
         _xcb_conn_shutdown(c);
        ret = 0;
     }
-    pthread_mutex_lock(&c->iolock);
+    _xcb_lock_io(c);
 
     if(ret)
     {
index 604faab..41764df 100644 (file)
@@ -318,7 +318,7 @@ void *xcb_wait_for_reply(xcb_connection_t *c, unsigned int request, xcb_generic_
     if(c->has_error)
         return 0;
 
-    pthread_mutex_lock(&c->iolock);
+    _xcb_lock_io(c);
 
     /* If this request has not been written yet, write it. */
     if(_xcb_out_flush_to(c, request))
@@ -358,7 +358,7 @@ void *xcb_wait_for_reply(xcb_connection_t *c, unsigned int request, xcb_generic_
     }
 
     wake_up_next_reader(c);
-    pthread_mutex_unlock(&c->iolock);
+    _xcb_unlock_io(c);
     return ret;
 }
 
@@ -373,9 +373,9 @@ int xcb_poll_for_reply(xcb_connection_t *c, unsigned int request, void **reply,
         return 1; /* would not block */
     }
     assert(reply != 0);
-    pthread_mutex_lock(&c->iolock);
+    _xcb_lock_io(c);
     ret = poll_for_reply(c, request, reply, error);
-    pthread_mutex_unlock(&c->iolock);
+    _xcb_unlock_io(c);
     return ret;
 }
 
@@ -384,14 +384,14 @@ xcb_generic_event_t *xcb_wait_for_event(xcb_connection_t *c)
     xcb_generic_event_t *ret;
     if(c->has_error)
         return 0;
-    pthread_mutex_lock(&c->iolock);
+    _xcb_lock_io(c);
     /* get_event returns 0 on empty list. */
     while(!(ret = get_event(c)))
         if(!_xcb_conn_wait(c, &c->in.event_cond, 0, 0))
             break;
 
     wake_up_next_reader(c);
-    pthread_mutex_unlock(&c->iolock);
+    _xcb_unlock_io(c);
     return ret;
 }
 
@@ -401,12 +401,12 @@ xcb_generic_event_t *xcb_poll_for_event(xcb_connection_t *c, int *error)
     {
         xcb_generic_event_t *ret = 0;
         int success;
-        pthread_mutex_lock(&c->iolock);
+        _xcb_lock_io(c);
         /* FIXME: follow X meets Z architecture changes. */
         success = _xcb_in_read(c);
         if(success)
             ret = get_event(c);
-        pthread_mutex_unlock(&c->iolock);
+        _xcb_unlock_io(c);
         if(success)
         {
             if(error)
index 162abd4..74787e3 100644 (file)
@@ -163,7 +163,7 @@ unsigned int xcb_send_request(xcb_connection_t *c, int flags, struct iovec *vect
         workaround = WORKAROUND_GLX_GET_FB_CONFIGS_BUG;
 
     /* get a sequence number and arrange for delivery. */
-    pthread_mutex_lock(&c->iolock);
+    _xcb_lock_io(c);
     /* wait for other writing threads to get out of my way. */
     while(c->out.writing)
         pthread_cond_wait(&c->out.cond, &c->iolock);
@@ -207,7 +207,7 @@ unsigned int xcb_send_request(xcb_connection_t *c, int flags, struct iovec *vect
         _xcb_conn_shutdown(c);
         request = 0;
     }
-    pthread_mutex_unlock(&c->iolock);
+    _xcb_unlock_io(c);
     return request;
 }
 
@@ -216,9 +216,9 @@ int xcb_flush(xcb_connection_t *c)
     int ret;
     if(c->has_error)
         return 0;
-    pthread_mutex_lock(&c->iolock);
+    _xcb_lock_io(c);
     ret = _xcb_out_flush_to(c, c->out.request);
-    pthread_mutex_unlock(&c->iolock);
+    _xcb_unlock_io(c);
     return ret;
 }
 
index 1a71696..1dc6f93 100644 (file)
@@ -159,6 +159,8 @@ struct xcb_connection_t {
 };
 
 void _xcb_conn_shutdown(xcb_connection_t *c);
+void _xcb_lock_io(xcb_connection_t *c);
+void _xcb_unlock_io(xcb_connection_t *c);
 int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vector, int *count);