Factor out pthread_mutex_lock and unlock calls for the iolock.
This commit is contained in:
parent
e7f473afbd
commit
57b0cd8fea
|
@ -97,12 +97,12 @@ static int write_setup(xcb_connection_t *c, xcb_auth_info_t *auth_info)
|
||||||
}
|
}
|
||||||
assert(count <= sizeof(parts) / sizeof(*parts));
|
assert(count <= sizeof(parts) / sizeof(*parts));
|
||||||
|
|
||||||
pthread_mutex_lock(&c->iolock);
|
_xcb_lock_io(c);
|
||||||
{
|
{
|
||||||
struct iovec *parts_ptr = parts;
|
struct iovec *parts_ptr = parts;
|
||||||
ret = _xcb_out_send(c, &parts_ptr, &count);
|
ret = _xcb_out_send(c, &parts_ptr, &count);
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&c->iolock);
|
_xcb_unlock_io(c);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,6 +255,16 @@ void _xcb_conn_shutdown(xcb_connection_t *c)
|
||||||
c->has_error = 1;
|
c->has_error = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _xcb_lock_io(xcb_connection_t *c)
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(&c->iolock);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _xcb_unlock_io(xcb_connection_t *c)
|
||||||
|
{
|
||||||
|
pthread_mutex_unlock(&c->iolock);
|
||||||
|
}
|
||||||
|
|
||||||
int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vector, int *count)
|
int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vector, int *count)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -278,7 +288,7 @@ int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vec
|
||||||
++c->out.writing;
|
++c->out.writing;
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&c->iolock);
|
_xcb_unlock_io(c);
|
||||||
do {
|
do {
|
||||||
ret = select(c->fd + 1, &rfds, &wfds, 0, 0);
|
ret = select(c->fd + 1, &rfds, &wfds, 0, 0);
|
||||||
} while (ret == -1 && errno == EINTR);
|
} while (ret == -1 && errno == EINTR);
|
||||||
|
@ -287,7 +297,7 @@ int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vec
|
||||||
_xcb_conn_shutdown(c);
|
_xcb_conn_shutdown(c);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
pthread_mutex_lock(&c->iolock);
|
_xcb_lock_io(c);
|
||||||
|
|
||||||
if(ret)
|
if(ret)
|
||||||
{
|
{
|
||||||
|
|
16
src/xcb_in.c
16
src/xcb_in.c
|
@ -318,7 +318,7 @@ void *xcb_wait_for_reply(xcb_connection_t *c, unsigned int request, xcb_generic_
|
||||||
if(c->has_error)
|
if(c->has_error)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
pthread_mutex_lock(&c->iolock);
|
_xcb_lock_io(c);
|
||||||
|
|
||||||
/* 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))
|
||||||
|
@ -358,7 +358,7 @@ void *xcb_wait_for_reply(xcb_connection_t *c, unsigned int request, xcb_generic_
|
||||||
}
|
}
|
||||||
|
|
||||||
wake_up_next_reader(c);
|
wake_up_next_reader(c);
|
||||||
pthread_mutex_unlock(&c->iolock);
|
_xcb_unlock_io(c);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,9 +373,9 @@ int xcb_poll_for_reply(xcb_connection_t *c, unsigned int request, void **reply,
|
||||||
return 1; /* would not block */
|
return 1; /* would not block */
|
||||||
}
|
}
|
||||||
assert(reply != 0);
|
assert(reply != 0);
|
||||||
pthread_mutex_lock(&c->iolock);
|
_xcb_lock_io(c);
|
||||||
ret = poll_for_reply(c, request, reply, error);
|
ret = poll_for_reply(c, request, reply, error);
|
||||||
pthread_mutex_unlock(&c->iolock);
|
_xcb_unlock_io(c);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,14 +384,14 @@ xcb_generic_event_t *xcb_wait_for_event(xcb_connection_t *c)
|
||||||
xcb_generic_event_t *ret;
|
xcb_generic_event_t *ret;
|
||||||
if(c->has_error)
|
if(c->has_error)
|
||||||
return 0;
|
return 0;
|
||||||
pthread_mutex_lock(&c->iolock);
|
_xcb_lock_io(c);
|
||||||
/* get_event returns 0 on empty list. */
|
/* get_event returns 0 on empty list. */
|
||||||
while(!(ret = get_event(c)))
|
while(!(ret = get_event(c)))
|
||||||
if(!_xcb_conn_wait(c, &c->in.event_cond, 0, 0))
|
if(!_xcb_conn_wait(c, &c->in.event_cond, 0, 0))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
wake_up_next_reader(c);
|
wake_up_next_reader(c);
|
||||||
pthread_mutex_unlock(&c->iolock);
|
_xcb_unlock_io(c);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,12 +401,12 @@ xcb_generic_event_t *xcb_poll_for_event(xcb_connection_t *c, int *error)
|
||||||
{
|
{
|
||||||
xcb_generic_event_t *ret = 0;
|
xcb_generic_event_t *ret = 0;
|
||||||
int success;
|
int success;
|
||||||
pthread_mutex_lock(&c->iolock);
|
_xcb_lock_io(c);
|
||||||
/* FIXME: follow X meets Z architecture changes. */
|
/* FIXME: follow X meets Z architecture changes. */
|
||||||
success = _xcb_in_read(c);
|
success = _xcb_in_read(c);
|
||||||
if(success)
|
if(success)
|
||||||
ret = get_event(c);
|
ret = get_event(c);
|
||||||
pthread_mutex_unlock(&c->iolock);
|
_xcb_unlock_io(c);
|
||||||
if(success)
|
if(success)
|
||||||
{
|
{
|
||||||
if(error)
|
if(error)
|
||||||
|
|
|
@ -163,7 +163,7 @@ unsigned int xcb_send_request(xcb_connection_t *c, int flags, struct iovec *vect
|
||||||
workaround = WORKAROUND_GLX_GET_FB_CONFIGS_BUG;
|
workaround = WORKAROUND_GLX_GET_FB_CONFIGS_BUG;
|
||||||
|
|
||||||
/* get a sequence number and arrange for delivery. */
|
/* get a sequence number and arrange for delivery. */
|
||||||
pthread_mutex_lock(&c->iolock);
|
_xcb_lock_io(c);
|
||||||
/* wait for other writing threads to get out of my way. */
|
/* wait for other writing threads to get out of my way. */
|
||||||
while(c->out.writing)
|
while(c->out.writing)
|
||||||
pthread_cond_wait(&c->out.cond, &c->iolock);
|
pthread_cond_wait(&c->out.cond, &c->iolock);
|
||||||
|
@ -207,7 +207,7 @@ unsigned int xcb_send_request(xcb_connection_t *c, int flags, struct iovec *vect
|
||||||
_xcb_conn_shutdown(c);
|
_xcb_conn_shutdown(c);
|
||||||
request = 0;
|
request = 0;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&c->iolock);
|
_xcb_unlock_io(c);
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,9 +216,9 @@ int xcb_flush(xcb_connection_t *c)
|
||||||
int ret;
|
int ret;
|
||||||
if(c->has_error)
|
if(c->has_error)
|
||||||
return 0;
|
return 0;
|
||||||
pthread_mutex_lock(&c->iolock);
|
_xcb_lock_io(c);
|
||||||
ret = _xcb_out_flush_to(c, c->out.request);
|
ret = _xcb_out_flush_to(c, c->out.request);
|
||||||
pthread_mutex_unlock(&c->iolock);
|
_xcb_unlock_io(c);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -159,6 +159,8 @@ struct xcb_connection_t {
|
||||||
};
|
};
|
||||||
|
|
||||||
void _xcb_conn_shutdown(xcb_connection_t *c);
|
void _xcb_conn_shutdown(xcb_connection_t *c);
|
||||||
|
void _xcb_lock_io(xcb_connection_t *c);
|
||||||
|
void _xcb_unlock_io(xcb_connection_t *c);
|
||||||
int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vector, int *count);
|
int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vector, int *count);
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue