authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-02 17:36:08-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-02 17:36:08-04:00
log7f6e97cb26ffabbc192e7ccdf44aebbbc3be751d
tree46e7ff095b47e4d755a9a386b1dc6daf946bde3a
parent65140b2fba4e55d713de506f2bed259ca9410cbf

fixups from the merge


4 files changed, 32 insertions(+), 47 deletions(-)

src-self-hosted/main.zig+2-2
...@@ -694,8 +694,8 @@ async fn asyncFmtMain(...@@ -694,8 +694,8 @@ async fn asyncFmtMain(
694 flags: *const Args,694 flags: *const Args,
695 color: errmsg.Color,695 color: errmsg.Color,
696) FmtError!void {696) FmtError!void {
697 suspend |p| {697 suspend {
698 resume p;698 resume @handle();
699 }699 }
700 // Things we need to make event-based:700 // Things we need to make event-based:
701 // * opening the file in the first place - the open()701 // * opening the file in the first place - the open()
std/event/fs.zig+23-38
...@@ -78,14 +78,9 @@ pub const Request = struct {...@@ -78,14 +78,9 @@ pub const Request = struct {
7878
79/// data - just the inner references - must live until pwritev promise completes.79/// data - just the inner references - must live until pwritev promise completes.
80pub async fn pwritev(loop: *event.Loop, fd: os.FileHandle, offset: usize, data: []const []const u8) !void {80pub async fn pwritev(loop: *event.Loop, fd: os.FileHandle, offset: usize, data: []const []const u8) !void {
81 //const data_dupe = try mem.dupe(loop.allocator, []const u8, data);
82 //defer loop.allocator.free(data_dupe);
83
84 // workaround for https://github.com/ziglang/zig/issues/119481 // workaround for https://github.com/ziglang/zig/issues/1194
85 var my_handle: promise = undefined;82 suspend {
86 suspend |p| {83 resume @handle();
87 my_handle = p;
88 resume p;
89 }84 }
9085
91 const iovecs = try loop.allocator.alloc(os.linux.iovec_const, data.len);86 const iovecs = try loop.allocator.alloc(os.linux.iovec_const, data.len);
...@@ -114,13 +109,13 @@ pub async fn pwritev(loop: *event.Loop, fd: os.FileHandle, offset: usize, data:...@@ -114,13 +109,13 @@ pub async fn pwritev(loop: *event.Loop, fd: os.FileHandle, offset: usize, data:
114 .TickNode = event.Loop.NextTickNode{109 .TickNode = event.Loop.NextTickNode{
115 .prev = undefined,110 .prev = undefined,
116 .next = undefined,111 .next = undefined,
117 .data = my_handle,112 .data = @handle(),
118 },113 },
119 },114 },
120 },115 },
121 };116 };
122117
123 suspend |_| {118 suspend {
124 loop.linuxFsRequest(&req_node);119 loop.linuxFsRequest(&req_node);
125 }120 }
126121
...@@ -133,10 +128,8 @@ pub async fn preadv(loop: *event.Loop, fd: os.FileHandle, offset: usize, data: [...@@ -133,10 +128,8 @@ pub async fn preadv(loop: *event.Loop, fd: os.FileHandle, offset: usize, data: [
133 //defer loop.allocator.free(data_dupe);128 //defer loop.allocator.free(data_dupe);
134129
135 // workaround for https://github.com/ziglang/zig/issues/1194130 // workaround for https://github.com/ziglang/zig/issues/1194
136 var my_handle: promise = undefined;131 suspend {
137 suspend |p| {132 resume @handle();
138 my_handle = p;
139 resume p;
140 }133 }
141134
142 const iovecs = try loop.allocator.alloc(os.linux.iovec, data.len);135 const iovecs = try loop.allocator.alloc(os.linux.iovec, data.len);
...@@ -165,13 +158,13 @@ pub async fn preadv(loop: *event.Loop, fd: os.FileHandle, offset: usize, data: [...@@ -165,13 +158,13 @@ pub async fn preadv(loop: *event.Loop, fd: os.FileHandle, offset: usize, data: [
165 .TickNode = event.Loop.NextTickNode{158 .TickNode = event.Loop.NextTickNode{
166 .prev = undefined,159 .prev = undefined,
167 .next = undefined,160 .next = undefined,
168 .data = my_handle,161 .data = @handle(),
169 },162 },
170 },163 },
171 },164 },
172 };165 };
173166
174 suspend |_| {167 suspend {
175 loop.linuxFsRequest(&req_node);168 loop.linuxFsRequest(&req_node);
176 }169 }
177170
...@@ -180,10 +173,8 @@ pub async fn preadv(loop: *event.Loop, fd: os.FileHandle, offset: usize, data: [...@@ -180,10 +173,8 @@ pub async fn preadv(loop: *event.Loop, fd: os.FileHandle, offset: usize, data: [
180173
181pub async fn openRead(loop: *event.Loop, path: []const u8) os.File.OpenError!os.FileHandle {174pub async fn openRead(loop: *event.Loop, path: []const u8) os.File.OpenError!os.FileHandle {
182 // workaround for https://github.com/ziglang/zig/issues/1194175 // workaround for https://github.com/ziglang/zig/issues/1194
183 var my_handle: promise = undefined;176 suspend {
184 suspend |p| {177 resume @handle();
185 my_handle = p;
186 resume p;
187 }178 }
188179
189 const path_with_null = try std.cstr.addNullByte(loop.allocator, path);180 const path_with_null = try std.cstr.addNullByte(loop.allocator, path);
...@@ -203,13 +194,13 @@ pub async fn openRead(loop: *event.Loop, path: []const u8) os.File.OpenError!os....@@ -203,13 +194,13 @@ pub async fn openRead(loop: *event.Loop, path: []const u8) os.File.OpenError!os.
203 .TickNode = event.Loop.NextTickNode{194 .TickNode = event.Loop.NextTickNode{
204 .prev = undefined,195 .prev = undefined,
205 .next = undefined,196 .next = undefined,
206 .data = my_handle,197 .data = @handle(),
207 },198 },
208 },199 },
209 },200 },
210 };201 };
211202
212 suspend |_| {203 suspend {
213 loop.linuxFsRequest(&req_node);204 loop.linuxFsRequest(&req_node);
214 }205 }
215206
...@@ -223,10 +214,8 @@ pub async fn openReadWrite(...@@ -223,10 +214,8 @@ pub async fn openReadWrite(
223 mode: os.File.Mode,214 mode: os.File.Mode,
224) os.File.OpenError!os.FileHandle {215) os.File.OpenError!os.FileHandle {
225 // workaround for https://github.com/ziglang/zig/issues/1194216 // workaround for https://github.com/ziglang/zig/issues/1194
226 var my_handle: promise = undefined;217 suspend {
227 suspend |p| {218 resume @handle();
228 my_handle = p;
229 resume p;
230 }219 }
231220
232 const path_with_null = try std.cstr.addNullByte(loop.allocator, path);221 const path_with_null = try std.cstr.addNullByte(loop.allocator, path);
...@@ -247,13 +236,13 @@ pub async fn openReadWrite(...@@ -247,13 +236,13 @@ pub async fn openReadWrite(
247 .TickNode = event.Loop.NextTickNode{236 .TickNode = event.Loop.NextTickNode{
248 .prev = undefined,237 .prev = undefined,
249 .next = undefined,238 .next = undefined,
250 .data = my_handle,239 .data = @handle(),
251 },240 },
252 },241 },
253 },242 },
254 };243 };
255244
256 suspend |_| {245 suspend {
257 loop.linuxFsRequest(&req_node);246 loop.linuxFsRequest(&req_node);
258 }247 }
259248
...@@ -311,10 +300,8 @@ pub async fn writeFile(loop: *event.Loop, path: []const u8, contents: []const u8...@@ -311,10 +300,8 @@ pub async fn writeFile(loop: *event.Loop, path: []const u8, contents: []const u8
311/// contents must remain alive until writeFile completes.300/// contents must remain alive until writeFile completes.
312pub async fn writeFileMode(loop: *event.Loop, path: []const u8, contents: []const u8, mode: os.File.Mode) !void {301pub async fn writeFileMode(loop: *event.Loop, path: []const u8, contents: []const u8, mode: os.File.Mode) !void {
313 // workaround for https://github.com/ziglang/zig/issues/1194302 // workaround for https://github.com/ziglang/zig/issues/1194
314 var my_handle: promise = undefined;303 suspend {
315 suspend |p| {304 resume @handle();
316 my_handle = p;
317 resume p;
318 }305 }
319306
320 const path_with_null = try std.cstr.addNullByte(loop.allocator, path);307 const path_with_null = try std.cstr.addNullByte(loop.allocator, path);
...@@ -336,13 +323,13 @@ pub async fn writeFileMode(loop: *event.Loop, path: []const u8, contents: []cons...@@ -336,13 +323,13 @@ pub async fn writeFileMode(loop: *event.Loop, path: []const u8, contents: []cons
336 .TickNode = event.Loop.NextTickNode{323 .TickNode = event.Loop.NextTickNode{
337 .prev = undefined,324 .prev = undefined,
338 .next = undefined,325 .next = undefined,
339 .data = my_handle,326 .data = @handle(),
340 },327 },
341 },328 },
342 },329 },
343 };330 };
344331
345 suspend |_| {332 suspend {
346 loop.linuxFsRequest(&req_node);333 loop.linuxFsRequest(&req_node);
347 }334 }
348335
...@@ -420,14 +407,12 @@ pub fn watchFile(loop: *event.Loop, file_path: []const u8) !*Watch {...@@ -420,14 +407,12 @@ pub fn watchFile(loop: *event.Loop, file_path: []const u8) !*Watch {
420407
421async fn watchEventPutter(inotify_fd: i32, wd: i32, channel: *event.Channel(Watch.Event), out_watch: **Watch) void {408async fn watchEventPutter(inotify_fd: i32, wd: i32, channel: *event.Channel(Watch.Event), out_watch: **Watch) void {
422 // TODO https://github.com/ziglang/zig/issues/1194409 // TODO https://github.com/ziglang/zig/issues/1194
423 var my_handle: promise = undefined;410 suspend {
424 suspend |p| {411 resume @handle();
425 my_handle = p;
426 resume p;
427 }412 }
428413
429 var watch = Watch{414 var watch = Watch{
430 .putter = my_handle,415 .putter = @handle(),
431 .channel = channel,416 .channel = channel,
432 };417 };
433 out_watch.* = &watch;418 out_watch.* = &watch;
std/event/lock.zig+1-1
...@@ -98,7 +98,7 @@ pub const Lock = struct {...@@ -98,7 +98,7 @@ pub const Lock = struct {
98 var my_tick_node = Loop.NextTickNode.init(@handle());98 var my_tick_node = Loop.NextTickNode.init(@handle());
9999
100 errdefer _ = self.queue.remove(&my_tick_node); // TODO test canceling an acquire100 errdefer _ = self.queue.remove(&my_tick_node); // TODO test canceling an acquire
101 suspend |_| {101 suspend {
102 self.queue.put(&my_tick_node);102 self.queue.put(&my_tick_node);
103103
104 // At this point, we are in the queue, so we might have already been resumed and this coroutine104 // At this point, we are in the queue, so we might have already been resumed and this coroutine
std/event/rwlock.zig+6-6
...@@ -97,10 +97,10 @@ pub const RwLock = struct {...@@ -97,10 +97,10 @@ pub const RwLock = struct {
97 pub async fn acquireRead(self: *RwLock) HeldRead {97 pub async fn acquireRead(self: *RwLock) HeldRead {
98 _ = @atomicRmw(usize, &self.reader_lock_count, AtomicRmwOp.Add, 1, AtomicOrder.SeqCst);98 _ = @atomicRmw(usize, &self.reader_lock_count, AtomicRmwOp.Add, 1, AtomicOrder.SeqCst);
9999
100 suspend |handle| {100 suspend {
101 // TODO explicitly put this memory in the coroutine frame #1194101 // TODO explicitly put this memory in the coroutine frame #1194
102 var my_tick_node = Loop.NextTickNode{102 var my_tick_node = Loop.NextTickNode{
103 .data = handle,103 .data = @handle(),
104 .prev = undefined,104 .prev = undefined,
105 .next = undefined,105 .next = undefined,
106 };106 };
...@@ -130,10 +130,10 @@ pub const RwLock = struct {...@@ -130,10 +130,10 @@ pub const RwLock = struct {
130 }130 }
131131
132 pub async fn acquireWrite(self: *RwLock) HeldWrite {132 pub async fn acquireWrite(self: *RwLock) HeldWrite {
133 suspend |handle| {133 suspend {
134 // TODO explicitly put this memory in the coroutine frame #1194134 // TODO explicitly put this memory in the coroutine frame #1194
135 var my_tick_node = Loop.NextTickNode{135 var my_tick_node = Loop.NextTickNode{
136 .data = handle,136 .data = @handle(),
137 .prev = undefined,137 .prev = undefined,
138 .next = undefined,138 .next = undefined,
139 };139 };
...@@ -231,8 +231,8 @@ test "std.event.RwLock" {...@@ -231,8 +231,8 @@ test "std.event.RwLock" {
231231
232async fn testLock(loop: *Loop, lock: *RwLock) void {232async fn testLock(loop: *Loop, lock: *RwLock) void {
233 // TODO explicitly put next tick node memory in the coroutine frame #1194233 // TODO explicitly put next tick node memory in the coroutine frame #1194
234 suspend |p| {234 suspend {
235 resume p;235 resume @handle();
236 }236 }
237237
238 var read_nodes: [100]Loop.NextTickNode = undefined;238 var read_nodes: [100]Loop.NextTickNode = undefined;