std.Thread: make Id smaller where possible

This commit is contained in:
r00ster91
2023-01-07 12:57:22 +01:00
committed by Veikka Tuominen
parent 4aa33da189
commit 3dd8f43ad3

View File

@@ -255,8 +255,19 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
return error.Unsupported;
}
/// Represents a unique ID per thread.
pub const Id = u64;
/// Represents an ID per thread guaranteed to be unique only within a process.
pub const Id = switch (target.os.tag) {
.linux,
.dragonfly,
.netbsd,
.freebsd,
.openbsd,
.haiku,
=> u32,
.macos, .ios, .watchos, .tvos => u64,
.windows => os.windows.DWORD,
else => usize,
};
/// Returns the platform ID of the callers thread.
/// Attempts to use thread locals and avoid syscalls when possible.
@@ -431,7 +442,7 @@ fn callFn(comptime f: anytype, args: anytype) switch (Impl) {
const UnsupportedImpl = struct {
pub const ThreadHandle = void;
fn getCurrentId() u64 {
fn getCurrentId() usize {
return unsupported({});
}
@@ -466,7 +477,7 @@ const WindowsThreadImpl = struct {
pub const ThreadHandle = windows.HANDLE;
fn getCurrentId() u64 {
fn getCurrentId() windows.DWORD {
return windows.kernel32.GetCurrentThreadId();
}