Restructure XCBWaitForReply to eliminate two gotos.

This commit is contained in:
Jamey Sharp 2006-04-19 20:23:37 -07:00
parent d5ab03b4b7
commit d5347485a5

View File

@ -298,9 +298,6 @@ static int poll_for_reply(XCBConnection *c, unsigned int request, void **reply,
void *XCBWaitForReply(XCBConnection *c, unsigned int request, XCBGenericError **e) void *XCBWaitForReply(XCBConnection *c, unsigned int request, XCBGenericError **e)
{ {
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
reader_list reader;
reader_list **prev_reader;
void *ret = 0; void *ret = 0;
if(e) if(e)
*e = 0; *e = 0;
@ -308,8 +305,11 @@ void *XCBWaitForReply(XCBConnection *c, unsigned int request, XCBGenericError **
pthread_mutex_lock(&c->iolock); pthread_mutex_lock(&c->iolock);
/* If this request has not been written yet, write it. */ /* If this request has not been written yet, write it. */
if(!_xcb_out_flush_to(c, request)) if(_xcb_out_flush_to(c, request))
goto done; /* error */ {
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
reader_list reader;
reader_list **prev_reader;
for(prev_reader = &c->in.readers; *prev_reader && (*prev_reader)->request <= request; prev_reader = &(*prev_reader)->next) for(prev_reader = &c->in.readers; *prev_reader && (*prev_reader)->request <= request; prev_reader = &(*prev_reader)->next)
if((*prev_reader)->request == request) if((*prev_reader)->request == request)
@ -320,11 +320,9 @@ void *XCBWaitForReply(XCBConnection *c, unsigned int request, XCBGenericError **
reader.next = *prev_reader; reader.next = *prev_reader;
*prev_reader = &reader; *prev_reader = &reader;
/* If this request has not completed yet and has no reply waiting,
* wait for one. */
while(!poll_for_reply(c, request, &ret, e)) while(!poll_for_reply(c, request, &ret, e))
if(!_xcb_conn_wait(c, &cond, 0, 0)) if(!_xcb_conn_wait(c, &cond, 0, 0))
goto done; break;
done: done:
for(prev_reader = &c->in.readers; *prev_reader && (*prev_reader)->request <= request; prev_reader = &(*prev_reader)->next) for(prev_reader = &c->in.readers; *prev_reader && (*prev_reader)->request <= request; prev_reader = &(*prev_reader)->next)
@ -334,6 +332,7 @@ done:
break; break;
} }
pthread_cond_destroy(&cond); pthread_cond_destroy(&cond);
}
wake_up_next_reader(c); wake_up_next_reader(c);
pthread_mutex_unlock(&c->iolock); pthread_mutex_unlock(&c->iolock);