@@ -107,7 +107,6 @@ pub fn main() !void {
107107
108108 var targets = std .array_list .Managed ([]const u8 ).init (arena );
109109 var debug_log_scopes = std .array_list .Managed ([]const u8 ).init (arena );
110- var thread_pool_options : std.Thread.Pool.Options = .{ .allocator = arena };
111110
112111 var install_prefix : ? []const u8 = null ;
113112 var dir_list = std.Build.DirList {};
@@ -413,19 +412,11 @@ pub fn main() !void {
413412 };
414413 } else if (mem .eql (u8 , arg , "-fno-reference-trace" )) {
415414 builder .reference_trace = null ;
416- } else if (mem .startsWith (u8 , arg , "-j" )) {
417- const num = arg ["-j" .len .. ];
418- const n_jobs = std .fmt .parseUnsigned (u32 , num , 10 ) catch | err | {
419- std .debug .print ("unable to parse jobs count '{s}': {s}" , .{
420- num , @errorName (err ),
421- });
422- process .exit (1 );
423- };
424- if (n_jobs < 1 ) {
425- std .debug .print ("number of jobs must be at least 1\n " , .{});
426- process .exit (1 );
427- }
428- thread_pool_options .n_jobs = n_jobs ;
415+ } else if (mem .cutPrefix (u8 , arg , "-j" )) | text | {
416+ const n = std .fmt .parseUnsigned (u32 , text , 10 ) catch | err |
417+ fatal ("unable to parse jobs count '{s}': {t}" , .{ text , err });
418+ if (n < 1 ) fatal ("number of jobs must be at least 1" , .{});
419+ threaded .setAsyncLimit (.limited (n ));
429420 } else if (mem .eql (u8 , arg , "--" )) {
430421 builder .args = argsRest (args , arg_idx );
431422 break ;
@@ -516,7 +507,6 @@ pub fn main() !void {
516507 .error_style = error_style ,
517508 .multiline_errors = multiline_errors ,
518509 .summary = summary orelse if (watch or webui_listen != null ) .line else .failures ,
519- .thread_pool = undefined ,
520510
521511 .ttyconf = ttyconf ,
522512 };
@@ -547,16 +537,12 @@ pub fn main() !void {
547537 break :w try .init ();
548538 };
549539
550- try run .thread_pool .init (thread_pool_options );
551- defer run .thread_pool .deinit ();
552-
553540 const now = Io .Clock .Timestamp .now (io , .awake ) catch | err | fatal ("failed to collect timestamp: {t}" , .{err });
554541
555542 run .web_server = if (webui_listen ) | listen_address | ws : {
556543 if (builtin .single_threaded ) unreachable ; // `fatal` above
557544 break :ws .init (.{
558545 .gpa = gpa ,
559- .thread_pool = & run .thread_pool ,
560546 .ttyconf = ttyconf ,
561547 .graph = & graph ,
562548 .all_steps = run .step_stack .keys (),
@@ -675,7 +661,6 @@ const Run = struct {
675661 memory_blocked_steps : std .ArrayList (* Step ),
676662 /// Allocated into `gpa`.
677663 step_stack : std .AutoArrayHashMapUnmanaged (* Step , void ),
678- thread_pool : std.Thread.Pool ,
679664 /// Similar to the `tty.Config` returned by `std.debug.lockStderrWriter`,
680665 /// but also respects the '--color' flag.
681666 ttyconf : tty.Config ,
@@ -754,14 +739,13 @@ fn runStepNames(
754739 const gpa = run .gpa ;
755740 const io = b .graph .io ;
756741 const step_stack = & run .step_stack ;
757- const thread_pool = & run .thread_pool ;
758742
759743 {
760744 const step_prog = parent_prog_node .start ("steps" , step_stack .count ());
761745 defer step_prog .end ();
762746
763- var wait_group : std.Thread.WaitGroup = .{} ;
764- defer wait_group .wait ();
747+ var group : Io.Group = .init ;
748+ defer group .wait (io );
765749
766750 // Here we spawn the initial set of tasks with a nice heuristic -
767751 // dependency order. Each worker when it finishes a step will then
@@ -771,9 +755,7 @@ fn runStepNames(
771755 const step = steps_slice [steps_slice .len - i - 1 ];
772756 if (step .state == .skipped_oom ) continue ;
773757
774- thread_pool .spawnWg (& wait_group , workerMakeOneStep , .{
775- & wait_group , b , step , step_prog , run ,
776- });
758+ group .async (io , workerMakeOneStep , .{ & group , b , step , step_prog , run });
777759 }
778760 }
779761
@@ -855,7 +837,6 @@ fn runStepNames(
855837 var f = std .Build .Fuzz .init (
856838 gpa ,
857839 io ,
858- thread_pool ,
859840 run .ttyconf ,
860841 step_stack .keys (),
861842 parent_prog_node ,
@@ -1318,14 +1299,12 @@ fn constructGraphAndCheckForDependencyLoop(
13181299}
13191300
13201301fn workerMakeOneStep (
1321- wg : * std.Thread.WaitGroup ,
1302+ group : * Io.Group ,
13221303 b : * std.Build ,
13231304 s : * Step ,
13241305 prog_node : std.Progress.Node ,
13251306 run : * Run ,
13261307) void {
1327- const thread_pool = & run .thread_pool ;
1328-
13291308 // First, check the conditions for running this step. If they are not met,
13301309 // then we return without doing the step, relying on another worker to
13311310 // queue this step up again when dependencies are met.
@@ -1381,7 +1360,6 @@ fn workerMakeOneStep(
13811360
13821361 const make_result = s .make (.{
13831362 .progress_node = sub_prog_node ,
1384- .thread_pool = thread_pool ,
13851363 .watch = run .watch ,
13861364 .web_server = if (run .web_server ) | * ws | ws else null ,
13871365 .ttyconf = run .ttyconf ,
@@ -1400,6 +1378,8 @@ fn workerMakeOneStep(
14001378 printErrorMessages (run .gpa , s , .{}, bw , ttyconf , run .error_style , run .multiline_errors ) catch {};
14011379 }
14021380
1381+ const io = b .graph .io ;
1382+
14031383 handle_result : {
14041384 if (make_result ) | _ | {
14051385 @atomicStore (Step .State , & s .state , .success , .seq_cst );
@@ -1419,9 +1399,7 @@ fn workerMakeOneStep(
14191399
14201400 // Successful completion of a step, so we queue up its dependants as well.
14211401 for (s .dependants .items ) | dep | {
1422- thread_pool .spawnWg (wg , workerMakeOneStep , .{
1423- wg , b , dep , prog_node , run ,
1424- });
1402+ group .async (io , workerMakeOneStep , .{ group , b , dep , prog_node , run });
14251403 }
14261404 }
14271405
@@ -1444,9 +1422,7 @@ fn workerMakeOneStep(
14441422 if (dep .max_rss <= remaining ) {
14451423 remaining -= dep .max_rss ;
14461424
1447- thread_pool .spawnWg (wg , workerMakeOneStep , .{
1448- wg , b , dep , prog_node , run ,
1449- });
1425+ group .async (io , workerMakeOneStep , .{ group , b , dep , prog_node , run });
14501426 } else {
14511427 run .memory_blocked_steps .items [i ] = dep ;
14521428 i += 1 ;
0 commit comments