Skip to content

Commit

Permalink
backend/epoll: read the wakeup eventfd to avoid being awaken again
Browse files Browse the repository at this point in the history
  • Loading branch information
Corendos committed Jan 14, 2025
1 parent 0d1c2f8 commit 38d4dbe
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/backend/epoll.zig
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ pub const Loop = struct {

var ev: linux.epoll_event = .{
.events = linux.EPOLL.IN | linux.EPOLL.RDHUP,
.data = .{ .ptr = 0 },
.data = .{ .fd = self.eventfd.fd },
};
posix.epoll_ctl(
self.fd,
Expand Down Expand Up @@ -397,9 +397,12 @@ pub const Loop = struct {

// Process all our events and invoke their completion handlers
for (events[0..n]) |ev| {
// Zero data values are internal events that we do nothing
// on such as the eventfd wakeup.
if (ev.data.ptr == 0) continue;
// Handle wakeup eventfd
if (ev.data.fd == self.eventfd.fd) {
var buffer: u64 = undefined;
_ = posix.read(self.eventfd.fd, std.mem.asBytes(&buffer)) catch {};
continue;
}

const c: *Completion = @ptrFromInt(@as(usize, @intCast(ev.data.ptr)));

Expand Down

0 comments on commit 38d4dbe

Please sign in to comment.