fix event loop regression on macos

master
Andrew Kelley 2019-08-17 11:40:48 -04:00
parent e24cc2e77b
commit 456a244d62
2 changed files with 9 additions and 9 deletions

View File

@ -97,28 +97,27 @@ test "std.event.Future" {
loop.run(); loop.run();
} }
async fn testFuture(loop: *Loop) void { fn testFuture(loop: *Loop) void {
var future = Future(i32).init(loop); var future = Future(i32).init(loop);
var a = async waitOnFuture(&future); var a = async waitOnFuture(&future);
var b = async waitOnFuture(&future); var b = async waitOnFuture(&future);
var c = async resolveFuture(&future); resolveFuture(&future);
// TODO make this work: // TODO https://github.com/ziglang/zig/issues/3077
//const result = (await a) + (await b); //const result = (await a) + (await b);
const a_result = await a; const a_result = await a;
const b_result = await b; const b_result = await b;
const result = a_result + b_result; const result = a_result + b_result;
await c;
testing.expect(result == 12); testing.expect(result == 12);
} }
async fn waitOnFuture(future: *Future(i32)) i32 { fn waitOnFuture(future: *Future(i32)) i32 {
return future.get().*; return future.get().*;
} }
async fn resolveFuture(future: *Future(i32)) void { fn resolveFuture(future: *Future(i32)) void {
future.data = 6; future.data = 6;
future.resolve(); future.resolve();
} }

View File

@ -149,14 +149,15 @@ pub const Loop = struct {
.overlapped = ResumeNode.overlapped_init, .overlapped = ResumeNode.overlapped_init,
}, },
}; };
// We need an extra one of these in case the fs thread wants to use onNextTick // We need at least one of these in case the fs thread wants to use onNextTick
const extra_thread_count = thread_count - 1;
const resume_node_count = std.math.max(extra_thread_count, 1);
self.eventfd_resume_nodes = try self.allocator.alloc( self.eventfd_resume_nodes = try self.allocator.alloc(
std.atomic.Stack(ResumeNode.EventFd).Node, std.atomic.Stack(ResumeNode.EventFd).Node,
thread_count, resume_node_count,
); );
errdefer self.allocator.free(self.eventfd_resume_nodes); errdefer self.allocator.free(self.eventfd_resume_nodes);
const extra_thread_count = thread_count - 1;
self.extra_threads = try self.allocator.alloc(*Thread, extra_thread_count); self.extra_threads = try self.allocator.alloc(*Thread, extra_thread_count);
errdefer self.allocator.free(self.extra_threads); errdefer self.allocator.free(self.extra_threads);