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...@@ -113,6 +113,8 @@ pub async fn pwriteWindows(loop: *Loop, fd: os.FileHandle, data: []const u8, off
113 },113 },
114 };114 };
115 const completion_key = @ptrToInt(&resume_node.base);115 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
116 _ = try os.windowsCreateIoCompletionPort(fd, loop.os_data.io_port, completion_key, undefined);118 _ = try os.windowsCreateIoCompletionPort(fd, loop.os_data.io_port, completion_key, undefined);
117 var overlapped = windows.OVERLAPPED{119 var overlapped = windows.OVERLAPPED{
118 .Internal = 0,120 .Internal = 0,
...@@ -247,6 +249,8 @@ pub async fn preadWindows(loop: *Loop, fd: os.FileHandle, data: []u8, offset: u6...@@ -247,6 +249,8 @@ pub async fn preadWindows(loop: *Loop, fd: os.FileHandle, data: []u8, offset: u6
247 },249 },
248 };250 };
249 const completion_key = @ptrToInt(&resume_node.base);251 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
250 _ = try os.windowsCreateIoCompletionPort(fd, loop.os_data.io_port, completion_key, undefined);254 _ = try os.windowsCreateIoCompletionPort(fd, loop.os_data.io_port, completion_key, undefined);
251 var overlapped = windows.OVERLAPPED{255 var overlapped = windows.OVERLAPPED{
252 .Internal = 0,256 .Internal = 0,
...@@ -831,8 +835,7 @@ pub fn Watch(comptime V: type) type {...@@ -831,8 +835,7 @@ pub fn Watch(comptime V: type) type {
831 var it = self.os_data.dir_table.iterator();835 var it = self.os_data.dir_table.iterator();
832 while (it.next()) |entry| {836 while (it.next()) |entry| {
833 allocator.free(entry.key);837 allocator.free(entry.key);
834 // TODO why does freeing this memory crash the test?838 allocator.destroy(entry.value);
835 //allocator.destroy(entry.value);
836 }839 }
837 self.os_data.dir_table.deinit();840 self.os_data.dir_table.deinit();
838 self.channel.destroy();841 self.channel.destroy();
...@@ -1100,13 +1103,15 @@ pub fn Watch(comptime V: type) type {...@@ -1100,13 +1103,15 @@ pub fn Watch(comptime V: type) type {
1100 };1103 };
1101 var event_buf: [4096]u8 align(@alignOf(windows.FILE_NOTIFY_INFORMATION)) = undefined;1104 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
1103 while (true) {1114 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 };
1110 {1115 {
1111 // TODO only 1 beginOneEvent for the whole coroutine1116 // TODO only 1 beginOneEvent for the whole coroutine
1112 self.channel.loop.beginOneEvent();1117 self.channel.loop.beginOneEvent();
...@@ -1343,7 +1348,6 @@ async fn testFsWatch(loop: *Loop) !void {...@@ -1343,7 +1348,6 @@ async fn testFsWatch(loop: *Loop) !void {
1343 WatchEventId.CloseWrite => {},1348 WatchEventId.CloseWrite => {},
1344 WatchEventId.Delete => @panic("wrong event"),1349 WatchEventId.Delete => @panic("wrong event"),
1345 }1350 }
1346
1347 const contents_updated = try await try async readFile(loop, file_path, 1024 * 1024);1351 const contents_updated = try await try async readFile(loop, file_path, 1024 * 1024);
1348 assert(mem.eql(u8, contents_updated,1352 assert(mem.eql(u8, contents_updated,
1349 \\line 11353 \\line 1
std/os/windows/util.zig+1
...@@ -220,6 +220,7 @@ pub fn windowsCreateIoCompletionPort(file_handle: windows.HANDLE, existing_compl...@@ -220,6 +220,7 @@ pub fn windowsCreateIoCompletionPort(file_handle: windows.HANDLE, existing_compl
220 const handle = windows.CreateIoCompletionPort(file_handle, existing_completion_port, completion_key, concurrent_thread_count) orelse {220 const handle = windows.CreateIoCompletionPort(file_handle, existing_completion_port, completion_key, concurrent_thread_count) orelse {
221 const err = windows.GetLastError();221 const err = windows.GetLastError();
222 switch (err) {222 switch (err) {
223 windows.ERROR.INVALID_PARAMETER => unreachable,
223 else => return os.unexpectedErrorWindows(err),224 else => return os.unexpectedErrorWindows(err),
224 }225 }
225 };226 };