authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-17 11:40:48-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-17 11:40:48-04:00
log456a244d62df62940f4d860cd9f57b40d563ca96
tree24f2b2abba0032003141b517cd782f0520fcd089
parente24cc2e77b741fe49e738acc497fbedf2998008c

fix event loop regression on macos


2 files changed, 9 insertions(+), 9 deletions(-)

std/event/future.zig+5-6
...@@ -97,28 +97,27 @@ test "std.event.Future" {...@@ -97,28 +97,27 @@ test "std.event.Future" {
97 loop.run();97 loop.run();
98}98}
9999
100async fn testFuture(loop: *Loop) void {100fn testFuture(loop: *Loop) void {
101 var future = Future(i32).init(loop);101 var future = Future(i32).init(loop);
102102
103 var a = async waitOnFuture(&future);103 var a = async waitOnFuture(&future);
104 var b = async waitOnFuture(&future);104 var b = async waitOnFuture(&future);
105 var c = async resolveFuture(&future);105 resolveFuture(&future);
106106
107 // TODO make this work:107 // TODO https://github.com/ziglang/zig/issues/3077
108 //const result = (await a) + (await b);108 //const result = (await a) + (await b);
109 const a_result = await a;109 const a_result = await a;
110 const b_result = await b;110 const b_result = await b;
111 const result = a_result + b_result;111 const result = a_result + b_result;
112112
113 await c;
114 testing.expect(result == 12);113 testing.expect(result == 12);
115}114}
116115
117async fn waitOnFuture(future: *Future(i32)) i32 {116fn waitOnFuture(future: *Future(i32)) i32 {
118 return future.get().*;117 return future.get().*;
119}118}
120119
121async fn resolveFuture(future: *Future(i32)) void {120fn resolveFuture(future: *Future(i32)) void {
122 future.data = 6;121 future.data = 6;
123 future.resolve();122 future.resolve();
124}123}
std/event/loop.zig+4-3
...@@ -149,14 +149,15 @@ pub const Loop = struct {...@@ -149,14 +149,15 @@ pub const Loop = struct {
149 .overlapped = ResumeNode.overlapped_init,149 .overlapped = ResumeNode.overlapped_init,
150 },150 },
151 };151 };
152 // We need an extra one of these in case the fs thread wants to use onNextTick152 // We need at least one of these in case the fs thread wants to use onNextTick
153 const extra_thread_count = thread_count - 1;
154 const resume_node_count = std.math.max(extra_thread_count, 1);
153 self.eventfd_resume_nodes = try self.allocator.alloc(155 self.eventfd_resume_nodes = try self.allocator.alloc(
154 std.atomic.Stack(ResumeNode.EventFd).Node,156 std.atomic.Stack(ResumeNode.EventFd).Node,
155 thread_count,157 resume_node_count,
156 );158 );
157 errdefer self.allocator.free(self.eventfd_resume_nodes);159 errdefer self.allocator.free(self.eventfd_resume_nodes);
158160
159 const extra_thread_count = thread_count - 1;
160 self.extra_threads = try self.allocator.alloc(*Thread, extra_thread_count);161 self.extra_threads = try self.allocator.alloc(*Thread, extra_thread_count);
161 errdefer self.allocator.free(self.extra_threads);162 errdefer self.allocator.free(self.extra_threads);
162163