From af96e8fcdd08d9bd2e84e7e8cc7fc404d683b4cc Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Mon, 17 Apr 2023 23:03:58 -0700 Subject: Remove spin loop in `bun build` --- src/bun.js/event_loop.zig | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'src/bun.js') diff --git a/src/bun.js/event_loop.zig b/src/bun.js/event_loop.zig index 35ba93eaa..cf0b046ec 100644 --- a/src/bun.js/event_loop.zig +++ b/src/bun.js/event_loop.zig @@ -763,20 +763,17 @@ pub const MiniEventLoop = struct { pub fn tick( this: *MiniEventLoop, context: *anyopaque, + comptime isDone: fn (*anyopaque) bool, ) void { - while (true) { - _ = this.tickConcurrentWithCount(); - while (this.tasks.readItem()) |task| { - task.run(context); + while (!isDone(context)) { + if (this.tickConcurrentWithCount() == 0 and this.tasks.count == 0) { + this.loop.num_polls += 1; + this.loop.tick(); + this.loop.num_polls -= 1; } - if (this.tickConcurrentWithCount() == 0) { - if (this.loop.active > 0 or this.loop.num_polls > 0) { - this.loop.run(); - continue; - } - - break; + while (this.tasks.readItem()) |task| { + task.run(context); } } } @@ -845,6 +842,7 @@ pub const AnyEventLoop = union(enum) { pub fn tick( this: *AnyEventLoop, context: *anyopaque, + comptime isDone: fn (*anyopaque) bool, ) void { switch (this.*) { .jsc => { @@ -852,7 +850,7 @@ pub const AnyEventLoop = union(enum) { this.jsc.autoTick(); }, .mini => { - this.mini.tick(context); + this.mini.tick(context, isDone); }, } } -- cgit v1.2.3