Am 09.04.2013 16:10, schrieb Peter Meerwald:
From: Peter Meerwald <[email protected]>
pa_write() knows two types of operation:
calling send() and calling write()
there is a flag (a pointer to an int) passed to pa_write()
which can remember which write type was successful
if the pointer is NULL or the int is 0, send() is tried first,
with a fallback to write() if send() resulted in ENOTSOCK
pa_fdsem_post() calls pa_write() with a NULL pointer;
unfortunately (at least with HAVE_SYS_EVENTFD_H #define'd) send()
always fails here and write() is called -- causing an extra syscall
quite frequently
strace:
send(17, "\1\0\0\0\0\0\0\0", 8, MSG_NOSIGNAL) = -1 ENOTSOCK (Socket operation
on non-socket)
write(17, "\1\0\0\0\0\0\0\0", 8) = 8
the patch adds a write_type field to pa_fdsem to the successful
pa_write() type can be remembered and unnecessary send() calls are
avoided
Signed-off-by: Peter Meerwald <[email protected]>
---
src/pulsecore/fdsem.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/pulsecore/fdsem.c b/src/pulsecore/fdsem.c
index 14fcbd6..1d3d44a 100644
--- a/src/pulsecore/fdsem.c
+++ b/src/pulsecore/fdsem.c
@@ -52,7 +52,7 @@ struct pa_fdsem {
#ifdef HAVE_SYS_EVENTFD_H
int efd;
#endif
-
+ int write_type;
pa_fdsem_data *data;
};
@@ -196,7 +196,7 @@ void pa_fdsem_post(pa_fdsem *f) {
if (f->efd >= 0) {
uint64_t u = 1;
- if ((r = pa_write(f->efd, &u, sizeof(u), NULL)) !=
sizeof(u)) {
+ if ((r = pa_write(f->efd, &u, sizeof(u), &f->write_type))
!= sizeof(u)) {
if (r >= 0 || errno != EINTR) {
pa_log_error("Invalid write to eventfd: %s", r < 0 ?
pa_cstrerror(errno) : "EOF");
pa_assert_not_reached();
@@ -207,7 +207,7 @@ void pa_fdsem_post(pa_fdsem *f) {
} else
#endif
- if ((r = pa_write(f->fds[1], &x, 1, NULL)) != 1) {
+ if ((r = pa_write(f->fds[1], &x, 1, &f->write_type)) != 1) {
if (r >= 0 || errno != EINTR) {
pa_log_error("Invalid write to pipe: %s", r < 0 ?
pa_cstrerror(errno) : "EOF");
pa_assert_not_reached();
The type should be initialized to 0. This doesn't happen in the
functions that allocate pa_fdsem objects.
Best regards.
_______________________________________________
pulseaudio-discuss mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss