From: Anton Ivanov <[email protected]>

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 <[email protected]>
---
 lib/latch-unix.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/lib/latch-unix.c b/lib/latch-unix.c
index 2995076d6..80115fe6d 100644
--- a/lib/latch-unix.c
+++ b/lib/latch-unix.c
@@ -23,6 +23,7 @@
 #include "openvswitch/poll-loop.h"
 #include "socket-util.h"
 
+
 /* Initializes 'latch' as initially unset. */
 void
 latch_init(struct latch *latch)
@@ -43,9 +44,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;
+
+    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 read(latch->fds[0], buffer, sizeof buffer) > 0;
+    return result;
 }
 
 /* Sets 'latch'.
-- 
2.20.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to