authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-10 16:44:05-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-20 10:38:39-07:00
log2db92a98e86de3588dc4b0dd7310e58ccccc09af
tree26b315a6b82c85c091c447590255f82cb5f4408b
parente95b26f1c6ae3d7197d9159760006157740b128c

std.Io.ThreadPool: fix asyncDetached


1 files changed, 3 insertions(+), 4 deletions(-)

lib/std/Io/ThreadPool.zig+3-4
......@@ -494,13 +494,12 @@ fn async(
494494const DetachedClosure = struct {
495495 pool: *Pool,
496496 func: *const fn (context: *anyopaque) void,
497 run_node: Pool.RunQueue.Node = .{ .data = .{ .runFn = runFn } },
497 runnable: Runnable = .{ .runFn = runFn },
498498 context_alignment: std.mem.Alignment,
499499 context_len: usize,
500500
501501 fn runFn(runnable: *Pool.Runnable, _: ?usize) void {
502 const run_node: *Pool.RunQueue.Node = @fieldParentPtr("data", runnable);
503 const closure: *DetachedClosure = @alignCast(@fieldParentPtr("run_node", run_node));
502 const closure: *DetachedClosure = @alignCast(@fieldParentPtr("runnable", runnable));
504503 closure.func(closure.contextPointer());
505504 const gpa = closure.pool.allocator;
506505 const base: [*]align(@alignOf(DetachedClosure)) u8 = @ptrCast(closure);
......@@ -544,7 +543,7 @@ fn asyncDetached(
544543 .context_len = context.len,
545544 };
546545 @memcpy(closure.contextPointer()[0..context.len], context);
547 pool.run_queue.prepend(&closure.run_node);
546 pool.run_queue.prepend(&closure.runnable.node);
548547
549548 if (pool.threads.items.len < pool.threads.capacity) {
550549 pool.threads.addOneAssumeCapacity().* = std.Thread.spawn(.{