From 0a1def7833882249563358f262e2210beb77492a Mon Sep 17 00:00:00 2001 From: kprotty Date: Sat, 19 Jun 2021 21:31:43 -0500 Subject: changes to accomodate std.Thread update --- src/ThreadPool.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ThreadPool.zig') diff --git a/src/ThreadPool.zig b/src/ThreadPool.zig index 4a7fa8cb9b..230608df4b 100644 --- a/src/ThreadPool.zig +++ b/src/ThreadPool.zig @@ -74,13 +74,13 @@ pub fn init(self: *ThreadPool, allocator: *std.mem.Allocator) !void { try worker.idle_node.data.init(); errdefer worker.idle_node.data.deinit(); - worker.thread = try std.Thread.spawn(Worker.run, worker); + worker.thread = try std.Thread.spawn(.{}, Worker.run, .{worker}); } } fn destroyWorkers(self: *ThreadPool, spawned: usize) void { for (self.workers[0..spawned]) |*worker| { - worker.thread.wait(); + worker.thread.join(); worker.idle_node.data.deinit(); } } -- cgit v1.2.3 From 3a276be1355fe304c177bcc13a7896122801e5f2 Mon Sep 17 00:00:00 2001 From: kprotty Date: Sat, 19 Jun 2021 21:50:34 -0500 Subject: std.Thread.getCpuCount(): fix usages --- lib/std/event/loop.zig | 4 ++-- lib/std/os/test.zig | 2 +- src/ThreadPool.zig | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/ThreadPool.zig') diff --git a/lib/std/event/loop.zig b/lib/std/event/loop.zig index 87d84acba6..26cbf3b988 100644 --- a/lib/std/event/loop.zig +++ b/lib/std/event/loop.zig @@ -137,7 +137,7 @@ pub const Loop = struct { } /// After initialization, call run(). - /// This is the same as `initThreadPool` using `Thread.cpuCount` to determine the thread + /// This is the same as `initThreadPool` using `Thread.getCpuCount` to determine the thread /// pool size. /// TODO copy elision / named return values so that the threads referencing *Loop /// have the correct pointer value. @@ -145,7 +145,7 @@ pub const Loop = struct { pub fn initMultiThreaded(self: *Loop) !void { if (builtin.single_threaded) @compileError("initMultiThreaded unavailable when building in single-threaded mode"); - const core_count = try Thread.cpuCount(); + const core_count = try Thread.getCpuCount(); return self.initThreadPool(core_count); } diff --git a/lib/std/os/test.zig b/lib/std/os/test.zig index 0bfe29d64b..472da73235 100644 --- a/lib/std/os/test.zig +++ b/lib/std/os/test.zig @@ -364,7 +364,7 @@ fn start2(ctx: *i32) u8 { test "cpu count" { if (native_os == .wasi) return error.SkipZigTest; - const cpu_count = try Thread.cpuCount(); + const cpu_count = try Thread.getCpuCount(); try expect(cpu_count >= 1); } diff --git a/src/ThreadPool.zig b/src/ThreadPool.zig index 230608df4b..18818c7d9d 100644 --- a/src/ThreadPool.zig +++ b/src/ThreadPool.zig @@ -60,7 +60,7 @@ pub fn init(self: *ThreadPool, allocator: *std.mem.Allocator) !void { if (std.builtin.single_threaded) return; - const worker_count = std.math.max(1, std.Thread.cpuCount() catch 1); + const worker_count = std.math.max(1, std.Thread.getCpuCount() catch 1); self.workers = try allocator.alloc(Worker, worker_count); errdefer allocator.free(self.workers); -- cgit v1.2.3 From 281a9a60f07afaf1b72bc66b2bb3c925b3c908f4 Mon Sep 17 00:00:00 2001 From: kprotty Date: Sun, 20 Jun 2021 13:45:16 -0500 Subject: std.Thread: fixup ThreadPool.zig --- src/ThreadPool.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ThreadPool.zig') diff --git a/src/ThreadPool.zig b/src/ThreadPool.zig index 18818c7d9d..7386e426eb 100644 --- a/src/ThreadPool.zig +++ b/src/ThreadPool.zig @@ -21,7 +21,7 @@ const Runnable = struct { const Worker = struct { pool: *ThreadPool, - thread: *std.Thread, + thread: std.Thread, /// The node is for this worker only and must have an already initialized event /// when the thread is spawned. idle_node: IdleQueue.Node, -- cgit v1.2.3