summaryrefslogtreecommitdiff
path: root/lib/latch-unix.c
diff options
context:
space:
mode:
authorAnton Ivanov <anton.ivanov@cambridgegreys.com>2021-07-15 16:28:12 +0100
committerBen Pfaff <blp@ovn.org>2021-07-15 11:40:41 -0700
commit066a84f89ac25cf26f21590d4e2130899a15d0d6 (patch)
treec23b9602c1b59f931435fdadb305be008a114355 /lib/latch-unix.c
parentd2e97030eda5dfafc875ec056788c49e2570d2ef (diff)
downloadopenvswitch-066a84f89ac25cf26f21590d4e2130899a15d0d6.tar.gz
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 <anton.ivanov@cambridgegreys.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'lib/latch-unix.c')
-rw-r--r--lib/latch-unix.c12
1 files changed, 10 insertions, 2 deletions
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'.