zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 3dd8f43ad3bf656402b983c5d19601c92dd59d56 (tree)
parent 4aa33da189264abf07f0b0e446036060c15a79e9
Author: r00ster91 <r00ster91@proton.me>
Date:   Sat,  7 Jan 2023 12:57:22 +0100

std.Thread: make Id smaller where possible

Diffstat:
Mlib/std/Thread.zig | 19+++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig @@ -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(); }