diff options
| author | r00ster91 <r00ster91@proton.me> | 2023-01-07 12:57:22 +0100 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2023-01-16 14:20:57 +0200 |
| commit | 3dd8f43ad3bf656402b983c5d19601c92dd59d56 (patch) | |
| tree | 06a72bef189f74df82b093d0019ce505cf3ef940 /lib/std/Thread.zig | |
| parent | 4aa33da189264abf07f0b0e446036060c15a79e9 (diff) | |
| download | zig-3dd8f43ad3bf656402b983c5d19601c92dd59d56.tar.gz zig-3dd8f43ad3bf656402b983c5d19601c92dd59d56.zip | |
std.Thread: make Id smaller where possible
Diffstat (limited to 'lib/std/Thread.zig')
| -rw-r--r-- | lib/std/Thread.zig | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig index fc4f676a1f..d27474584f 100644 --- 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(); } |
