summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/trace/Ring.zig7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/trace/Ring.zig b/src/trace/Ring.zig
index 766ed63..0bde33a 100644
--- a/src/trace/Ring.zig
+++ b/src/trace/Ring.zig
@@ -196,8 +196,11 @@ pub fn advance(r: *Ring, rec: Record) void {
const size = record_overhead + std.mem.alignForward(usize, rec.payload.len, 8);
const start: [*]u8 = @ptrFromInt(@intFromPtr(rec.ev) - 8);
@memset(start[0..size], 0);
- _ = h.tail.fetchAdd(size, .seq_cst);
- if (h.space_waiters.load(.seq_cst) != 0) {
+ const tail = h.tail.fetchAdd(size, .seq_cst) + size;
+ // A producer waiting for room is woken once half the ring is free, not
+ // at every record: the wake is a syscall, and it would be back waiting
+ // a record later.
+ if (h.space_waiters.load(.seq_cst) != 0 and h.head.load(.acquire) - tail <= h.capacity / 2) {
_ = h.space_seq.fetchAdd(1, .release);
futexWake(&h.space_seq);
}