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(
694694 flags: *const Args,
695695 color: errmsg.Color,
696696) FmtError!void {
697 suspend |p| {
698 resume p;
697 suspend {
698 resume @handle();
699699 }
700700 // Things we need to make event-based:
701701 // * opening the file in the first place - the open()
std/event/fs.zig+23-38
......@@ -78,14 +78,9 @@ pub const Request = struct {
7878
7979/// data - just the inner references - must live until pwritev promise completes.
8080pub 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
8481 // workaround for https://github.com/ziglang/zig/issues/1194
85 var my_handle: promise = undefined;
86 suspend |p| {
87 my_handle = p;
88 resume p;
82 suspend {
83 resume @handle();
8984 }
9085
9186 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:
114109 .TickNode = event.Loop.NextTickNode{
115110 .prev = undefined,
116111 .next = undefined,
117 .data = my_handle,
112 .data = @handle(),
118113 },
119114 },
120115 },
121116 };
122117
123 suspend |_| {
118 suspend {
124119 loop.linuxFsRequest(&req_node);
125120 }
126121
......@@ -133,10 +128,8 @@ pub async fn preadv(loop: *event.Loop, fd: os.FileHandle, offset: usize, data: [
133128 //defer loop.allocator.free(data_dupe);
134129
135130 // workaround for https://github.com/ziglang/zig/issues/1194
136 var my_handle: promise = undefined;
137 suspend |p| {
138 my_handle = p;
139 resume p;
131 suspend {
132 resume @handle();
140133 }
141134
142135 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: [
165158 .TickNode = event.Loop.NextTickNode{
166159 .prev = undefined,
167160 .next = undefined,
168 .data = my_handle,
161 .data = @handle(),
169162 },
170163 },
171164 },
172165 };
173166
174 suspend |_| {
167 suspend {
175168 loop.linuxFsRequest(&req_node);
176169 }
177170
......@@ -180,10 +173,8 @@ pub async fn preadv(loop: *event.Loop, fd: os.FileHandle, offset: usize, data: [
180173
181174pub async fn openRead(loop: *event.Loop, path: []const u8) os.File.OpenError!os.FileHandle {
182175 // workaround for https://github.com/ziglang/zig/issues/1194
183 var my_handle: promise = undefined;
184 suspend |p| {
185 my_handle = p;
186 resume p;
176 suspend {
177 resume @handle();
187178 }
188179
189180 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.
203194 .TickNode = event.Loop.NextTickNode{
204195 .prev = undefined,
205196 .next = undefined,
206 .data = my_handle,
197 .data = @handle(),
207198 },
208199 },
209200 },
210201 };
211202
212 suspend |_| {
203 suspend {
213204 loop.linuxFsRequest(&req_node);
214205 }
215206
......@@ -223,10 +214,8 @@ pub async fn openReadWrite(
223214 mode: os.File.Mode,
224215) os.File.OpenError!os.FileHandle {
225216 // workaround for https://github.com/ziglang/zig/issues/1194
226 var my_handle: promise = undefined;
227 suspend |p| {
228 my_handle = p;
229 resume p;
217 suspend {
218 resume @handle();
230219 }
231220
232221 const path_with_null = try std.cstr.addNullByte(loop.allocator, path);
......@@ -247,13 +236,13 @@ pub async fn openReadWrite(
247236 .TickNode = event.Loop.NextTickNode{
248237 .prev = undefined,
249238 .next = undefined,
250 .data = my_handle,
239 .data = @handle(),
251240 },
252241 },
253242 },
254243 };
255244
256 suspend |_| {
245 suspend {
257246 loop.linuxFsRequest(&req_node);
258247 }
259248
......@@ -311,10 +300,8 @@ pub async fn writeFile(loop: *event.Loop, path: []const u8, contents: []const u8
311300/// contents must remain alive until writeFile completes.
312301pub async fn writeFileMode(loop: *event.Loop, path: []const u8, contents: []const u8, mode: os.File.Mode) !void {
313302 // workaround for https://github.com/ziglang/zig/issues/1194
314 var my_handle: promise = undefined;
315 suspend |p| {
316 my_handle = p;
317 resume p;
303 suspend {
304 resume @handle();
318305 }
319306
320307 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
336323 .TickNode = event.Loop.NextTickNode{
337324 .prev = undefined,
338325 .next = undefined,
339 .data = my_handle,
326 .data = @handle(),
340327 },
341328 },
342329 },
343330 };
344331
345 suspend |_| {
332 suspend {
346333 loop.linuxFsRequest(&req_node);
347334 }
348335
......@@ -420,14 +407,12 @@ pub fn watchFile(loop: *event.Loop, file_path: []const u8) !*Watch {
420407
421408async fn watchEventPutter(inotify_fd: i32, wd: i32, channel: *event.Channel(Watch.Event), out_watch: **Watch) void {
422409 // TODO https://github.com/ziglang/zig/issues/1194
423 var my_handle: promise = undefined;
424 suspend |p| {
425 my_handle = p;
426 resume p;
410 suspend {
411 resume @handle();
427412 }
428413
429414 var watch = Watch{
430 .putter = my_handle,
415 .putter = @handle(),
431416 .channel = channel,
432417 };
433418 out_watch.* = &watch;
std/event/lock.zig+1-1
......@@ -98,7 +98,7 @@ pub const Lock = struct {
9898 var my_tick_node = Loop.NextTickNode.init(@handle());
9999
100100 errdefer _ = self.queue.remove(&my_tick_node); // TODO test canceling an acquire
101 suspend |_| {
101 suspend {
102102 self.queue.put(&my_tick_node);
103103
104104 // 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 {
9797 pub async fn acquireRead(self: *RwLock) HeldRead {
9898 _ = @atomicRmw(usize, &self.reader_lock_count, AtomicRmwOp.Add, 1, AtomicOrder.SeqCst);
9999
100 suspend |handle| {
100 suspend {
101101 // TODO explicitly put this memory in the coroutine frame #1194
102102 var my_tick_node = Loop.NextTickNode{
103 .data = handle,
103 .data = @handle(),
104104 .prev = undefined,
105105 .next = undefined,
106106 };
......@@ -130,10 +130,10 @@ pub const RwLock = struct {
130130 }
131131
132132 pub async fn acquireWrite(self: *RwLock) HeldWrite {
133 suspend |handle| {
133 suspend {
134134 // TODO explicitly put this memory in the coroutine frame #1194
135135 var my_tick_node = Loop.NextTickNode{
136 .data = handle,
136 .data = @handle(),
137137 .prev = undefined,
138138 .next = undefined,
139139 };
......@@ -231,8 +231,8 @@ test "std.event.RwLock" {
231231
232232async fn testLock(loop: *Loop, lock: *RwLock) void {
233233 // TODO explicitly put next tick node memory in the coroutine frame #1194
234 suspend |p| {
235 resume p;
234 suspend {
235 resume @handle();
236236 }
237237
238238 var read_nodes: [100]Loop.NextTickNode = undefined;