authorgravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2023-01-07 12:57:22+01:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-01-16 14:20:57+02:00
log3dd8f43ad3bf656402b983c5d19601c92dd59d56
tree06a72bef189f74df82b093d0019ce505cf3ef940
parent4aa33da189264abf07f0b0e446036060c15a79e9

std.Thread: make Id smaller where possible


1 files changed, 15 insertions(+), 4 deletions(-)

lib/std/Thread.zig+15-4
......@@ -255,8 +255,19 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
255255 return error.Unsupported;
256256}
257257
258/// Represents a unique ID per thread.
259pub const Id = u64;
258/// Represents an ID per thread guaranteed to be unique only within a process.
259pub const Id = switch (target.os.tag) {
260 .linux,
261 .dragonfly,
262 .netbsd,
263 .freebsd,
264 .openbsd,
265 .haiku,
266 => u32,
267 .macos, .ios, .watchos, .tvos => u64,
268 .windows => os.windows.DWORD,
269 else => usize,
270};
260271
261272/// Returns the platform ID of the callers thread.
262273/// Attempts to use thread locals and avoid syscalls when possible.
......@@ -431,7 +442,7 @@ fn callFn(comptime f: anytype, args: anytype) switch (Impl) {
431442const UnsupportedImpl = struct {
432443 pub const ThreadHandle = void;
433444
434 fn getCurrentId() u64 {
445 fn getCurrentId() usize {
435446 return unsupported({});
436447 }
437448
......@@ -466,7 +477,7 @@ const WindowsThreadImpl = struct {
466477
467478 pub const ThreadHandle = windows.HANDLE;
468479
469 fn getCurrentId() u64 {
480 fn getCurrentId() windows.DWORD {
470481 return windows.kernel32.GetCurrentThreadId();
471482 }
472483