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.
@@ -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'.
