Skip to content

Commit 57fe5ad

Browse files
committed
queue: clear next before re-enqueue
1 parent 9f785d2 commit 57fe5ad

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/backend/kqueue.zig

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ pub const Loop = struct {
201201
const ecanceled = -1 * @as(i32, @intCast(@intFromEnum(posix.system.E.CANCELED)));
202202
c.result = c.syscall_result(ecanceled);
203203
c.flags.state = .dead;
204+
c.next = null;
204205
self.completions.push(c);
205206

206207
events[events_len] = ev;
@@ -261,6 +262,7 @@ pub const Loop = struct {
261262
}
262263

263264
assert(c.result != null);
265+
c.next = null;
264266
self.completions.push(c);
265267
}
266268
}
@@ -454,7 +456,10 @@ pub const Loop = struct {
454456
},
455457

456458
// Only resubmit if we aren't already active (in the queue)
457-
.rearm => if (!c_active) self.submissions.push(c),
459+
.rearm => if (!c_active) {
460+
c.next = null;
461+
self.submissions.push(c);
462+
},
458463
}
459464

460465
// If we filled the events slice, we break to avoid overflow.

src/watcher/file.zig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,10 @@ fn FileStream(comptime xev: type) type {
196196

197197
// Rearm requeues this request, it doesn't return rearm
198198
// on the actual callback here...
199-
if (action == .rearm) q_inner.push(req_inner);
199+
if (action == .rearm) {
200+
req_inner.next = null;
201+
q_inner.push(req_inner);
202+
}
200203

201204
// If we have another request, add that completion next.
202205
if (q_inner.head) |req_next| l_inner.add(&req_next.completion);

src/watcher/stream.zig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,10 @@ pub fn Writeable(comptime xev: type, comptime T: type, comptime options: Options
854854

855855
// Rearm requeues this request, it doesn't return rearm
856856
// on the actual callback here...
857-
if (action == .rearm) q_inner.push(req_inner);
857+
if (action == .rearm) {
858+
req_inner.next = null;
859+
q_inner.push(req_inner);
860+
}
858861

859862
// If we have another request, add that completion next.
860863
if (q_inner.head) |req_next| l_inner.add(&req_next.completion);

0 commit comments

Comments
 (0)