authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-09 20:12:46-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-09 20:12:46-04:00
log26a842c264523c007687a72ab44f4c44990b5a89
tree15a4f75969f7017b1cf85f172de7bd193d5228b9
parentb219feb3f1983e9dcf0d32a7b2a3063dd6662f61

windows: only create io completion port once


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

std/event/fs.zig+13-9
......@@ -113,6 +113,8 @@ pub async fn pwriteWindows(loop: *Loop, fd: os.FileHandle, data: []const u8, off
113113 },
114114 };
115115 const completion_key = @ptrToInt(&resume_node.base);
116 // TODO support concurrent async ops on the file handle
117 // we can do this by ignoring completion key and using @fieldParentPtr with the *Overlapped
116118 _ = try os.windowsCreateIoCompletionPort(fd, loop.os_data.io_port, completion_key, undefined);
117119 var overlapped = windows.OVERLAPPED{
118120 .Internal = 0,
......@@ -247,6 +249,8 @@ pub async fn preadWindows(loop: *Loop, fd: os.FileHandle, data: []u8, offset: u6
247249 },
248250 };
249251 const completion_key = @ptrToInt(&resume_node.base);
252 // TODO support concurrent async ops on the file handle
253 // we can do this by ignoring completion key and using @fieldParentPtr with the *Overlapped
250254 _ = try os.windowsCreateIoCompletionPort(fd, loop.os_data.io_port, completion_key, undefined);
251255 var overlapped = windows.OVERLAPPED{
252256 .Internal = 0,
......@@ -831,8 +835,7 @@ pub fn Watch(comptime V: type) type {
831835 var it = self.os_data.dir_table.iterator();
832836 while (it.next()) |entry| {
833837 allocator.free(entry.key);
834 // TODO why does freeing this memory crash the test?
835 //allocator.destroy(entry.value);
838 allocator.destroy(entry.value);
836839 }
837840 self.os_data.dir_table.deinit();
838841 self.channel.destroy();
......@@ -1100,13 +1103,15 @@ pub fn Watch(comptime V: type) type {
11001103 };
11011104 var event_buf: [4096]u8 align(@alignOf(windows.FILE_NOTIFY_INFORMATION)) = undefined;
11021105
1106 // TODO handle this error not in the channel but in the setup
1107 _ = os.windowsCreateIoCompletionPort(
1108 dir_handle, self.channel.loop.os_data.io_port, completion_key, undefined,
1109 ) catch |err| {
1110 await (async self.channel.put(err) catch unreachable);
1111 return;
1112 };
1113
11031114 while (true) {
1104 _ = os.windowsCreateIoCompletionPort(
1105 dir_handle, self.channel.loop.os_data.io_port, completion_key, undefined,
1106 ) catch |err| {
1107 await (async self.channel.put(err) catch unreachable);
1108 return;
1109 };
11101115 {
11111116 // TODO only 1 beginOneEvent for the whole coroutine
11121117 self.channel.loop.beginOneEvent();
......@@ -1343,7 +1348,6 @@ async fn testFsWatch(loop: *Loop) !void {
13431348 WatchEventId.CloseWrite => {},
13441349 WatchEventId.Delete => @panic("wrong event"),
13451350 }
1346
13471351 const contents_updated = try await try async readFile(loop, file_path, 1024 * 1024);
13481352 assert(mem.eql(u8, contents_updated,
13491353 \\line 1
std/os/windows/util.zig+1
......@@ -220,6 +220,7 @@ pub fn windowsCreateIoCompletionPort(file_handle: windows.HANDLE, existing_compl
220220 const handle = windows.CreateIoCompletionPort(file_handle, existing_completion_port, completion_key, concurrent_thread_count) orelse {
221221 const err = windows.GetLastError();
222222 switch (err) {
223 windows.ERROR.INVALID_PARAMETER => unreachable,
223224 else => return os.unexpectedErrorWindows(err),
224225 }
225226 };