Skip to content

Commit

Permalink
epoll: don't count immediate actions
Browse files Browse the repository at this point in the history
If an immediate action is dispatched, the loop might block
on epoll_wait even though only one action was requested.
  • Loading branch information
steeve committed Jan 17, 2025
1 parent 0890b33 commit 476a87a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/backend/epoll.zig
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,27 @@ pub const Loop = struct {

// Submit all the submissions. We copy the submission queue so that
// any resubmits don't cause an infinite loop.
var wait_rem: usize = @intCast(wait);
var queued = self.submissions;
self.submissions = .{};
while (queued.pop()) |c| {
// We ignore any completions that aren't in the adding state.
// This usually means that we switched them to be deleted or
// something.
if (c.flags.state != .adding) continue;

// These operations happen synchronously. Ensure they are
// decremented from wait_rem.
switch (c.op) {
.cancel,
// should noop be counted?
// .noop,
.shutdown,
.timer,
=> wait_rem -|= 1,
else => {},
}

self.start(c);
}

Expand All @@ -322,7 +336,6 @@ pub const Loop = struct {

// Wait and process events. We only do this if we have any active.
var events: [1024]linux.epoll_event = undefined;
var wait_rem: usize = @intCast(wait);
while (self.active > 0 and (wait == 0 or wait_rem > 0)) {
self.update_now();
const now_timer: Operation.Timer = .{ .next = self.cached_now };
Expand Down

0 comments on commit 476a87a

Please sign in to comment.