diff options
author | Uli Schlachter <psychon@znc.in> | 2013-11-18 19:49:41 +0100 |
---|---|---|
committer | Uli Schlachter <psychon@znc.in> | 2013-11-18 19:49:41 +0100 |
commit | 5d1dbb468bb0f834eaa8adea6daf6729808ca429 (patch) | |
tree | 753ea11c037a69347af09b57b3751b8b4cecf0ba /src | |
parent | c7c5b710f2cc0782412c9e159986c96b52aa0d02 (diff) |
Revert "fix deadlock with xcb_take_socket/return_socket v3"
This reverts commit 9ae84ad187e2ba440c40f44b8eb21c82c2fdbf12.
After this patch was merged, there were complaints about it not being a good
idea. Revert this for now until we can agree on this.
References: http://lists.freedesktop.org/archives/xcb/2013-June/008340.html
Signed-off-by: Uli Schlachter <psychon@znc.in>
Conflicts:
src/xcbint.h
Diffstat (limited to 'src')
-rw-r--r-- | src/xcb_out.c | 38 | ||||
-rw-r--r-- | src/xcbext.h | 1 | ||||
-rw-r--r-- | src/xcbint.h | 7 |
3 files changed, 21 insertions, 25 deletions
diff --git a/src/xcb_out.c b/src/xcb_out.c index 1a3aca5..18bb5f9 100644 --- a/src/xcb_out.c +++ b/src/xcb_out.c @@ -86,24 +86,21 @@ static void send_sync(xcb_connection_t *c) static void get_socket_back(xcb_connection_t *c) { - while (c->out.return_socket) { - /* we are about to release the lock, - so make a copy of the current status */ - xcb_return_socket_func_t return_socket = c->out.return_socket; - void *socket_closure = c->out.socket_closure; - int socket_seq = c->out.socket_seq; - - pthread_mutex_unlock(&c->iolock); - return_socket(socket_closure); - pthread_mutex_lock(&c->iolock); - - /* make sure nobody else has acquired the socket */ - if (socket_seq == c->out.socket_seq) { - c->out.return_socket = 0; - c->out.socket_closure = 0; - _xcb_in_replies_done(c); - } - } + while(c->out.return_socket && c->out.socket_moving) + pthread_cond_wait(&c->out.socket_cond, &c->iolock); + if(!c->out.return_socket) + return; + + c->out.socket_moving = 1; + pthread_mutex_unlock(&c->iolock); + c->out.return_socket(c->out.socket_closure); + pthread_mutex_lock(&c->iolock); + c->out.socket_moving = 0; + + pthread_cond_broadcast(&c->out.socket_cond); + c->out.return_socket = 0; + c->out.socket_closure = 0; + _xcb_in_replies_done(c); } /* Public interface */ @@ -299,7 +296,6 @@ int xcb_take_socket(xcb_connection_t *c, void (*return_socket)(void *closure), v { c->out.return_socket = return_socket; c->out.socket_closure = closure; - ++c->out.socket_seq; if(flags) _xcb_in_expect_reply(c, c->out.request, WORKAROUND_EXTERNAL_SOCKET_OWNER, flags); assert(c->out.request == c->out.request_written); @@ -336,9 +332,11 @@ int xcb_flush(xcb_connection_t *c) int _xcb_out_init(_xcb_out *out) { + if(pthread_cond_init(&out->socket_cond, 0)) + return 0; out->return_socket = 0; out->socket_closure = 0; - out->socket_seq = 0; + out->socket_moving = 0; if(pthread_cond_init(&out->cond, 0)) return 0; diff --git a/src/xcbext.h b/src/xcbext.h index 1eb1be7..20ec1c3 100644 --- a/src/xcbext.h +++ b/src/xcbext.h @@ -69,7 +69,6 @@ void xcb_send_fd(xcb_connection_t *c, int fd); * callback which XCB can call when it wants the write side of the * socket back to make a request. This callback synchronizes with the * external socket owner and flushes any output queues if appropriate. - * The callback might be called from different threads at the same time. * If you are sending requests which won't cause a reply, please note the * comment for xcb_writev which explains some sequence number wrap issues. * */ diff --git a/src/xcbint.h b/src/xcbint.h index 5c904fb..b25f03b 100644 --- a/src/xcbint.h +++ b/src/xcbint.h @@ -79,8 +79,6 @@ void *_xcb_map_remove(_xcb_map *q, unsigned int key); /* xcb_out.c */ -typedef void (*xcb_return_socket_func_t)(void *closure); - #if HAVE_SENDMSG #define XCB_MAX_PASS_FD 16 @@ -95,9 +93,10 @@ typedef struct _xcb_out { pthread_cond_t cond; int writing; - xcb_return_socket_func_t return_socket; + pthread_cond_t socket_cond; + void (*return_socket)(void *closure); void *socket_closure; - unsigned int socket_seq; + int socket_moving; char queue[XCB_QUEUE_BUFFER_SIZE]; int queue_len; |