diff options
author | Jamey Sharp <jamey@minilop.net> | 2006-04-19 16:49:32 -0700 |
---|---|---|
committer | Jamey Sharp <jamey@minilop.net> | 2006-04-19 16:49:32 -0700 |
commit | 7667adbc631119ec39f3ef5a316aec42dbf5f393 (patch) | |
tree | 9d1d6a5114988ed88a95bc52089a00d6145cd615 /src | |
parent | 53971ea183d9d1dcfbaec18b135e49c9c118fabb (diff) |
Add XCBPollForReply and deprecate XCBGetRequestRead and XCBGetQueuedRequestRead.
Diffstat (limited to 'src')
-rw-r--r-- | src/xcb.h | 5 | ||||
-rw-r--r-- | src/xcb_in.c | 55 | ||||
-rw-r--r-- | src/xcbext.h | 1 | ||||
-rw-r--r-- | src/xcbxlib.h | 2 |
4 files changed, 60 insertions, 3 deletions
@@ -273,9 +273,10 @@ XCBGenericEvent *XCBPollForEvent(XCBConnection *c, int *error); * processed. This function enables applications to determine whether * forcing a cookie is going to block. * - * @todo review that function. + * @deprecated This function is deprecated in favor of XCBPollForReply. + * It must not be used in newly written code. */ -unsigned int XCBGetRequestRead(XCBConnection *c); +unsigned int XCBGetRequestRead(XCBConnection *c) deprecated; /* xcb_ext.c */ diff --git a/src/xcb_in.c b/src/xcb_in.c index 76f9702..4ad4654 100644 --- a/src/xcb_in.c +++ b/src/xcb_in.c @@ -239,6 +239,51 @@ static int read_block(const int fd, void *buf, const size_t len) return len; } +static int poll_for_reply(XCBConnection *c, unsigned int request, void **reply, XCBGenericError **error) +{ + struct reply_list *head; + + if(!request) + head = 0; + else if(c->in.request_completed >= request) + { + head = _xcb_map_remove(c->in.replies, request); + if(head && head->next) + _xcb_map_put(c->in.replies, request, head->next); + } + else if(c->in.request_read == request && c->in.current_reply) + { + head = c->in.current_reply; + c->in.current_reply = head->next; + if(!head->next) + c->in.current_reply_tail = &c->in.current_reply; + } + else + /* Would block: do nothing. */ + return 0; + + if(error) + *error = 0; + *reply = 0; + + if(head) + { + if(((XCBGenericRep *) head->reply)->response_type == XCBError) + { + if(error) + *error = head->reply; + else + free(head->reply); + } + else + *reply = head->reply; + + free(head); + } + + return 1; +} + /* Public interface */ void *XCBWaitForReply(XCBConnection *c, unsigned int request, XCBGenericError **e) @@ -323,6 +368,16 @@ done: return ret; } +int XCBPollForReply(XCBConnection *c, unsigned int request, void **reply, XCBGenericError **error) +{ + int ret; + assert(reply != 0); + pthread_mutex_lock(&c->iolock); + ret = poll_for_reply(c, request, reply, error); + pthread_mutex_unlock(&c->iolock); + return ret; +} + XCBGenericEvent *XCBWaitEvent(XCBConnection *c) { return XCBWaitForEvent(c); diff --git a/src/xcbext.h b/src/xcbext.h index 0d172e9..508ebf0 100644 --- a/src/xcbext.h +++ b/src/xcbext.h @@ -63,6 +63,7 @@ unsigned int XCBSendRequest(XCBConnection *c, int flags, struct iovec *vector, c /* xcb_in.c */ void *XCBWaitForReply(XCBConnection *c, unsigned int request, XCBGenericError **e); +int XCBPollForReply(XCBConnection *c, unsigned int request, void **reply, XCBGenericError **error); /* xcb_xid.c */ diff --git a/src/xcbxlib.h b/src/xcbxlib.h index 462e2e3..4ceb03e 100644 --- a/src/xcbxlib.h +++ b/src/xcbxlib.h @@ -32,7 +32,7 @@ #include "xcb.h" /* This function must be called with the IOLock held. */ -unsigned int XCBGetQueuedRequestRead(XCBConnection *c); +unsigned int XCBGetQueuedRequestRead(XCBConnection *c) deprecated; /* This function must be called with the IOLock held. */ unsigned int XCBGetRequestSent(XCBConnection *c); |