iochannel: Avoid unnecessary wakeup after successful write

To save some CPU (in low latency scenarios), don't re-enable the
"writable" event after it has succeeded. It is very likely the next
write will succeed right away too.

This means that we always need to handle EAGAIN/EWOULDBLOCK as a
successful write of 0 bytes, so I also verified that all callers to
pa_iochannel_write handled this correctly.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
This commit is contained in:
David Henningsson 2013-06-13 14:26:09 +02:00 committed by Tanu Kaskinen
parent e2d1421f61
commit 9c4dcffca5
6 changed files with 17 additions and 21 deletions

View file

@ -223,11 +223,22 @@ ssize_t pa_iochannel_write(pa_iochannel*io, const void*data, size_t l) {
pa_assert(l);
pa_assert(io->ofd >= 0);
if ((r = pa_write(io->ofd, data, l, &io->ofd_type)) >= 0) {
io->writable = io->hungup = FALSE;
enable_events(io);
r = pa_write(io->ofd, data, l, &io->ofd_type);
if ((size_t) r == l)
return r; /* Fast path - we almost always successfully write everything */
if (r < 0) {
if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)
r = 0;
else
return r;
}
/* Partial write - let's get a notification when we can write more */
io->writable = io->hungup = FALSE;
enable_events(io);
return r;
}