| ... | @@ -2517,8 +2517,9 @@ pub const Thread = struct { | ... | @@ -2517,8 +2517,9 @@ pub const Thread = struct { |
| 2517 | | 2517 | |
| 2518 | pub const use_pthreads = is_posix and builtin.link_libc; | 2518 | pub const use_pthreads = is_posix and builtin.link_libc; |
| 2519 | | 2519 | |
| 2520 | /// An type representing a kernel thread ID. | 2520 | /// Represents a kernel thread handle. |
| 2521 | pub const Id = if (use_pthreads) | 2521 | /// May be an integer or a pointer depending on the platform. |
| | 2522 | pub const Handle = if (use_pthreads) |
| 2522 | c.pthread_t | 2523 | c.pthread_t |
| 2523 | else switch (builtin.os) { | 2524 | else switch (builtin.os) { |
| 2524 | builtin.Os.linux => i32, | 2525 | builtin.Os.linux => i32, |
| ... | @@ -2526,20 +2527,28 @@ pub const Thread = struct { | ... | @@ -2526,20 +2527,28 @@ pub const Thread = struct { |
| 2526 | else => @compileError("Unsupported OS"), | 2527 | else => @compileError("Unsupported OS"), |
| 2527 | }; | 2528 | }; |
| 2528 | | 2529 | |
| | 2530 | /// Represents a unique ID per thread. |
| | 2531 | /// May be an integer or pointer depending on the platform. |
| | 2532 | /// On Linux and POSIX, this is the same as Handle. |
| | 2533 | pub const Id = switch (builtin.os) { |
| | 2534 | builtin.Os.windows => windows.DWORD, |
| | 2535 | else => Handle, |
| | 2536 | }; |
| | 2537 | |
| 2529 | pub const Data = if (use_pthreads) | 2538 | pub const Data = if (use_pthreads) |
| 2530 | struct { | 2539 | struct { |
| 2531 | handle: Thread.Id, | 2540 | handle: Thread.Handle, |
| 2532 | stack_addr: usize, | 2541 | stack_addr: usize, |
| 2533 | stack_len: usize, | 2542 | stack_len: usize, |
| 2534 | } | 2543 | } |
| 2535 | else switch (builtin.os) { | 2544 | else switch (builtin.os) { |
| 2536 | builtin.Os.linux => struct { | 2545 | builtin.Os.linux => struct { |
| 2537 | handle: Thread.Id, | 2546 | handle: Thread.Handle, |
| 2538 | stack_addr: usize, | 2547 | stack_addr: usize, |
| 2539 | stack_len: usize, | 2548 | stack_len: usize, |
| 2540 | }, | 2549 | }, |
| 2541 | builtin.Os.windows => struct { | 2550 | builtin.Os.windows => struct { |
| 2542 | handle: Thread.Id, | 2551 | handle: Thread.Handle, |
| 2543 | alloc_start: *c_void, | 2552 | alloc_start: *c_void, |
| 2544 | heap_handle: windows.HANDLE, | 2553 | heap_handle: windows.HANDLE, |
| 2545 | }, | 2554 | }, |
| ... | @@ -2548,19 +2557,19 @@ pub const Thread = struct { | ... | @@ -2548,19 +2557,19 @@ pub const Thread = struct { |
| 2548 | | 2557 | |
| 2549 | /// Returns the ID of the calling thread. | 2558 | /// Returns the ID of the calling thread. |
| 2550 | /// Makes a syscall every time the function is called. | 2559 | /// Makes a syscall every time the function is called. |
| 2551 | pub fn getCurrentId() Thread.Id { | 2560 | pub fn getCurrentId() Id { |
| 2552 | if (use_pthreads) { | 2561 | if (use_pthreads) { |
| 2553 | return c.pthread_self(); | 2562 | return c.pthread_self(); |
| 2554 | } else | 2563 | } else |
| 2555 | return switch (builtin.os) { | 2564 | return switch (builtin.os) { |
| 2556 | builtin.Os.linux => linux.gettid(), | 2565 | builtin.Os.linux => linux.gettid(), |
| 2557 | builtin.Os.windows => windows.GetCurrentThread(), | 2566 | builtin.Os.windows => windows.GetCurrentThreadId(), |
| 2558 | else => @compileError("Unsupported OS"), | 2567 | else => @compileError("Unsupported OS"), |
| 2559 | }; | 2568 | }; |
| 2560 | } | 2569 | } |
| 2561 | | 2570 | |
| 2562 | /// Returns the ID of this thread. | 2571 | /// Returns the handle of this thread. |
| 2563 | pub fn id(self: Thread) Thread.Id { | 2572 | pub fn handle(self: Thread) Thread.Handle { |
| 2564 | return self.data.handle; | 2573 | return self.data.handle; |
| 2565 | } | 2574 | } |
| 2566 | | 2575 | |