authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-08 15:13:05-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-08 15:13:05-04:00
logcfe84423c97eb2121138c2de5876c47782cd6dda
tree026afba62a3c412cee5fb4c40e4208f1e3038a3c
parentbfa1d12fbad2031402fbafe51c3a0c481fe69351
signaturelock-open Commit is signed but in an unrecognized format.

fix segfault with var args


3 files changed, 143 insertions(+), 148 deletions(-)

src/ir.cpp+5-3
......@@ -15746,7 +15746,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1574615746 size_t impl_param_count = impl_fn_type_id->param_count;
1574715747 if (call_instruction->is_async) {
1574815748 IrInstruction *result = ir_analyze_async_call(ira, call_instruction, impl_fn, impl_fn->type_entry,
15749 nullptr, casted_args, call_param_count, casted_new_stack);
15749 nullptr, casted_args, impl_param_count, casted_new_stack);
1575015750 return ir_finish_anal(ira, result);
1575115751 }
1575215752
......@@ -15756,7 +15756,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1575615756
1575715757 IrInstructionCallGen *new_call_instruction = ir_build_call_gen(ira, &call_instruction->base,
1575815758 impl_fn, nullptr, impl_param_count, casted_args, fn_inline,
15759 call_instruction->is_async, casted_new_stack, result_loc,
15759 false, casted_new_stack, result_loc,
1576015760 impl_fn_type_id->return_type);
1576115761
1576215762 parent_fn_entry->call_list.append(new_call_instruction);
......@@ -15799,7 +15799,9 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1579915799 casted_args[next_arg_index] = casted_arg;
1580015800 next_arg_index += 1;
1580115801 }
15802 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {
15802 size_t iter_count = (call_param_count < call_instruction->arg_count) ?
15803 call_param_count : call_instruction->arg_count;
15804 for (size_t call_i = 0; call_i < iter_count; call_i += 1) {
1580315805 IrInstruction *old_arg = call_instruction->args[call_i]->child;
1580415806 if (type_is_invalid(old_arg->value.type))
1580515807 return ira->codegen->invalid_instruction;
std/event/fs.zig+60-60
......@@ -83,10 +83,10 @@ pub async fn pwritev(loop: *Loop, fd: fd_t, data: []const []const u8, offset: us
8383 resume @handle();
8484 }
8585 switch (builtin.os) {
86 builtin.Os.macosx,
87 builtin.Os.linux,
88 builtin.Os.freebsd,
89 builtin.Os.netbsd,
86 .macosx,
87 .linux,
88 .freebsd,
89 .netbsd,
9090 => {
9191 const iovecs = try loop.allocator.alloc(os.iovec_const, data.len);
9292 defer loop.allocator.free(iovecs);
......@@ -100,7 +100,7 @@ pub async fn pwritev(loop: *Loop, fd: fd_t, data: []const []const u8, offset: us
100100
101101 return await (async pwritevPosix(loop, fd, iovecs, offset) catch unreachable);
102102 },
103 builtin.Os.windows => {
103 .windows => {
104104 const data_copy = try std.mem.dupe(loop.allocator, []const u8, data);
105105 defer loop.allocator.free(data_copy);
106106 return await (async pwritevWindows(loop, fd, data, offset) catch unreachable);
......@@ -220,10 +220,10 @@ pub async fn preadv(loop: *Loop, fd: fd_t, data: []const []u8, offset: usize) PR
220220
221221 assert(data.len != 0);
222222 switch (builtin.os) {
223 builtin.Os.macosx,
224 builtin.Os.linux,
225 builtin.Os.freebsd,
226 builtin.Os.netbsd,
223 .macosx,
224 .linux,
225 .freebsd,
226 .netbsd,
227227 => {
228228 const iovecs = try loop.allocator.alloc(os.iovec, data.len);
229229 defer loop.allocator.free(iovecs);
......@@ -237,7 +237,7 @@ pub async fn preadv(loop: *Loop, fd: fd_t, data: []const []u8, offset: usize) PR
237237
238238 return await (async preadvPosix(loop, fd, iovecs, offset) catch unreachable);
239239 },
240 builtin.Os.windows => {
240 .windows => {
241241 const data_copy = try std.mem.dupe(loop.allocator, []u8, data);
242242 defer loop.allocator.free(data_copy);
243243 return await (async preadvWindows(loop, fd, data_copy, offset) catch unreachable);
......@@ -403,12 +403,12 @@ pub async fn openPosix(
403403
404404pub async fn openRead(loop: *Loop, path: []const u8) File.OpenError!fd_t {
405405 switch (builtin.os) {
406 builtin.Os.macosx, builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => {
406 .macosx, .linux, .freebsd, .netbsd => {
407407 const flags = os.O_LARGEFILE | os.O_RDONLY | os.O_CLOEXEC;
408408 return await (async openPosix(loop, path, flags, File.default_mode) catch unreachable);
409409 },
410410
411 builtin.Os.windows => return windows.CreateFile(
411 .windows => return windows.CreateFile(
412412 path,
413413 windows.GENERIC_READ,
414414 windows.FILE_SHARE_READ,
......@@ -431,15 +431,15 @@ pub async fn openWrite(loop: *Loop, path: []const u8) File.OpenError!fd_t {
431431/// Creates if does not exist. Truncates the file if it exists.
432432pub async fn openWriteMode(loop: *Loop, path: []const u8, mode: File.Mode) File.OpenError!fd_t {
433433 switch (builtin.os) {
434 builtin.Os.macosx,
435 builtin.Os.linux,
436 builtin.Os.freebsd,
437 builtin.Os.netbsd,
434 .macosx,
435 .linux,
436 .freebsd,
437 .netbsd,
438438 => {
439439 const flags = os.O_LARGEFILE | os.O_WRONLY | os.O_CREAT | os.O_CLOEXEC | os.O_TRUNC;
440440 return await (async openPosix(loop, path, flags, File.default_mode) catch unreachable);
441441 },
442 builtin.Os.windows => return windows.CreateFile(
442 .windows => return windows.CreateFile(
443443 path,
444444 windows.GENERIC_WRITE,
445445 windows.FILE_SHARE_WRITE | windows.FILE_SHARE_READ | windows.FILE_SHARE_DELETE,
......@@ -459,12 +459,12 @@ pub async fn openReadWrite(
459459 mode: File.Mode,
460460) File.OpenError!fd_t {
461461 switch (builtin.os) {
462 builtin.Os.macosx, builtin.Os.linux, builtin.Os.freebsd, builtin.Os.netbsd => {
462 .macosx, .linux, .freebsd, .netbsd => {
463463 const flags = os.O_LARGEFILE | os.O_RDWR | os.O_CREAT | os.O_CLOEXEC;
464464 return await (async openPosix(loop, path, flags, mode) catch unreachable);
465465 },
466466
467 builtin.Os.windows => return windows.CreateFile(
467 .windows => return windows.CreateFile(
468468 path,
469469 windows.GENERIC_WRITE | windows.GENERIC_READ,
470470 windows.FILE_SHARE_WRITE | windows.FILE_SHARE_READ | windows.FILE_SHARE_DELETE,
......@@ -489,9 +489,9 @@ pub const CloseOperation = struct {
489489 os_data: OsData,
490490
491491 const OsData = switch (builtin.os) {
492 builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => OsDataPosix,
492 .linux, .macosx, .freebsd, .netbsd => OsDataPosix,
493493
494 builtin.Os.windows => struct {
494 .windows => struct {
495495 handle: ?fd_t,
496496 },
497497
......@@ -508,8 +508,8 @@ pub const CloseOperation = struct {
508508 self.* = CloseOperation{
509509 .loop = loop,
510510 .os_data = switch (builtin.os) {
511 builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => initOsDataPosix(self),
512 builtin.Os.windows => OsData{ .handle = null },
511 .linux, .macosx, .freebsd, .netbsd => initOsDataPosix(self),
512 .windows => OsData{ .handle = null },
513513 else => @compileError("Unsupported OS"),
514514 },
515515 };
......@@ -535,10 +535,10 @@ pub const CloseOperation = struct {
535535 /// Defer this after creating.
536536 pub fn finish(self: *CloseOperation) void {
537537 switch (builtin.os) {
538 builtin.Os.linux,
539 builtin.Os.macosx,
540 builtin.Os.freebsd,
541 builtin.Os.netbsd,
538 .linux,
539 .macosx,
540 .freebsd,
541 .netbsd,
542542 => {
543543 if (self.os_data.have_fd) {
544544 self.loop.posixFsRequest(&self.os_data.close_req_node);
......@@ -546,7 +546,7 @@ pub const CloseOperation = struct {
546546 self.loop.allocator.destroy(self);
547547 }
548548 },
549 builtin.Os.windows => {
549 .windows => {
550550 if (self.os_data.handle) |handle| {
551551 os.close(handle);
552552 }
......@@ -558,15 +558,15 @@ pub const CloseOperation = struct {
558558
559559 pub fn setHandle(self: *CloseOperation, handle: fd_t) void {
560560 switch (builtin.os) {
561 builtin.Os.linux,
562 builtin.Os.macosx,
563 builtin.Os.freebsd,
564 builtin.Os.netbsd,
561 .linux,
562 .macosx,
563 .freebsd,
564 .netbsd,
565565 => {
566566 self.os_data.close_req_node.data.msg.Close.fd = handle;
567567 self.os_data.have_fd = true;
568568 },
569 builtin.Os.windows => {
569 .windows => {
570570 self.os_data.handle = handle;
571571 },
572572 else => @compileError("Unsupported OS"),
......@@ -576,14 +576,14 @@ pub const CloseOperation = struct {
576576 /// Undo a `setHandle`.
577577 pub fn clearHandle(self: *CloseOperation) void {
578578 switch (builtin.os) {
579 builtin.Os.linux,
580 builtin.Os.macosx,
581 builtin.Os.freebsd,
582 builtin.Os.netbsd,
579 .linux,
580 .macosx,
581 .freebsd,
582 .netbsd,
583583 => {
584584 self.os_data.have_fd = false;
585585 },
586 builtin.Os.windows => {
586 .windows => {
587587 self.os_data.handle = null;
588588 },
589589 else => @compileError("Unsupported OS"),
......@@ -592,15 +592,15 @@ pub const CloseOperation = struct {
592592
593593 pub fn getHandle(self: *CloseOperation) fd_t {
594594 switch (builtin.os) {
595 builtin.Os.linux,
596 builtin.Os.macosx,
597 builtin.Os.freebsd,
598 builtin.Os.netbsd,
595 .linux,
596 .macosx,
597 .freebsd,
598 .netbsd,
599599 => {
600600 assert(self.os_data.have_fd);
601601 return self.os_data.close_req_node.data.msg.Close.fd;
602602 },
603 builtin.Os.windows => {
603 .windows => {
604604 return self.os_data.handle.?;
605605 },
606606 else => @compileError("Unsupported OS"),
......@@ -617,12 +617,12 @@ pub async fn writeFile(loop: *Loop, path: []const u8, contents: []const u8) !voi
617617/// contents must remain alive until writeFile completes.
618618pub async fn writeFileMode(loop: *Loop, path: []const u8, contents: []const u8, mode: File.Mode) !void {
619619 switch (builtin.os) {
620 builtin.Os.linux,
621 builtin.Os.macosx,
622 builtin.Os.freebsd,
623 builtin.Os.netbsd,
620 .linux,
621 .macosx,
622 .freebsd,
623 .netbsd,
624624 => return await (async writeFileModeThread(loop, path, contents, mode) catch unreachable),
625 builtin.Os.windows => return await (async writeFileWindows(loop, path, contents) catch unreachable),
625 .windows => return await (async writeFileWindows(loop, path, contents) catch unreachable),
626626 else => @compileError("Unsupported OS"),
627627 }
628628}
......@@ -728,7 +728,7 @@ pub fn Watch(comptime V: type) type {
728728 os_data: OsData,
729729
730730 const OsData = switch (builtin.os) {
731 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => struct {
731 .macosx, .freebsd, .netbsd => struct {
732732 file_table: FileTable,
733733 table_lock: event.Lock,
734734
......@@ -739,8 +739,8 @@ pub fn Watch(comptime V: type) type {
739739 };
740740 },
741741
742 builtin.Os.linux => LinuxOsData,
743 builtin.Os.windows => WindowsOsData,
742 .linux => LinuxOsData,
743 .windows => WindowsOsData,
744744
745745 else => @compileError("Unsupported OS"),
746746 };
......@@ -793,7 +793,7 @@ pub fn Watch(comptime V: type) type {
793793 errdefer channel.destroy();
794794
795795 switch (builtin.os) {
796 builtin.Os.linux => {
796 .linux => {
797797 const inotify_fd = try os.inotify_init1(os.linux.IN_NONBLOCK | os.linux.IN_CLOEXEC);
798798 errdefer os.close(inotify_fd);
799799
......@@ -802,7 +802,7 @@ pub fn Watch(comptime V: type) type {
802802 return result;
803803 },
804804
805 builtin.Os.windows => {
805 .windows => {
806806 const self = try loop.allocator.create(Self);
807807 errdefer loop.allocator.destroy(self);
808808 self.* = Self{
......@@ -817,7 +817,7 @@ pub fn Watch(comptime V: type) type {
817817 return self;
818818 },
819819
820 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => {
820 .macosx, .freebsd, .netbsd => {
821821 const self = try loop.allocator.create(Self);
822822 errdefer loop.allocator.destroy(self);
823823
......@@ -837,7 +837,7 @@ pub fn Watch(comptime V: type) type {
837837 /// All addFile calls and removeFile calls must have completed.
838838 pub fn destroy(self: *Self) void {
839839 switch (builtin.os) {
840 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => {
840 .macosx, .freebsd, .netbsd => {
841841 // TODO we need to cancel the coroutines before destroying the lock
842842 self.os_data.table_lock.deinit();
843843 var it = self.os_data.file_table.iterator();
......@@ -847,8 +847,8 @@ pub fn Watch(comptime V: type) type {
847847 }
848848 self.channel.destroy();
849849 },
850 builtin.Os.linux => cancel self.os_data.putter,
851 builtin.Os.windows => {
850 .linux => cancel self.os_data.putter,
851 .windows => {
852852 while (self.os_data.all_putters.get()) |putter_node| {
853853 cancel putter_node.data;
854854 }
......@@ -879,9 +879,9 @@ pub fn Watch(comptime V: type) type {
879879
880880 pub async fn addFile(self: *Self, file_path: []const u8, value: V) !?V {
881881 switch (builtin.os) {
882 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => return await (async addFileKEvent(self, file_path, value) catch unreachable),
883 builtin.Os.linux => return await (async addFileLinux(self, file_path, value) catch unreachable),
884 builtin.Os.windows => return await (async addFileWindows(self, file_path, value) catch unreachable),
882 .macosx, .freebsd, .netbsd => return await (async addFileKEvent(self, file_path, value) catch unreachable),
883 .linux => return await (async addFileLinux(self, file_path, value) catch unreachable),
884 .windows => return await (async addFileWindows(self, file_path, value) catch unreachable),
885885 else => @compileError("Unsupported OS"),
886886 }
887887 }
std/event/loop.zig+78-85
......@@ -13,7 +13,7 @@ const Thread = std.Thread;
1313
1414pub const Loop = struct {
1515 allocator: *mem.Allocator,
16 next_tick_queue: std.atomic.Queue(promise),
16 next_tick_queue: std.atomic.Queue(anyframe),
1717 os_data: OsData,
1818 final_resume_node: ResumeNode,
1919 pending_event_count: usize,
......@@ -24,11 +24,11 @@ pub const Loop = struct {
2424 available_eventfd_resume_nodes: std.atomic.Stack(ResumeNode.EventFd),
2525 eventfd_resume_nodes: []std.atomic.Stack(ResumeNode.EventFd).Node,
2626
27 pub const NextTickNode = std.atomic.Queue(promise).Node;
27 pub const NextTickNode = std.atomic.Queue(anyframe).Node;
2828
2929 pub const ResumeNode = struct {
3030 id: Id,
31 handle: promise,
31 handle: anyframe,
3232 overlapped: Overlapped,
3333
3434 pub const overlapped_init = switch (builtin.os) {
......@@ -110,7 +110,7 @@ pub const Loop = struct {
110110 .pending_event_count = 1,
111111 .allocator = allocator,
112112 .os_data = undefined,
113 .next_tick_queue = std.atomic.Queue(promise).init(),
113 .next_tick_queue = std.atomic.Queue(anyframe).init(),
114114 .extra_threads = undefined,
115115 .available_eventfd_resume_nodes = std.atomic.Stack(ResumeNode.EventFd).init(),
116116 .eventfd_resume_nodes = undefined,
......@@ -148,18 +148,18 @@ pub const Loop = struct {
148148 fn initOsData(self: *Loop, extra_thread_count: usize) InitOsDataError!void {
149149 switch (builtin.os) {
150150 .linux => {
151 self.os_data.fs_queue = std.atomic.Queue(fs.Request).init();
152 self.os_data.fs_queue_item = 0;
153 // we need another thread for the file system because Linux does not have an async
154 // file system I/O API.
155 self.os_data.fs_end_request = fs.RequestNode{
156 .prev = undefined,
157 .next = undefined,
158 .data = fs.Request{
159 .msg = fs.Request.Msg.End,
160 .finish = fs.Request.Finish.NoAction,
161 },
162 };
151 // TODO self.os_data.fs_queue = std.atomic.Queue(fs.Request).init();
152 // TODO self.os_data.fs_queue_item = 0;
153 // TODO // we need another thread for the file system because Linux does not have an async
154 // TODO // file system I/O API.
155 // TODO self.os_data.fs_end_request = fs.RequestNode{
156 // TODO .prev = undefined,
157 // TODO .next = undefined,
158 // TODO .data = fs.Request{
159 // TODO .msg = fs.Request.Msg.End,
160 // TODO .finish = fs.Request.Finish.NoAction,
161 // TODO },
162 // TODO };
163163
164164 errdefer {
165165 while (self.available_eventfd_resume_nodes.pop()) |node| os.close(node.data.eventfd);
......@@ -197,10 +197,10 @@ pub const Loop = struct {
197197 &self.os_data.final_eventfd_event,
198198 );
199199
200 self.os_data.fs_thread = try Thread.spawn(self, posixFsRun);
200 // TODO self.os_data.fs_thread = try Thread.spawn(self, posixFsRun);
201201 errdefer {
202 self.posixFsRequest(&self.os_data.fs_end_request);
203 self.os_data.fs_thread.wait();
202 // TODO self.posixFsRequest(&self.os_data.fs_end_request);
203 // TODO self.os_data.fs_thread.wait();
204204 }
205205
206206 if (builtin.single_threaded) {
......@@ -302,10 +302,10 @@ pub const Loop = struct {
302302 .udata = undefined,
303303 };
304304
305 self.os_data.fs_thread = try Thread.spawn(self, posixFsRun);
305 // TODO self.os_data.fs_thread = try Thread.spawn(self, posixFsRun);
306306 errdefer {
307 self.posixFsRequest(&self.os_data.fs_end_request);
308 self.os_data.fs_thread.wait();
307 // TODO self.posixFsRequest(&self.os_data.fs_end_request);
308 // TODO self.os_data.fs_thread.wait();
309309 }
310310
311311 if (builtin.single_threaded) {
......@@ -397,7 +397,7 @@ pub const Loop = struct {
397397 }
398398 }
399399
400 /// resume_node must live longer than the promise that it holds a reference to.
400 /// resume_node must live longer than the anyframe that it holds a reference to.
401401 /// flags must contain EPOLLET
402402 pub fn linuxAddFd(self: *Loop, fd: i32, resume_node: *ResumeNode, flags: u32) !void {
403403 assert(flags & os.EPOLLET == os.EPOLLET);
......@@ -460,7 +460,7 @@ pub const Loop = struct {
460460 return resume_node.kev;
461461 }
462462
463 /// resume_node must live longer than the promise that it holds a reference to.
463 /// resume_node must live longer than the anyframe that it holds a reference to.
464464 pub fn bsdAddKev(self: *Loop, resume_node: *ResumeNode.Basic, ident: usize, filter: i16, fflags: u32) !void {
465465 self.beginOneEvent();
466466 errdefer self.finishOneEvent();
......@@ -561,11 +561,11 @@ pub const Loop = struct {
561561 self.workerRun();
562562
563563 switch (builtin.os) {
564 builtin.Os.linux,
565 builtin.Os.macosx,
566 builtin.Os.freebsd,
567 builtin.Os.netbsd,
568 => self.os_data.fs_thread.wait(),
564 .linux,
565 .macosx,
566 .freebsd,
567 .netbsd,
568 => {}, // TODO self.os_data.fs_thread.wait(),
569569 else => {},
570570 }
571571
......@@ -574,45 +574,39 @@ pub const Loop = struct {
574574 }
575575 }
576576
577 /// This is equivalent to an async call, except instead of beginning execution of the async function,
578 /// it immediately returns to the caller, and the async function is queued in the event loop. It still
579 /// returns a promise to be awaited.
580 pub fn call(self: *Loop, comptime func: var, args: ...) !(promise->@typeOf(func).ReturnType) {
581 const S = struct {
582 async fn asyncFunc(loop: *Loop, handle: *promise->@typeOf(func).ReturnType, args2: ...) @typeOf(func).ReturnType {
583 suspend {
584 handle.* = @handle();
585 var my_tick_node = Loop.NextTickNode{
586 .prev = undefined,
587 .next = undefined,
588 .data = @handle(),
589 };
590 loop.onNextTick(&my_tick_node);
591 }
592 // TODO guaranteed allocation elision for await in same func as async
593 return await (async func(args2) catch unreachable);
594 }
595 };
596 var handle: promise->@typeOf(func).ReturnType = undefined;
597 return async<self.allocator> S.asyncFunc(self, &handle, args);
577 /// This is equivalent to function call, except it calls `startCpuBoundOperation` first.
578 pub fn call(comptime func: var, args: ...) @typeOf(func).ReturnType {
579 startCpuBoundOperation();
580 return func(args);
598581 }
599582
600 /// Awaiting a yield lets the event loop run, starting any unstarted async operations.
583 /// Yielding lets the event loop run, starting any unstarted async operations.
601584 /// Note that async operations automatically start when a function yields for any other reason,
602585 /// for example, when async I/O is performed. This function is intended to be used only when
603586 /// CPU bound tasks would be waiting in the event loop but never get started because no async I/O
604587 /// is performed.
605 pub async fn yield(self: *Loop) void {
588 pub fn yield(self: *Loop) void {
606589 suspend {
607 var my_tick_node = Loop.NextTickNode{
590 var my_tick_node = NextTickNode{
608591 .prev = undefined,
609592 .next = undefined,
610 .data = @handle(),
593 .data = @frame(),
611594 };
612595 self.onNextTick(&my_tick_node);
613596 }
614597 }
615598
599 /// If the build is multi-threaded and there is an event loop, then it calls `yield`. Otherwise,
600 /// does nothing.
601 pub fn startCpuBoundOperation() void {
602 if (builtin.is_single_threaded) {
603 return;
604 } else if (instance) |event_loop| {
605 event_loop.yield();
606 }
607 }
608
609
616610 /// call finishOneEvent when done
617611 pub fn beginOneEvent(self: *Loop) void {
618612 _ = @atomicRmw(usize, &self.pending_event_count, AtomicRmwOp.Add, 1, AtomicOrder.SeqCst);
......@@ -624,7 +618,7 @@ pub const Loop = struct {
624618 // cause all the threads to stop
625619 switch (builtin.os) {
626620 .linux => {
627 self.posixFsRequest(&self.os_data.fs_end_request);
621 // TODO self.posixFsRequest(&self.os_data.fs_end_request);
628622 // writing 8 bytes to an eventfd cannot fail
629623 os.write(self.os_data.final_eventfd, wakeup_bytes) catch unreachable;
630624 return;
......@@ -672,9 +666,9 @@ pub const Loop = struct {
672666 const handle = resume_node.handle;
673667 const resume_node_id = resume_node.id;
674668 switch (resume_node_id) {
675 ResumeNode.Id.Basic => {},
676 ResumeNode.Id.Stop => return,
677 ResumeNode.Id.EventFd => {
669 .Basic => {},
670 .Stop => return,
671 .EventFd => {
678672 const event_fd_node = @fieldParentPtr(ResumeNode.EventFd, "base", resume_node);
679673 event_fd_node.epoll_op = os.EPOLL_CTL_MOD;
680674 const stack_node = @fieldParentPtr(std.atomic.Stack(ResumeNode.EventFd).Node, "data", event_fd_node);
......@@ -696,12 +690,12 @@ pub const Loop = struct {
696690 const handle = resume_node.handle;
697691 const resume_node_id = resume_node.id;
698692 switch (resume_node_id) {
699 ResumeNode.Id.Basic => {
693 .Basic => {
700694 const basic_node = @fieldParentPtr(ResumeNode.Basic, "base", resume_node);
701695 basic_node.kev = ev;
702696 },
703 ResumeNode.Id.Stop => return,
704 ResumeNode.Id.EventFd => {
697 .Stop => return,
698 .EventFd => {
705699 const event_fd_node = @fieldParentPtr(ResumeNode.EventFd, "base", resume_node);
706700 const stack_node = @fieldParentPtr(std.atomic.Stack(ResumeNode.EventFd).Node, "data", event_fd_node);
707701 self.available_eventfd_resume_nodes.push(stack_node);
......@@ -730,9 +724,9 @@ pub const Loop = struct {
730724 const handle = resume_node.handle;
731725 const resume_node_id = resume_node.id;
732726 switch (resume_node_id) {
733 ResumeNode.Id.Basic => {},
734 ResumeNode.Id.Stop => return,
735 ResumeNode.Id.EventFd => {
727 .Basic => {},
728 .Stop => return,
729 .EventFd => {
736730 const event_fd_node = @fieldParentPtr(ResumeNode.EventFd, "base", resume_node);
737731 const stack_node = @fieldParentPtr(std.atomic.Stack(ResumeNode.EventFd).Node, "data", event_fd_node);
738732 self.available_eventfd_resume_nodes.push(stack_node);
......@@ -750,12 +744,12 @@ pub const Loop = struct {
750744 self.beginOneEvent(); // finished in posixFsRun after processing the msg
751745 self.os_data.fs_queue.put(request_node);
752746 switch (builtin.os) {
753 builtin.Os.macosx, builtin.Os.freebsd, builtin.Os.netbsd => {
747 .macosx, .freebsd, .netbsd => {
754748 const fs_kevs = (*const [1]os.Kevent)(&self.os_data.fs_kevent_wake);
755749 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
756750 _ = os.kevent(self.os_data.fs_kqfd, fs_kevs, empty_kevs, null) catch unreachable;
757751 },
758 builtin.Os.linux => {
752 .linux => {
759753 _ = @atomicRmw(i32, &self.os_data.fs_queue_item, AtomicRmwOp.Xchg, 1, AtomicOrder.SeqCst);
760754 const rc = os.linux.futex_wake(&self.os_data.fs_queue_item, os.linux.FUTEX_WAKE, 1);
761755 switch (os.linux.getErrno(rc)) {
......@@ -781,18 +775,18 @@ pub const Loop = struct {
781775 }
782776 while (self.os_data.fs_queue.get()) |node| {
783777 switch (node.data.msg) {
784 @TagType(fs.Request.Msg).End => return,
785 @TagType(fs.Request.Msg).PWriteV => |*msg| {
778 .End => return,
779 .PWriteV => |*msg| {
786780 msg.result = os.pwritev(msg.fd, msg.iov, msg.offset);
787781 },
788 @TagType(fs.Request.Msg).PReadV => |*msg| {
782 .PReadV => |*msg| {
789783 msg.result = os.preadv(msg.fd, msg.iov, msg.offset);
790784 },
791 @TagType(fs.Request.Msg).Open => |*msg| {
785 .Open => |*msg| {
792786 msg.result = os.openC(msg.path.ptr, msg.flags, msg.mode);
793787 },
794 @TagType(fs.Request.Msg).Close => |*msg| os.close(msg.fd),
795 @TagType(fs.Request.Msg).WriteFile => |*msg| blk: {
788 .Close => |*msg| os.close(msg.fd),
789 .WriteFile => |*msg| blk: {
796790 const flags = os.O_LARGEFILE | os.O_WRONLY | os.O_CREAT |
797791 os.O_CLOEXEC | os.O_TRUNC;
798792 const fd = os.openC(msg.path.ptr, flags, msg.mode) catch |err| {
......@@ -804,11 +798,11 @@ pub const Loop = struct {
804798 },
805799 }
806800 switch (node.data.finish) {
807 @TagType(fs.Request.Finish).TickNode => |*tick_node| self.onNextTick(tick_node),
808 @TagType(fs.Request.Finish).DeallocCloseOperation => |close_op| {
801 .TickNode => |*tick_node| self.onNextTick(tick_node),
802 .DeallocCloseOperation => |close_op| {
809803 self.allocator.destroy(close_op);
810804 },
811 @TagType(fs.Request.Finish).NoAction => {},
805 .NoAction => {},
812806 }
813807 self.finishOneEvent();
814808 }
......@@ -855,16 +849,16 @@ pub const Loop = struct {
855849 epollfd: i32,
856850 final_eventfd: i32,
857851 final_eventfd_event: os.linux.epoll_event,
858 fs_thread: *Thread,
859 fs_queue_item: i32,
860 fs_queue: std.atomic.Queue(fs.Request),
861 fs_end_request: fs.RequestNode,
852 // TODO fs_thread: *Thread,
853 // TODO fs_queue_item: i32,
854 // TODO fs_queue: std.atomic.Queue(fs.Request),
855 // TODO fs_end_request: fs.RequestNode,
862856 };
863857};
864858
865859test "std.event.Loop - basic" {
866860 // https://github.com/ziglang/zig/issues/1908
867 if (builtin.single_threaded or builtin.os != builtin.Os.linux) return error.SkipZigTest;
861 if (builtin.single_threaded) return error.SkipZigTest;
868862
869863 const allocator = std.heap.direct_allocator;
870864
......@@ -877,7 +871,7 @@ test "std.event.Loop - basic" {
877871
878872test "std.event.Loop - call" {
879873 // https://github.com/ziglang/zig/issues/1908
880 if (builtin.single_threaded or builtin.os != builtin.Os.linux) return error.SkipZigTest;
874 if (builtin.single_threaded) return error.SkipZigTest;
881875
882876 const allocator = std.heap.direct_allocator;
883877
......@@ -886,9 +880,8 @@ test "std.event.Loop - call" {
886880 defer loop.deinit();
887881
888882 var did_it = false;
889 const handle = try loop.call(testEventLoop);
890 const handle2 = try loop.call(testEventLoop2, handle, &did_it);
891 defer cancel handle2;
883 const handle = async Loop.call(testEventLoop);
884 const handle2 = async Loop.call(testEventLoop2, handle, &did_it);
892885
893886 loop.run();
894887
......@@ -899,7 +892,7 @@ async fn testEventLoop() i32 {
899892 return 1234;
900893}
901894
902async fn testEventLoop2(h: promise->i32, did_it: *bool) void {
895async fn testEventLoop2(h: anyframe->i32, did_it: *bool) void {
903896 const value = await h;
904897 testing.expect(value == 1234);
905898 did_it.* = true;