Change filedescriptor API to be thread safe
authorKristian Høgsberg <krh@bitplanet.net>
Thu, 4 Oct 2012 20:54:22 +0000 (16:54 -0400)
committerKristian Høgsberg <krh@bitplanet.net>
Thu, 11 Oct 2012 00:59:00 +0000 (20:59 -0400)
commit53d24713a31d59d9534c1c1a84a7ad46f44ee95f
tree0e550fa29c2e5b9ccc757b307dfed026143c3a24
parent0371668dcca5aa29c0fc4b59b974e40bcf073563
Change filedescriptor API to be thread safe

The update callback for the file descriptors was always a bit awkward and
un-intuitive.  The idea was that whenever the protocol code needed to
write data to the fd it would call the 'update' function.  This function
would adjust the mainloop so that it polls for POLLOUT on the fd so we
can eventually flush the data to the socket.

The problem is that in multi-threaded applications, any thread can issue
a request, which writes data to the output buffer and thus triggers the
update callback.  Thus, we'll be calling out with the display mutex
held and may call from any thread.

The solution is to eliminate the udpate callback and just require that
the application or server flushes all connection buffers before blocking.
This turns out to be a simpler API, although we now require clients to
deal with EAGAIN and non-blocking writes.  It also saves a few syscalls,
since the socket will be writable most of the time and most writes will
complete, so we avoid changing epoll to poll for POLLOUT, then write and
then change it back for each write.
src/connection.c
src/event-loop.c
src/wayland-client.c
src/wayland-client.h
src/wayland-private.h
src/wayland-server.c
src/wayland-server.h
tests/connection-test.c
tests/os-wrappers-test.c