| ... | ... | @@ -13,6 +13,7 @@ const net = std.Io.net; |
| 13 | 13 | const HostName = std.Io.net.HostName; |
| 14 | 14 | const IpAddress = std.Io.net.IpAddress; |
| 15 | 15 | const Allocator = std.mem.Allocator; |
| 16 | const Alignment = std.mem.Alignment; |
| 16 | 17 | const assert = std.debug.assert; |
| 17 | 18 | const posix = std.posix; |
| 18 | 19 | |
| ... | ... | @@ -22,10 +23,30 @@ mutex: std.Thread.Mutex = .{}, |
| 22 | 23 | cond: std.Thread.Condition = .{}, |
| 23 | 24 | run_queue: std.SinglyLinkedList = .{}, |
| 24 | 25 | join_requested: bool = false, |
| 25 | | threads: std.ArrayList(std.Thread), |
| 26 | 26 | stack_size: usize, |
| 27 | | cpu_count: std.Thread.CpuCountError!usize, |
| 28 | | concurrent_count: usize, |
| 27 | /// All threads are spawned detached; this is how we wait until they all exit. |
| 28 | wait_group: std.Thread.WaitGroup = .{}, |
| 29 | /// Maximum thread pool size (excluding main thread) when dispatching async |
| 30 | /// tasks. Until this limit, calls to `Io.async` when all threads are busy will |
| 31 | /// cause a new thread to be spawned and permanently added to the pool. After |
| 32 | /// this limit, calls to `Io.async` when all threads are busy run the task |
| 33 | /// immediately. |
| 34 | /// |
| 35 | /// Defaults to a number equal to logical CPU cores. |
| 36 | async_limit: Io.Limit, |
| 37 | /// Maximum thread pool size (excluding main thread) for dispatching concurrent |
| 38 | /// tasks. Until this limit, calls to `Io.concurrent` will increase the thread |
| 39 | /// pool size. |
| 40 | /// |
| 41 | /// concurrent tasks. After this number, calls to `Io.concurrent` return |
| 42 | /// `error.ConcurrencyUnavailable`. |
| 43 | concurrent_limit: Io.Limit = .unlimited, |
| 44 | /// Error from calling `std.Thread.getCpuCount` in `init`. |
| 45 | cpu_count_error: ?std.Thread.CpuCountError, |
| 46 | /// Number of threads that are unavailable to take tasks. To calculate |
| 47 | /// available count, subtract this from either `async_limit` or |
| 48 | /// `concurrent_limit`. |
| 49 | busy_count: usize = 0, |
| 29 | 50 | |
| 30 | 51 | wsa: if (is_windows) Wsa else struct {} = .{}, |
| 31 | 52 | |
| ... | ... | @@ -70,8 +91,6 @@ const Closure = struct { |
| 70 | 91 | start: Start, |
| 71 | 92 | node: std.SinglyLinkedList.Node = .{}, |
| 72 | 93 | cancel_tid: CancelId, |
| 73 | | /// Whether this task bumps minimum number of threads in the pool. |
| 74 | | is_concurrent: bool, |
| 75 | 94 | |
| 76 | 95 | const Start = *const fn (*Closure) void; |
| 77 | 96 | |
| ... | ... | @@ -90,8 +109,6 @@ const Closure = struct { |
| 90 | 109 | } |
| 91 | 110 | }; |
| 92 | 111 | |
| 93 | | pub const InitError = std.Thread.CpuCountError || Allocator.Error; |
| 94 | | |
| 95 | 112 | /// Related: |
| 96 | 113 | /// * `init_single_threaded` |
| 97 | 114 | pub fn init( |
| ... | ... | @@ -103,21 +120,20 @@ pub fn init( |
| 103 | 120 | /// here. |
| 104 | 121 | gpa: Allocator, |
| 105 | 122 | ) Threaded { |
| 123 | if (builtin.single_threaded) return .init_single_threaded; |
| 124 | |
| 125 | const cpu_count = std.Thread.getCpuCount(); |
| 126 | |
| 106 | 127 | var t: Threaded = .{ |
| 107 | 128 | .allocator = gpa, |
| 108 | | .threads = .empty, |
| 109 | 129 | .stack_size = std.Thread.SpawnConfig.default_stack_size, |
| 110 | | .cpu_count = std.Thread.getCpuCount(), |
| 111 | | .concurrent_count = 0, |
| 130 | .async_limit = if (cpu_count) |n| .limited(n - 1) else |_| .nothing, |
| 131 | .cpu_count_error = if (cpu_count) |_| null else |e| e, |
| 112 | 132 | .old_sig_io = undefined, |
| 113 | 133 | .old_sig_pipe = undefined, |
| 114 | 134 | .have_signal_handler = false, |
| 115 | 135 | }; |
| 116 | 136 | |
| 117 | | if (t.cpu_count) |n| { |
| 118 | | t.threads.ensureTotalCapacityPrecise(gpa, n - 1) catch {}; |
| 119 | | } else |_| {} |
| 120 | | |
| 121 | 137 | if (posix.Sigaction != void) { |
| 122 | 138 | // This causes sending `posix.SIG.IO` to thread to interrupt blocking |
| 123 | 139 | // syscalls, returning `posix.E.INTR`. |
| ... | ... | @@ -142,19 +158,17 @@ pub fn init( |
| 142 | 158 | /// * `deinit` is safe, but unnecessary to call. |
| 143 | 159 | pub const init_single_threaded: Threaded = .{ |
| 144 | 160 | .allocator = .failing, |
| 145 | | .threads = .empty, |
| 146 | 161 | .stack_size = std.Thread.SpawnConfig.default_stack_size, |
| 147 | | .cpu_count = 1, |
| 148 | | .concurrent_count = 0, |
| 162 | .async_limit = .nothing, |
| 163 | .cpu_count_error = null, |
| 164 | .concurrent_limit = .nothing, |
| 149 | 165 | .old_sig_io = undefined, |
| 150 | 166 | .old_sig_pipe = undefined, |
| 151 | 167 | .have_signal_handler = false, |
| 152 | 168 | }; |
| 153 | 169 | |
| 154 | 170 | pub fn deinit(t: *Threaded) void { |
| 155 | | const gpa = t.allocator; |
| 156 | 171 | t.join(); |
| 157 | | t.threads.deinit(gpa); |
| 158 | 172 | if (is_windows and t.wsa.status == .initialized) { |
| 159 | 173 | if (ws2_32.WSACleanup() != 0) recoverableOsBugDetected(); |
| 160 | 174 | } |
| ... | ... | @@ -173,10 +187,12 @@ fn join(t: *Threaded) void { |
| 173 | 187 | t.join_requested = true; |
| 174 | 188 | } |
| 175 | 189 | t.cond.broadcast(); |
| 176 | | for (t.threads.items) |thread| thread.join(); |
| 190 | t.wait_group.wait(); |
| 177 | 191 | } |
| 178 | 192 | |
| 179 | 193 | fn worker(t: *Threaded) void { |
| 194 | defer t.wait_group.finish(); |
| 195 | |
| 180 | 196 | t.mutex.lock(); |
| 181 | 197 | defer t.mutex.unlock(); |
| 182 | 198 | |
| ... | ... | @@ -184,12 +200,9 @@ fn worker(t: *Threaded) void { |
| 184 | 200 | while (t.run_queue.popFirst()) |closure_node| { |
| 185 | 201 | t.mutex.unlock(); |
| 186 | 202 | const closure: *Closure = @fieldParentPtr("node", closure_node); |
| 187 | | const is_concurrent = closure.is_concurrent; |
| 188 | 203 | closure.start(closure); |
| 189 | 204 | t.mutex.lock(); |
| 190 | | if (is_concurrent) { |
| 191 | | t.concurrent_count -= 1; |
| 192 | | } |
| 205 | t.busy_count -= 1; |
| 193 | 206 | } |
| 194 | 207 | if (t.join_requested) break; |
| 195 | 208 | t.cond.wait(&t.mutex); |
| ... | ... | @@ -387,7 +400,7 @@ const AsyncClosure = struct { |
| 387 | 400 | func: *const fn (context: *anyopaque, result: *anyopaque) void, |
| 388 | 401 | reset_event: ResetEvent, |
| 389 | 402 | select_condition: ?*ResetEvent, |
| 390 | | context_alignment: std.mem.Alignment, |
| 403 | context_alignment: Alignment, |
| 391 | 404 | result_offset: usize, |
| 392 | 405 | alloc_len: usize, |
| 393 | 406 | |
| ... | ... | @@ -432,11 +445,10 @@ const AsyncClosure = struct { |
| 432 | 445 | |
| 433 | 446 | fn init( |
| 434 | 447 | gpa: Allocator, |
| 435 | | mode: enum { async, concurrent }, |
| 436 | 448 | result_len: usize, |
| 437 | | result_alignment: std.mem.Alignment, |
| 449 | result_alignment: Alignment, |
| 438 | 450 | context: []const u8, |
| 439 | | context_alignment: std.mem.Alignment, |
| 451 | context_alignment: Alignment, |
| 440 | 452 | func: *const fn (context: *const anyopaque, result: *anyopaque) void, |
| 441 | 453 | ) Allocator.Error!*AsyncClosure { |
| 442 | 454 | const max_context_misalignment = context_alignment.toByteUnits() -| @alignOf(AsyncClosure); |
| ... | ... | @@ -454,10 +466,6 @@ const AsyncClosure = struct { |
| 454 | 466 | .closure = .{ |
| 455 | 467 | .cancel_tid = .none, |
| 456 | 468 | .start = start, |
| 457 | | .is_concurrent = switch (mode) { |
| 458 | | .async => false, |
| 459 | | .concurrent => true, |
| 460 | | }, |
| 461 | 469 | }, |
| 462 | 470 | .func = func, |
| 463 | 471 | .context_alignment = context_alignment, |
| ... | ... | @@ -470,10 +478,15 @@ const AsyncClosure = struct { |
| 470 | 478 | return ac; |
| 471 | 479 | } |
| 472 | 480 | |
| 473 | | fn waitAndDeinit(ac: *AsyncClosure, gpa: Allocator, result: []u8) void { |
| 474 | | ac.reset_event.waitUncancelable(); |
| 481 | fn waitAndDeinit(ac: *AsyncClosure, t: *Threaded, result: []u8) void { |
| 482 | ac.reset_event.wait(t) catch |err| switch (err) { |
| 483 | error.Canceled => { |
| 484 | ac.closure.requestCancel(); |
| 485 | ac.reset_event.waitUncancelable(); |
| 486 | }, |
| 487 | }; |
| 475 | 488 | @memcpy(result, ac.resultPointer()[0..result.len]); |
| 476 | | ac.deinit(gpa); |
| 489 | ac.deinit(t.allocator); |
| 477 | 490 | } |
| 478 | 491 | |
| 479 | 492 | fn deinit(ac: *AsyncClosure, gpa: Allocator) void { |
| ... | ... | @@ -485,60 +498,50 @@ const AsyncClosure = struct { |
| 485 | 498 | fn async( |
| 486 | 499 | userdata: ?*anyopaque, |
| 487 | 500 | result: []u8, |
| 488 | | result_alignment: std.mem.Alignment, |
| 501 | result_alignment: Alignment, |
| 489 | 502 | context: []const u8, |
| 490 | | context_alignment: std.mem.Alignment, |
| 503 | context_alignment: Alignment, |
| 491 | 504 | start: *const fn (context: *const anyopaque, result: *anyopaque) void, |
| 492 | 505 | ) ?*Io.AnyFuture { |
| 493 | | if (builtin.single_threaded) { |
| 506 | const t: *Threaded = @ptrCast(@alignCast(userdata)); |
| 507 | if (builtin.single_threaded or t.async_limit == .nothing) { |
| 494 | 508 | start(context.ptr, result.ptr); |
| 495 | 509 | return null; |
| 496 | 510 | } |
| 497 | | |
| 498 | | const t: *Threaded = @ptrCast(@alignCast(userdata)); |
| 499 | | const cpu_count = t.cpu_count catch { |
| 500 | | return concurrent(userdata, result.len, result_alignment, context, context_alignment, start) catch { |
| 501 | | start(context.ptr, result.ptr); |
| 502 | | return null; |
| 503 | | }; |
| 504 | | }; |
| 505 | | |
| 506 | 511 | const gpa = t.allocator; |
| 507 | | const ac = AsyncClosure.init(gpa, .async, result.len, result_alignment, context, context_alignment, start) catch { |
| 512 | const ac = AsyncClosure.init(gpa, result.len, result_alignment, context, context_alignment, start) catch { |
| 508 | 513 | start(context.ptr, result.ptr); |
| 509 | 514 | return null; |
| 510 | 515 | }; |
| 511 | 516 | |
| 512 | 517 | t.mutex.lock(); |
| 513 | 518 | |
| 514 | | const thread_capacity = cpu_count - 1 + t.concurrent_count; |
| 519 | const busy_count = t.busy_count; |
| 515 | 520 | |
| 516 | | t.threads.ensureTotalCapacityPrecise(gpa, thread_capacity) catch { |
| 521 | if (busy_count >= @intFromEnum(t.async_limit)) { |
| 517 | 522 | t.mutex.unlock(); |
| 518 | 523 | ac.deinit(gpa); |
| 519 | 524 | start(context.ptr, result.ptr); |
| 520 | 525 | return null; |
| 521 | | }; |
| 526 | } |
| 522 | 527 | |
| 523 | | t.run_queue.prepend(&ac.closure.node); |
| 528 | t.busy_count = busy_count + 1; |
| 524 | 529 | |
| 525 | | if (t.threads.items.len < thread_capacity) { |
| 530 | const pool_size = t.wait_group.value(); |
| 531 | if (pool_size - busy_count == 0) { |
| 532 | t.wait_group.start(); |
| 526 | 533 | const thread = std.Thread.spawn(.{ .stack_size = t.stack_size }, worker, .{t}) catch { |
| 527 | | if (t.threads.items.len == 0) { |
| 528 | | assert(t.run_queue.popFirst() == &ac.closure.node); |
| 529 | | t.mutex.unlock(); |
| 530 | | ac.deinit(gpa); |
| 531 | | start(context.ptr, result.ptr); |
| 532 | | return null; |
| 533 | | } |
| 534 | | // Rely on other workers to do it. |
| 534 | t.wait_group.finish(); |
| 535 | t.busy_count = busy_count; |
| 535 | 536 | t.mutex.unlock(); |
| 536 | | t.cond.signal(); |
| 537 | | return @ptrCast(ac); |
| 537 | ac.deinit(gpa); |
| 538 | start(context.ptr, result.ptr); |
| 539 | return null; |
| 538 | 540 | }; |
| 539 | | t.threads.appendAssumeCapacity(thread); |
| 541 | thread.detach(); |
| 540 | 542 | } |
| 541 | 543 | |
| 544 | t.run_queue.prepend(&ac.closure.node); |
| 542 | 545 | t.mutex.unlock(); |
| 543 | 546 | t.cond.signal(); |
| 544 | 547 | return @ptrCast(ac); |
| ... | ... | @@ -547,45 +550,42 @@ fn async( |
| 547 | 550 | fn concurrent( |
| 548 | 551 | userdata: ?*anyopaque, |
| 549 | 552 | result_len: usize, |
| 550 | | result_alignment: std.mem.Alignment, |
| 553 | result_alignment: Alignment, |
| 551 | 554 | context: []const u8, |
| 552 | | context_alignment: std.mem.Alignment, |
| 555 | context_alignment: Alignment, |
| 553 | 556 | start: *const fn (context: *const anyopaque, result: *anyopaque) void, |
| 554 | 557 | ) Io.ConcurrentError!*Io.AnyFuture { |
| 555 | 558 | if (builtin.single_threaded) return error.ConcurrencyUnavailable; |
| 556 | 559 | |
| 557 | 560 | const t: *Threaded = @ptrCast(@alignCast(userdata)); |
| 558 | | const cpu_count = t.cpu_count catch 1; |
| 559 | 561 | |
| 560 | 562 | const gpa = t.allocator; |
| 561 | | const ac = AsyncClosure.init(gpa, .concurrent, result_len, result_alignment, context, context_alignment, start) catch { |
| 563 | const ac = AsyncClosure.init(gpa, result_len, result_alignment, context, context_alignment, start) catch |
| 562 | 564 | return error.ConcurrencyUnavailable; |
| 563 | | }; |
| 565 | errdefer ac.deinit(gpa); |
| 564 | 566 | |
| 565 | 567 | t.mutex.lock(); |
| 568 | defer t.mutex.unlock(); |
| 566 | 569 | |
| 567 | | t.concurrent_count += 1; |
| 568 | | const thread_capacity = cpu_count - 1 + t.concurrent_count; |
| 570 | const busy_count = t.busy_count; |
| 569 | 571 | |
| 570 | | t.threads.ensureTotalCapacity(gpa, thread_capacity) catch { |
| 571 | | t.mutex.unlock(); |
| 572 | | ac.deinit(gpa); |
| 572 | if (busy_count >= @intFromEnum(t.concurrent_limit)) |
| 573 | 573 | return error.ConcurrencyUnavailable; |
| 574 | | }; |
| 575 | 574 | |
| 576 | | t.run_queue.prepend(&ac.closure.node); |
| 575 | t.busy_count = busy_count + 1; |
| 576 | errdefer t.busy_count = busy_count; |
| 577 | 577 | |
| 578 | | if (t.threads.items.len < thread_capacity) { |
| 579 | | const thread = std.Thread.spawn(.{ .stack_size = t.stack_size }, worker, .{t}) catch { |
| 580 | | assert(t.run_queue.popFirst() == &ac.closure.node); |
| 581 | | t.mutex.unlock(); |
| 582 | | ac.deinit(gpa); |
| 578 | const pool_size = t.wait_group.value(); |
| 579 | if (pool_size - busy_count == 0) { |
| 580 | t.wait_group.start(); |
| 581 | errdefer t.wait_group.finish(); |
| 582 | |
| 583 | const thread = std.Thread.spawn(.{ .stack_size = t.stack_size }, worker, .{t}) catch |
| 583 | 584 | return error.ConcurrencyUnavailable; |
| 584 | | }; |
| 585 | | t.threads.appendAssumeCapacity(thread); |
| 585 | thread.detach(); |
| 586 | 586 | } |
| 587 | 587 | |
| 588 | | t.mutex.unlock(); |
| 588 | t.run_queue.prepend(&ac.closure.node); |
| 589 | 589 | t.cond.signal(); |
| 590 | 590 | return @ptrCast(ac); |
| 591 | 591 | } |
| ... | ... | @@ -597,7 +597,7 @@ const GroupClosure = struct { |
| 597 | 597 | /// Points to sibling `GroupClosure`. Used for walking the group to cancel all. |
| 598 | 598 | node: std.SinglyLinkedList.Node, |
| 599 | 599 | func: *const fn (*Io.Group, context: *anyopaque) void, |
| 600 | | context_alignment: std.mem.Alignment, |
| 600 | context_alignment: Alignment, |
| 601 | 601 | alloc_len: usize, |
| 602 | 602 | |
| 603 | 603 | fn start(closure: *Closure) void { |
| ... | ... | @@ -638,7 +638,7 @@ const GroupClosure = struct { |
| 638 | 638 | t: *Threaded, |
| 639 | 639 | group: *Io.Group, |
| 640 | 640 | context: []const u8, |
| 641 | | context_alignment: std.mem.Alignment, |
| 641 | context_alignment: Alignment, |
| 642 | 642 | func: *const fn (*Io.Group, context: *const anyopaque) void, |
| 643 | 643 | ) Allocator.Error!*GroupClosure { |
| 644 | 644 | const max_context_misalignment = context_alignment.toByteUnits() -| @alignOf(GroupClosure); |
| ... | ... | @@ -652,7 +652,6 @@ const GroupClosure = struct { |
| 652 | 652 | .closure = .{ |
| 653 | 653 | .cancel_tid = .none, |
| 654 | 654 | .start = start, |
| 655 | | .is_concurrent = false, |
| 656 | 655 | }, |
| 657 | 656 | .t = t, |
| 658 | 657 | .group = group, |
| ... | ... | @@ -678,45 +677,48 @@ fn groupAsync( |
| 678 | 677 | userdata: ?*anyopaque, |
| 679 | 678 | group: *Io.Group, |
| 680 | 679 | context: []const u8, |
| 681 | | context_alignment: std.mem.Alignment, |
| 680 | context_alignment: Alignment, |
| 682 | 681 | start: *const fn (*Io.Group, context: *const anyopaque) void, |
| 683 | 682 | ) void { |
| 684 | | if (builtin.single_threaded) return start(group, context.ptr); |
| 685 | | |
| 686 | 683 | const t: *Threaded = @ptrCast(@alignCast(userdata)); |
| 687 | | const cpu_count = t.cpu_count catch 1; |
| 684 | if (builtin.single_threaded or t.async_limit == .nothing) |
| 685 | return start(group, context.ptr); |
| 688 | 686 | |
| 689 | 687 | const gpa = t.allocator; |
| 690 | | const gc = GroupClosure.init(gpa, t, group, context, context_alignment, start) catch { |
| 688 | const gc = GroupClosure.init(gpa, t, group, context, context_alignment, start) catch |
| 691 | 689 | return start(group, context.ptr); |
| 692 | | }; |
| 693 | 690 | |
| 694 | 691 | t.mutex.lock(); |
| 695 | 692 | |
| 696 | | // Append to the group linked list inside the mutex to make `Io.Group.async` thread-safe. |
| 697 | | gc.node = .{ .next = @ptrCast(@alignCast(group.token)) }; |
| 698 | | group.token = &gc.node; |
| 693 | const busy_count = t.busy_count; |
| 699 | 694 | |
| 700 | | const thread_capacity = cpu_count - 1 + t.concurrent_count; |
| 701 | | |
| 702 | | t.threads.ensureTotalCapacityPrecise(gpa, thread_capacity) catch { |
| 695 | if (busy_count >= @intFromEnum(t.async_limit)) { |
| 703 | 696 | t.mutex.unlock(); |
| 704 | 697 | gc.deinit(gpa); |
| 705 | 698 | return start(group, context.ptr); |
| 706 | | }; |
| 699 | } |
| 707 | 700 | |
| 708 | | t.run_queue.prepend(&gc.closure.node); |
| 701 | t.busy_count = busy_count + 1; |
| 709 | 702 | |
| 710 | | if (t.threads.items.len < thread_capacity) { |
| 703 | const pool_size = t.wait_group.value(); |
| 704 | if (pool_size - busy_count == 0) { |
| 705 | t.wait_group.start(); |
| 711 | 706 | const thread = std.Thread.spawn(.{ .stack_size = t.stack_size }, worker, .{t}) catch { |
| 712 | | assert(t.run_queue.popFirst() == &gc.closure.node); |
| 707 | t.wait_group.finish(); |
| 708 | t.busy_count = busy_count; |
| 713 | 709 | t.mutex.unlock(); |
| 714 | 710 | gc.deinit(gpa); |
| 715 | 711 | return start(group, context.ptr); |
| 716 | 712 | }; |
| 717 | | t.threads.appendAssumeCapacity(thread); |
| 713 | thread.detach(); |
| 718 | 714 | } |
| 719 | 715 | |
| 716 | // Append to the group linked list inside the mutex to make `Io.Group.async` thread-safe. |
| 717 | gc.node = .{ .next = @ptrCast(@alignCast(group.token)) }; |
| 718 | group.token = &gc.node; |
| 719 | |
| 720 | t.run_queue.prepend(&gc.closure.node); |
| 721 | |
| 720 | 722 | // This needs to be done before unlocking the mutex to avoid a race with |
| 721 | 723 | // the associated task finishing. |
| 722 | 724 | const group_state: *std.atomic.Value(usize) = @ptrCast(&group.state); |
| ... | ... | @@ -794,25 +796,25 @@ fn await( |
| 794 | 796 | userdata: ?*anyopaque, |
| 795 | 797 | any_future: *Io.AnyFuture, |
| 796 | 798 | result: []u8, |
| 797 | | result_alignment: std.mem.Alignment, |
| 799 | result_alignment: Alignment, |
| 798 | 800 | ) void { |
| 799 | 801 | _ = result_alignment; |
| 800 | 802 | const t: *Threaded = @ptrCast(@alignCast(userdata)); |
| 801 | 803 | const closure: *AsyncClosure = @ptrCast(@alignCast(any_future)); |
| 802 | | closure.waitAndDeinit(t.allocator, result); |
| 804 | closure.waitAndDeinit(t, result); |
| 803 | 805 | } |
| 804 | 806 | |
| 805 | 807 | fn cancel( |
| 806 | 808 | userdata: ?*anyopaque, |
| 807 | 809 | any_future: *Io.AnyFuture, |
| 808 | 810 | result: []u8, |
| 809 | | result_alignment: std.mem.Alignment, |
| 811 | result_alignment: Alignment, |
| 810 | 812 | ) void { |
| 811 | 813 | _ = result_alignment; |
| 812 | 814 | const t: *Threaded = @ptrCast(@alignCast(userdata)); |
| 813 | 815 | const ac: *AsyncClosure = @ptrCast(@alignCast(any_future)); |
| 814 | 816 | ac.closure.requestCancel(); |
| 815 | | ac.waitAndDeinit(t.allocator, result); |
| 817 | ac.waitAndDeinit(t, result); |
| 816 | 818 | } |
| 817 | 819 | |
| 818 | 820 | fn cancelRequested(userdata: ?*anyopaque) bool { |