[Xcb-commit] 4 commits - configure.ac src

Jamey Sharp jamey at kemper.freedesktop.org
Fri Mar 18 22:51:58 PDT 2011


 configure.ac |    1 
 src/xcb.h    |   35 +++++++++++++++++
 src/xcb_in.c |  119 +++++++++++++++++++++++++++++++++++++++--------------------
 src/xcbint.h |    2 
 4 files changed, 118 insertions(+), 39 deletions(-)

New commits:
commit 2415c11dec5e5adb0c17f98aa52fbb371a4f8f23
Author: Jamey Sharp <jamey at minilop.net>
Date:   Fri Mar 18 20:56:07 2011 -0700

    Introduce xcb_wait_for_event_until, for consuming responses in wire-order.
    
    Signed-off-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Josh Triplett <josh at freedesktop.org>

diff --git a/src/xcb.h b/src/xcb.h
index 14244a7..3e61ebd 100644
--- a/src/xcb.h
+++ b/src/xcb.h
@@ -272,6 +272,41 @@ xcb_generic_event_t *xcb_wait_for_event(xcb_connection_t *c);
 xcb_generic_event_t *xcb_poll_for_event(xcb_connection_t *c);
 
 /**
+ * @brief Returns the next event or error that precedes the given request.
+ * @param c: The connection to the X server.
+ * @param request: The limiting sequence number.
+ * @return The next event from the server.
+ *
+ * Returns the next event or error with a sequence number less than or
+ * equal to the given sequence number, or returns NULL if no such event can
+ * ever arrive. Blocks until either a suitable event or error arrive, or a
+ * response arrives that proves no such event is coming, or an I/O error
+ * occurs.
+ *
+ * After processing a request, the X server sends responses in a specific
+ * order. First come any events that the request generated, then any
+ * replies for the request, then the error response if there is one. After
+ * that, the server may spontaneously send more events with the same
+ * sequence number, which are not related to that request.
+ *
+ * This function will always return events from the pre-reply phase of the
+ * specified request. It may also return events from the unrelated
+ * post-reply stream, as long as they have the same sequence number.
+ *
+ * This function is useful for callers that need to process responses in
+ * wire-order.
+ *
+ * Implementation note: You cannot currently use this function to ensure
+ * that you process responses in exactly wire-order, because depending on
+ * the sequence of calls you make and the timing of server responses,
+ * post-reply events with the same sequence number may be returned as part
+ * of the pre-reply event stream, even though they were separated by a
+ * reply or error. In practice this kind of error is unlikely to matter,
+ * but it may be fixed in the future.
+ */
+xcb_generic_event_t *xcb_wait_for_event_until(xcb_connection_t *c, unsigned int request);
+
+/**
  * @brief Return the error for a request, or NULL if none can ever arrive.
  * @param c: The connection to the X server.
  * @param cookie: The request cookie.
diff --git a/src/xcb_in.c b/src/xcb_in.c
index 1199e23..ca75169 100644
--- a/src/xcb_in.c
+++ b/src/xcb_in.c
@@ -57,6 +57,7 @@
 #endif
 
 struct event_list {
+    uint64_t sequence;
     xcb_generic_event_t *event;
     struct event_list *next;
 };
@@ -125,7 +126,7 @@ static int read_packet(xcb_connection_t *c)
                 c->in.current_reply = 0;
                 c->in.current_reply_tail = &c->in.current_reply;
             }
-            c->in.request_completed = c->in.request_read - 1;
+            c->in.request_completed = c->in.event_responses_completed = c->in.request_read - 1;
         }
 
         while(c->in.pending_replies && 
@@ -140,9 +141,12 @@ static int read_packet(xcb_connection_t *c)
         }
 
         if(genrep.response_type == XCB_ERROR)
-            c->in.request_completed = c->in.request_read;
+            c->in.request_completed = c->in.event_responses_completed = c->in.request_read;
+        else if(genrep.response_type == XCB_REPLY)
+            c->in.event_responses_completed = c->in.request_read;
 
         remove_finished_readers(&c->in.readers, c->in.request_completed);
+        remove_finished_readers(&c->in.event_readers, c->in.event_responses_completed);
     }
 
     if(genrep.response_type == XCB_ERROR || genrep.response_type == XCB_REPLY)
@@ -231,11 +235,15 @@ static int read_packet(xcb_connection_t *c)
         free(buf);
         return 0;
     }
+    event->sequence = c->in.request_read;
     event->event = buf;
     event->next = 0;
     *c->in.events_tail = event;
     c->in.events_tail = &event->next;
-    pthread_cond_signal(&c->in.event_cond);
+    if(c->in.event_readers)
+        pthread_cond_signal(c->in.event_readers->data);
+    else
+        pthread_cond_signal(&c->in.event_cond);
     return 1; /* I have something for you... */
 }
 
