[Xcb] [RFC libxcb 1/5] Merge xcb_wait_for_event and poll_for_next_event
Daniel Martin
consume.noise at gmail.com
Tue Jun 4 15:52:02 PDT 2013
Merge the functionality of
xcb_wait_for_event() and
poll_for_next_event()
into
get_event_locked()
and make
xcb_wait_for_event(),
xcb_poll_for_event() and
xcb_poll_for_queued_event()
wrappers around
get_event_locked().
It's done to streamline the internal event pickup and prepares for
another wrapper.
Signed-off-by: Daniel Martin <consume.noise at gmail.com>
---
src/xcb.h | 7 +++++++
src/xcb_in.c | 63 ++++++++++++++++++++++++++++++++----------------------------
2 files changed, 41 insertions(+), 29 deletions(-)
diff --git a/src/xcb.h b/src/xcb.h
index f7dc6af..5419813 100644
--- a/src/xcb.h
+++ b/src/xcb.h
@@ -264,6 +264,13 @@ void xcb_prefetch_maximum_request_length(xcb_connection_t *c);
/* xcb_in.c */
+/* Atm. internally used only */
+typedef enum xcb_rcv_style_t {
+ XCB_RCV_QUEUED,
+ XCB_RCV_POLL,
+ XCB_RCV_WAIT
+} xcb_rcv_style_t;
+
/**
* @brief Returns the next event or error from the server.
* @param c: The connection to the X server.
diff --git a/src/xcb_in.c b/src/xcb_in.c
index 8a7af92..a9d7c51 100644
--- a/src/xcb_in.c
+++ b/src/xcb_in.c
@@ -257,6 +257,37 @@ static xcb_generic_event_t *get_event(xcb_connection_t *c)
return ret;
}
+static xcb_generic_event_t *get_event_locked(xcb_connection_t *c, xcb_rcv_style_t style)
+{
+ xcb_generic_event_t *ret = NULL;
+
+ if(c->has_error)
+ return NULL;
+
+ pthread_mutex_lock(&c->iolock);
+
+ ret = get_event(c, full_sequence);
+
+ if(!ret && style == XCB_RCV_POLL)
+ {
+ /* FIXME: follow X meets Z architecture changes. */
+ if(c->in.reading == 0 && _xcb_in_read(c)) /* _xcb_in_read shuts down the connection on error */
+ ret = get_event(c, full_sequence);
+ } else
+ if(!ret && style == XCB_RCV_WAIT)
+ {
+ /* get_event returns 0 on empty list. */
+ while(!(ret = get_event(c, full_sequence)))
+ if(!_xcb_conn_wait(c, &c->in.event_cond, 0, 0))
+ break;
+ _xcb_in_wake_up_next_reader(c);
+ }
+
+ pthread_mutex_unlock(&c->iolock);
+
+ return ret;
+}
+
static void free_reply_list(struct reply_list *head)
{
while(head)
@@ -517,43 +548,17 @@ int xcb_poll_for_reply(xcb_connection_t *c, unsigned int request, void **reply,
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);
- /* get_event returns 0 on empty list. */
- while(!(ret = get_event(c)))
- if(!_xcb_conn_wait(c, &c->in.event_cond, 0, 0))
- break;
-
- _xcb_in_wake_up_next_reader(c);
- pthread_mutex_unlock(&c->iolock);
- return ret;
-}
-
-static xcb_generic_event_t *poll_for_next_event(xcb_connection_t *c, int queued)
-{
- xcb_generic_event_t *ret = 0;
- if(!c->has_error)
- {
- pthread_mutex_lock(&c->iolock);
- /* FIXME: follow X meets Z architecture changes. */
- ret = get_event(c);
- if(!ret && !queued && c->in.reading == 0 && _xcb_in_read(c)) /* _xcb_in_read shuts down the connection on error */
- ret = get_event(c);
- pthread_mutex_unlock(&c->iolock);
- }
- return ret;
+ return get_event_locked(c, XCB_RCV_WAIT);
}
xcb_generic_event_t *xcb_poll_for_event(xcb_connection_t *c)
{
- return poll_for_next_event(c, 0);
+ return get_event_locked(c, XCB_RCV_POLL);
}
xcb_generic_event_t *xcb_poll_for_queued_event(xcb_connection_t *c)
{
- return poll_for_next_event(c, 1);
+ return get_event_locked(c, XCB_RCV_QUEUED);
}
xcb_generic_error_t *xcb_request_check(xcb_connection_t *c, xcb_void_cookie_t cookie)
--
1.8.3
More information about the Xcb
mailing list