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...@@ -255,8 +255,19 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
255 return error.Unsupported;255 return error.Unsupported;
256}256}
257257
258/// Represents a unique ID per thread.258/// Represents an ID per thread guaranteed to be unique only within a process.
259pub const Id = u64;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
261/// Returns the platform ID of the callers thread.272/// Returns the platform ID of the callers thread.
262/// Attempts to use thread locals and avoid syscalls when possible.273/// Attempts to use thread locals and avoid syscalls when possible.
...@@ -431,7 +442,7 @@ fn callFn(comptime f: anytype, args: anytype) switch (Impl) {...@@ -431,7 +442,7 @@ fn callFn(comptime f: anytype, args: anytype) switch (Impl) {
431const UnsupportedImpl = struct {442const UnsupportedImpl = struct {
432 pub const ThreadHandle = void;443 pub const ThreadHandle = void;
433444
434 fn getCurrentId() u64 {445 fn getCurrentId() usize {
435 return unsupported({});446 return unsupported({});
436 }447 }
437448
...@@ -466,7 +477,7 @@ const WindowsThreadImpl = struct {...@@ -466,7 +477,7 @@ const WindowsThreadImpl = struct {
466477
467 pub const ThreadHandle = windows.HANDLE;478 pub const ThreadHandle = windows.HANDLE;
468479
469 fn getCurrentId() u64 {480 fn getCurrentId() windows.DWORD {
470 return windows.kernel32.GetCurrentThreadId();481 return windows.kernel32.GetCurrentThreadId();
471 }482 }
472483