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-10-02 16:30:59-07:00
logf0499abd88be7a914935c8d8076f9ae857bbcd7d
treeb96e7052f696648a47a294e2e818532bbd4701a5
parent806214797a124b175a2318cf25f487970f4518a4

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(...@@ -494,13 +494,12 @@ fn async(
494const DetachedClosure = struct {494const DetachedClosure = struct {
495 pool: *Pool,495 pool: *Pool,
496 func: *const fn (context: *anyopaque) void,496 func: *const fn (context: *anyopaque) void,
497 run_node: Pool.RunQueue.Node = .{ .data = .{ .runFn = runFn } },497 runnable: Runnable = .{ .runFn = runFn },
498 context_alignment: std.mem.Alignment,498 context_alignment: std.mem.Alignment,
499 context_len: usize,499 context_len: usize,
500500
501 fn runFn(runnable: *Pool.Runnable, _: ?usize) void {501 fn runFn(runnable: *Pool.Runnable, _: ?usize) void {
502 const run_node: *Pool.RunQueue.Node = @fieldParentPtr("data", runnable);502 const closure: *DetachedClosure = @alignCast(@fieldParentPtr("runnable", runnable));
503 const closure: *DetachedClosure = @alignCast(@fieldParentPtr("run_node", run_node));
504 closure.func(closure.contextPointer());503 closure.func(closure.contextPointer());
505 const gpa = closure.pool.allocator;504 const gpa = closure.pool.allocator;
506 const base: [*]align(@alignOf(DetachedClosure)) u8 = @ptrCast(closure);505 const base: [*]align(@alignOf(DetachedClosure)) u8 = @ptrCast(closure);
...@@ -544,7 +543,7 @@ fn asyncDetached(...@@ -544,7 +543,7 @@ fn asyncDetached(
544 .context_len = context.len,543 .context_len = context.len,
545 };544 };
546 @memcpy(closure.contextPointer()[0..context.len], context);545 @memcpy(closure.contextPointer()[0..context.len], context);
547 pool.run_queue.prepend(&closure.run_node);546 pool.run_queue.prepend(&closure.runnable.node);
548547
549 if (pool.threads.items.len < pool.threads.capacity) {548 if (pool.threads.items.len < pool.threads.capacity) {
550 pool.threads.addOneAssumeCapacity().* = std.Thread.spawn(.{549 pool.threads.addOneAssumeCapacity().* = std.Thread.spawn(.{