From 066a84f89ac25cf26f21590d4e2130899a15d0d6 Mon Sep 17 00:00:00 2001 From: Anton Ivanov Date: Thu, 15 Jul 2021 16:28:12 +0100 Subject: latch-unix: Decrease the stack usage in latch 1. Make latch behave as described and documented - clear all outstanding latch writes when invoking latch_poll(). 2. Decrease the size of the latch buffer. Less stack usage, less cache thrashing. Signed-off-by: Anton Ivanov Signed-off-by: Ben Pfaff --- lib/latch-unix.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib/latch-unix.c') diff --git a/lib/latch-unix.c b/lib/latch-unix.c index 2995076d6..f4d10c39a 100644 --- a/lib/latch-unix.c +++ b/lib/latch-unix.c @@ -43,9 +43,17 @@ latch_destroy(struct latch *latch) bool latch_poll(struct latch *latch) { - char buffer[_POSIX_PIPE_BUF]; + char latch_buffer[16]; + bool result = false; + int ret; - return read(latch->fds[0], buffer, sizeof buffer) > 0; + do { + ret = read(latch->fds[0], &latch_buffer, sizeof latch_buffer); + result |= ret > 0; + /* Repeat as long as read() reads a full buffer. */ + } while (ret == sizeof latch_buffer); + + return result; } /* Sets 'latch'. -- cgit v1.2.1