| ... | ... | @@ -62,18 +62,20 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void { |
| 62 | 62 | |
| 63 | 63 | switch (target.os.tag) { |
| 64 | 64 | .linux => if (use_pthreads) { |
| 65 | | const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr); |
| 66 | | switch (err) { |
| 67 | | .SUCCESS => return, |
| 68 | | .RANGE => unreachable, |
| 69 | | else => |e| return os.unexpectedErrno(e), |
| 70 | | } |
| 71 | | } else if (use_pthreads and self.getHandle() == std.c.pthread_self()) { |
| 72 | | // TODO: this is dead code. what did the author of this code intend to happen here? |
| 73 | | const err = try os.prctl(.SET_NAME, .{@ptrToInt(name_with_terminator.ptr)}); |
| 74 | | switch (@intToEnum(os.E, err)) { |
| 75 | | .SUCCESS => return, |
| 76 | | else => |e| return os.unexpectedErrno(e), |
| 65 | if (self.getHandle() == std.c.pthread_self()) { |
| 66 | // Set the name of the calling thread (no thread id required). |
| 67 | const err = try os.prctl(.SET_NAME, .{@ptrToInt(name_with_terminator.ptr)}); |
| 68 | switch (@intToEnum(os.E, err)) { |
| 69 | .SUCCESS => return, |
| 70 | else => |e| return os.unexpectedErrno(e), |
| 71 | } |
| 72 | } else { |
| 73 | const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr); |
| 74 | switch (err) { |
| 75 | .SUCCESS => return, |
| 76 | .RANGE => unreachable, |
| 77 | else => |e| return os.unexpectedErrno(e), |
| 78 | } |
| 77 | 79 | } |
| 78 | 80 | } else { |
| 79 | 81 | var buf: [32]u8 = undefined; |
| ... | ... | @@ -177,6 +179,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co |
| 177 | 179 | else => |e| return os.unexpectedErrno(e), |
| 178 | 180 | } |
| 179 | 181 | } else if (use_pthreads and self.getHandle() == std.c.pthread_self()) { |
| 182 | // Get the name of the calling thread (no thread id required). |
| 180 | 183 | const err = try os.prctl(.GET_NAME, .{@ptrToInt(buffer.ptr)}); |
| 181 | 184 | switch (@intToEnum(os.E, err)) { |
| 182 | 185 | .SUCCESS => return std.mem.sliceTo(buffer, 0), |
| ... | ... | @@ -325,10 +328,10 @@ pub const SpawnError = error{ |
| 325 | 328 | Unexpected, |
| 326 | 329 | }; |
| 327 | 330 | |
| 328 | | /// Spawns a new thread which executes `function` using `args` and returns a handle the spawned thread. |
| 331 | /// Spawns a new thread which executes `function` using `args` and returns a handle to the spawned thread. |
| 329 | 332 | /// `config` can be used as hints to the platform for now to spawn and execute the `function`. |
| 330 | 333 | /// The caller must eventually either call `join()` to wait for the thread to finish and free its resources |
| 331 | | /// or call `detach()` to excuse the caller from calling `join()` and have the thread clean up its resources on completion`. |
| 334 | /// or call `detach()` to excuse the caller from calling `join()` and have the thread clean up its resources on completion. |
| 332 | 335 | pub fn spawn(config: SpawnConfig, comptime function: anytype, args: anytype) SpawnError!Thread { |
| 333 | 336 | if (builtin.single_threaded) { |
| 334 | 337 | @compileError("Cannot spawn thread when building in single-threaded mode"); |