@@ -542,6 +550,35 @@ xcb_generic_event_t *xcb_poll_for_event(xcb_connection_t *c)
     return ret;
 }
 
+static xcb_generic_event_t *get_event_until(xcb_connection_t *c, uint64_t request)
+{
+    if(c->in.events && XCB_SEQUENCE_COMPARE(c->in.events->sequence, <=, request))
+        return get_event(c);
+    return 0;
+}
+
+xcb_generic_event_t *xcb_wait_for_event_until(xcb_connection_t *c, unsigned int request)
+{
+    pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+    reader_list reader;
+    xcb_generic_event_t *ret;
+    if(c->has_error)
+        return 0;
+    pthread_mutex_lock(&c->iolock);
+
+    insert_reader(&c->in.event_readers, &reader, widen(c, request), &cond);
+
+    while(!(ret = get_event_until(c, reader.request)) && XCB_SEQUENCE_COMPARE(c->in.event_responses_completed, <, reader.request))
+        if(!_xcb_conn_wait(c, &cond, 0, 0))
+            break;
+
+    remove_reader(&c->in.event_readers, &reader);
+    pthread_cond_destroy(&cond);
+    _xcb_in_wake_up_next_reader(c);
+    pthread_mutex_unlock(&c->iolock);
+    return ret;
+}
+
 xcb_generic_error_t *xcb_request_check(xcb_connection_t *c, xcb_void_cookie_t cookie)
 {
     uint64_t request;
@@ -612,6 +649,8 @@ void _xcb_in_wake_up_next_reader(xcb_connection_t *c)
     int pthreadret;
     if(c->in.readers)
         pthreadret = pthread_cond_signal(c->in.readers->data);
+    else if(c->in.event_readers)
+        pthreadret = pthread_cond_signal(c->in.event_readers->data);
     else
         pthreadret = pthread_cond_signal(&c->in.event_cond);
     assert(pthreadret == 0);
diff --git a/src/xcbint.h b/src/xcbint.h
index 096576c..95f078a 100644
--- a/src/xcbint.h
+++ b/src/xcbint.h
@@ -121,6 +121,7 @@ typedef struct _xcb_in {
 
     uint64_t request_expected;
     uint64_t request_read;
+    uint64_t event_responses_completed;
     uint64_t request_completed;
     struct reply_list *current_reply;
     struct reply_list **current_reply_tail;
@@ -129,6 +130,7 @@ typedef struct _xcb_in {
     struct event_list *events;
     struct event_list **events_tail;
     struct reader_list *readers;
+    struct reader_list *event_readers;
 
     struct pending_reply *pending_replies;
     struct pending_reply **pending_replies_tail;
commit 29a974f212aae9eeff4fde99f110cee08f0312f3
Author: Jamey Sharp <jamey at minilop.net>
Date:   Fri Mar 18 17:36:32 2011 -0700

    Dequeue readers that can't receive any new responses.
    
    Signed-off-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Josh Triplett <josh at freedesktop.org>

diff --git a/src/xcb_in.c b/src/xcb_in.c
index fb55111..1199e23 100644
--- a/src/xcb_in.c
+++ b/src/xcb_in.c
@@ -80,6 +80,17 @@ typedef struct reader_list {
     struct reader_list *next;
 } reader_list;
 
+static void remove_finished_readers(reader_list **prev_reader, uint64_t completed)
+{
+    while(*prev_reader && XCB_SEQUENCE_COMPARE((*prev_reader)->request, <=, completed))
+    {
+        /* If you don't have what you're looking for now, you never
+         * will. Wake up and leave me alone. */
+        pthread_cond_signal((*prev_reader)->data);
+        *prev_reader = (*prev_reader)->next;
+    }
+}
+
 static int read_packet(xcb_connection_t *c)
 {
     xcb_generic_reply_t genrep;
@@ -130,6 +141,8 @@ static int read_packet(xcb_connection_t *c)
 
         if(genrep.response_type == XCB_ERROR)
             c->in.request_completed = c->in.request_read;
+
+        remove_finished_readers(&c->in.readers, c->in.request_completed);
     }
 
     if(genrep.response_type == XCB_ERROR || genrep.response_type == XCB_REPLY)
@@ -194,7 +207,6 @@ static int read_packet(xcb_connection_t *c)
     if( genrep.response_type == XCB_REPLY ||
        (genrep.response_type == XCB_ERROR && pend && (pend->flags & XCB_REQUEST_CHECKED)))
     {
-        reader_list *reader;
         struct reply_list *cur = malloc(sizeof(struct reply_list));
         if(!cur)
         {
@@ -206,17 +218,8 @@ static int read_packet(xcb_connection_t *c)
         cur->next = 0;
         *c->in.current_reply_tail = cur;
         c->in.current_reply_tail = &cur->next;
-        for(reader = c->in.readers; 
-	    reader && 
-	    XCB_SEQUENCE_COMPARE(reader->request, <=, c->in.request_read);
-	    reader = reader->next)
-	{
-            pthread_cond_signal(reader->data);
-            if(reader->request == c->in.request_read)
-            {
-                break;
-            }
-	}
+        if(c->in.readers && c->in.readers->request == c->in.request_read)
+            pthread_cond_signal(c->in.readers->data);
         return 1;
     }
 
commit 131e867fca5cda94e634af69214ad54e066ac871
Author: Jamey Sharp <jamey at minilop.net>
Date:   Fri Mar 18 15:37:34 2011 -0700

    Factor reader_list management out of wait_for_reply.
    
    Later patches will insert reader_list entries from other entry points.
    
    Signed-off-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Josh Triplett <josh at freedesktop.org>

diff --git a/src/xcb_in.c b/src/xcb_in.c
index 7d34429..fb55111 100644
--- a/src/xcb_in.c
+++ b/src/xcb_in.c
@@ -356,6 +356,26 @@ static int poll_for_reply(xcb_connection_t *c, uint64_t request, void **reply, x
     return 1;
 }
 
+static void insert_reader(reader_list **prev_reader, reader_list *reader, uint64_t request, pthread_cond_t *cond)
+{
+    while(*prev_reader && XCB_SEQUENCE_COMPARE((*prev_reader)->request, <=, request))
+        prev_reader = &(*prev_reader)->next;
+    reader->request = request;
+    reader->data = cond;
+    reader->next = *prev_reader;
+    *prev_reader = reader;
+}
+
+static void remove_reader(reader_list **prev_reader, reader_list *reader)
+{
+    while(*prev_reader && XCB_SEQUENCE_COMPARE((*prev_reader)->request, <=, reader->request))
+        if(*prev_reader == reader)
+        {
+            *prev_reader = (*prev_reader)->next;
+            break;
+        }
+}
+
 static void *wait_for_reply(xcb_connection_t *c, uint64_t request, xcb_generic_error_t **e)
 {
     void *ret = 0;
@@ -365,35 +385,14 @@ static void *wait_for_reply(xcb_connection_t *c, uint64_t request, xcb_generic_e
     {
         pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
         reader_list reader;
-        reader_list **prev_reader;
 
-        for(prev_reader = &c->in.readers; 
-	    *prev_reader && 
-	    XCB_SEQUENCE_COMPARE((*prev_reader)->request, <=, request);
-	    prev_reader = &(*prev_reader)->next)
-	{
-            /* empty */;
-	}
-        reader.request = request;
-        reader.data = &cond;
-        reader.next = *prev_reader;
-        *prev_reader = &reader;
+        insert_reader(&c->in.readers, &reader, request, &cond);
 
         while(!poll_for_reply(c, request, &ret, e))
             if(!_xcb_conn_wait(c, &cond, 0, 0))
                 break;
 
-        for(prev_reader = &c->in.readers;
-	    *prev_reader && 
-	    XCB_SEQUENCE_COMPARE((*prev_reader)->request, <=, request);
-	    prev_reader = &(*prev_reader)->next)
-	{
-            if(*prev_reader == &reader)
-            {
-                *prev_reader = (*prev_reader)->next;
-                break;
-            }
-	}
+        remove_reader(&c->in.readers, &reader);
         pthread_cond_destroy(&cond);
     }
 
commit 1469e879655b20351530059538a7b89612028ae2
Author: Jamey Sharp <jamey at minilop.net>
Date:   Fri Mar 18 18:18:41 2011 -0700

    Enable AM_SILENT_RULES on automake 1.11 or newer.
    
    This incantation is supposed to be a no-op on earlier automake versions.
    
    Signed-off-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Josh Triplett <josh at freedesktop.org>

diff --git a/configure.ac b/configure.ac
index 5f91173..3551d4a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -7,6 +7,7 @@ AC_INIT([libxcb],
         [xcb at lists.freedesktop.org])
 AC_CONFIG_SRCDIR([xcb.pc.in])
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
+m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 
 AM_PATH_PYTHON([2.5])
 


More information about the xcb-commit mailing list