mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
libuv: thread self, no deinit
This commit is contained in:
@ -9,6 +9,11 @@ const errors = @import("error.zig");
|
|||||||
|
|
||||||
thread: c.uv_thread_t,
|
thread: c.uv_thread_t,
|
||||||
|
|
||||||
|
/// Get the current thread
|
||||||
|
pub fn self() Thread {
|
||||||
|
return .{ .thread = c.uv_thread_self() };
|
||||||
|
}
|
||||||
|
|
||||||
/// Initialize a new thread.
|
/// Initialize a new thread.
|
||||||
pub fn init(
|
pub fn init(
|
||||||
comptime callback: fn () void,
|
comptime callback: fn () void,
|
||||||
@ -52,18 +57,13 @@ pub fn initData(
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *Thread) void {
|
pub fn join(t: *Thread) !void {
|
||||||
self.* = undefined;
|
try errors.convertError(c.uv_thread_join(&t.thread));
|
||||||
}
|
|
||||||
|
|
||||||
pub fn join(self: *Thread) !void {
|
|
||||||
try errors.convertError(c.uv_thread_join(&self.thread));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test "Thread: no data argument" {
|
test "Thread: no data argument" {
|
||||||
count = 0;
|
count = 0;
|
||||||
var thread = try init(incr);
|
var thread = try init(incr);
|
||||||
defer thread.deinit();
|
|
||||||
try thread.join();
|
try thread.join();
|
||||||
try testing.expectEqual(@as(u8, 1), count);
|
try testing.expectEqual(@as(u8, 1), count);
|
||||||
}
|
}
|
||||||
@ -72,7 +72,6 @@ test "Thread: with data argument" {
|
|||||||
count = 0;
|
count = 0;
|
||||||
var data: u8 = 2;
|
var data: u8 = 2;
|
||||||
var thread = try initData(&data, incrBy);
|
var thread = try initData(&data, incrBy);
|
||||||
defer thread.deinit();
|
|
||||||
try thread.join();
|
try thread.join();
|
||||||
try testing.expectEqual(@as(u8, 2), count);
|
try testing.expectEqual(@as(u8, 2), count);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user