Add XCBPollForReply and deprecate XCBGetRequestRead and XCBGetQueuedRequestRead.

This commit is contained in:
Jamey Sharp 2006-04-19 16:49:32 -07:00
parent 53971ea183
commit 7667adbc63
4 changed files with 60 additions and 3 deletions

View File

@ -273,9 +273,10 @@ XCBGenericEvent *XCBPollForEvent(XCBConnection *c, int *error);
* processed. This function enables applications to determine whether * processed. This function enables applications to determine whether
* forcing a cookie is going to block. * 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 */ /* xcb_ext.c */

View File

@ -239,6 +239,51 @@ static int read_block(const int fd, void *buf, const size_t len)
return 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 */ /* Public interface */
void *XCBWaitForReply(XCBConnection *c, unsigned int request, XCBGenericError **e) void *XCBWaitForReply(XCBConnection *c, unsigned int request, XCBGenericError **e)
@ -323,6 +368,16 @@ done:
return ret; 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) XCBGenericEvent *XCBWaitEvent(XCBConnection *c)
{ {
return XCBWaitForEvent(c); return XCBWaitForEvent(c);

View File

@ -63,6 +63,7 @@ unsigned int XCBSendRequest(XCBConnection *c, int flags, struct iovec *vector, c
/* xcb_in.c */ /* xcb_in.c */
void *XCBWaitForReply(XCBConnection *c, unsigned int request, XCBGenericError **e); void *XCBWaitForReply(XCBConnection *c, unsigned int request, XCBGenericError **e);
int XCBPollForReply(XCBConnection *c, unsigned int request, void **reply, XCBGenericError **error);
/* xcb_xid.c */ /* xcb_xid.c */

View File

@ -32,7 +32,7 @@
#include "xcb.h" #include "xcb.h"
/* This function must be called with the IOLock held. */ /* 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. */ /* This function must be called with the IOLock held. */
unsigned int XCBGetRequestSent(XCBConnection *c); unsigned int XCBGetRequestSent(XCBConnection *c);