authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-06 17:30:55-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-06 17:31:52-04:00
log24d74cbf44b34b180b2df5557927d9d2e4c9e443
treed63d84c3eba4cd1d9c28a41ac7979eeff4784843
parentd2dd29e80c89d8cc530a185e32e9025d0e453bb5

fix Thread impl on Linux and add docs


2 files changed, 5 insertions(+), 2 deletions(-)

std/os/index.zig+4-1
...@@ -2519,6 +2519,7 @@ pub const Thread = struct {...@@ -2519,6 +2519,7 @@ pub const Thread = struct {
25192519
2520 /// Represents a kernel thread handle.2520 /// Represents a kernel thread handle.
2521 /// May be an integer or a pointer depending on the platform.2521 /// May be an integer or a pointer depending on the platform.
2522 /// On Linux and POSIX, this is the same as Id.
2522 pub const Handle = if (use_pthreads)2523 pub const Handle = if (use_pthreads)
2523 c.pthread_t2524 c.pthread_t
2524 else switch (builtin.os) {2525 else switch (builtin.os) {
...@@ -2557,6 +2558,7 @@ pub const Thread = struct {...@@ -2557,6 +2558,7 @@ pub const Thread = struct {
25572558
2558 /// Returns the ID of the calling thread.2559 /// Returns the ID of the calling thread.
2559 /// Makes a syscall every time the function is called.2560 /// Makes a syscall every time the function is called.
2561 /// On Linux and POSIX, this Id is the same as a Handle.
2560 pub fn getCurrentId() Id {2562 pub fn getCurrentId() Id {
2561 if (use_pthreads) {2563 if (use_pthreads) {
2562 return c.pthread_self();2564 return c.pthread_self();
...@@ -2569,7 +2571,8 @@ pub const Thread = struct {...@@ -2569,7 +2571,8 @@ pub const Thread = struct {
2569 }2571 }
25702572
2571 /// Returns the handle of this thread.2573 /// Returns the handle of this thread.
2572 pub fn handle(self: Thread) Thread.Handle {2574 /// On Linux and POSIX, this is the same as Id.
2575 pub fn handle(self: Thread) Handle {
2573 return self.data.handle;2576 return self.data.handle;
2574 }2577 }
25752578
std/os/test.zig+1-1
...@@ -41,11 +41,11 @@ fn testThreadIdFn(thread_id: *os.Thread.Id) void {...@@ -41,11 +41,11 @@ fn testThreadIdFn(thread_id: *os.Thread.Id) void {
41test "std.os.Thread.getCurrentId" {41test "std.os.Thread.getCurrentId" {
42 var thread_current_id: os.Thread.Id = undefined;42 var thread_current_id: os.Thread.Id = undefined;
43 const thread = try os.spawnThread(&thread_current_id, testThreadIdFn);43 const thread = try os.spawnThread(&thread_current_id, testThreadIdFn);
44 const thread_id = thread.handle();
44 thread.wait();45 thread.wait();
45 switch (builtin.os) {46 switch (builtin.os) {
46 builtin.Os.windows => assert(os.Thread.getCurrentId() != thread_current_id),47 builtin.Os.windows => assert(os.Thread.getCurrentId() != thread_current_id),
47 else => {48 else => {
48 const thread_id = thread.handle();
49 assert(thread_current_id == thread_id);49 assert(thread_current_id == thread_id);
50 },50 },
51 }51 }