Ensure xcb owns socket and no other threads are writing before send_request
authorKeith Packard <keithp@keithp.com>
Tue, 24 Dec 2013 05:15:20 +0000 (21:15 -0800)
committerUli Schlachter <psychon@znc.in>
Sun, 30 Mar 2014 20:15:38 +0000 (22:15 +0200)
commitbe0fe56c3bcad5124dcc6c47a2fad01acd16f71a
treedda9b02d3df27bb38c591a41087c996c52970045
parente2813e1cde893f384fa620ff3c13493beebabe0c
Ensure xcb owns socket and no other threads are writing before send_request

send_request may only write to out.queue if no other thread is busy
writing to the network (as that thread may be writing from out.queue).

send_request may only allocate request sequence numbers if XCB owns
the socket.

Therefore, send_request must make sure that both conditions are true
when it holds iolock, which can only be done by looping until both
conditions are true without having dropped the lock waiting for the
second condition.

We choose to get the socket back from Xlib first as get_socket_back
has a complicated test and checking for other threads writing is a
simple in-lined check.

This also changes the sequence number checks (64k requests with no
reply, 4M request wrapping) to ensure that both conditions are true
before queueing the request.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Uli Schlachter <psychon@znc.in>
src/xcb_out.c