From 4b0cddc948f4b0d218f92bcf06f8da5fee0985c2 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 21 Apr 2022 16:28:06 -0700 Subject: [PATCH] libuv: thread self, no deinit --- src/libuv/Thread.zig | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/libuv/Thread.zig b/src/libuv/Thread.zig index 38e17f768..7ff620ac4 100644 --- a/src/libuv/Thread.zig +++ b/src/libuv/Thread.zig @@ -9,6 +9,11 @@ const errors = @import("error.zig"); thread: c.uv_thread_t, +/// Get the current thread +pub fn self() Thread { + return .{ .thread = c.uv_thread_self() }; +} + /// Initialize a new thread. pub fn init( comptime callback: fn () void, @@ -52,18 +57,13 @@ pub fn initData( return res; } -pub fn deinit(self: *Thread) void { - self.* = undefined; -} - -pub fn join(self: *Thread) !void { - try errors.convertError(c.uv_thread_join(&self.thread)); +pub fn join(t: *Thread) !void { + try errors.convertError(c.uv_thread_join(&t.thread)); } test "Thread: no data argument" { count = 0; var thread = try init(incr); - defer thread.deinit(); try thread.join(); try testing.expectEqual(@as(u8, 1), count); } @@ -72,7 +72,6 @@ test "Thread: with data argument" { count = 0; var data: u8 = 2; var thread = try initData(&data, incrBy); - defer thread.deinit(); try thread.join(); try testing.expectEqual(@as(u8, 2), count); }