Skip to content

Commit

Permalink
posix: use atomic counter only on kqueue
Browse files Browse the repository at this point in the history
  • Loading branch information
Cloudef committed Jun 22, 2024
1 parent 4de5a08 commit f5bfc27
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/aio/common/posix.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ pub const PIDFD_NONBLOCK = @as(usize, 1 << @bitOffsetOf(std.posix.O, "NONBLOCK")

pub const EventSource = struct {
fd: std.posix.fd_t,
counter: std.atomic.Value(u32) = std.atomic.Value(u32).init(0),
_: if (@hasDecl(std.posix.system, "kqueue"))
struct {
counter: std.atomic.Value(u32) = std.atomic.Value(u32).init(0),
}
else
struct {} = .{},

pub inline fn init() !@This() {
if (comptime @hasDecl(std.posix.system, "eventfd")) {
Expand All @@ -34,7 +39,7 @@ pub const EventSource = struct {
_ = std.posix.write(self.fd, &std.mem.toBytes(@as(u64, 1))) catch continue;
} else if (comptime @hasDecl(std.posix.system, "kqueue")) {
_ = std.posix.kevent(self.fd, &.{.{
.ident = self.counter.fetchAdd(1, .monotonic),
.ident = self._.counter.fetchAdd(1, .monotonic),
.filter = std.posix.system.EVFILT_USER,
.flags = std.posix.system.EV_ADD | std.posix.system.EV_ENABLE | std.posix.system.EV_ONESHOT,
.fflags = std.posix.system.NOTE_TRIGGER,
Expand Down

0 comments on commit f5bfc27

Please sign in to comment.