diff options
| author | Yuki Okushi <huyuumi.dev+love@gmail.com> | 2022-10-27 08:30:59 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-27 08:30:59 +0900 |
| commit | b4b3ff4e6b34abd2a63f37c19754412d1685d3c2 (patch) | |
| tree | 796d34dc26ce6c8de088b8352628a2809d71a4a8 | |
| parent | 77145c042d8a94ab2159af0b624e1297812472fb (diff) | |
| parent | d1132fb805537bc43539e1fca7729dde1bc16048 (diff) | |
| download | rust-b4b3ff4e6b34abd2a63f37c19754412d1685d3c2.tar.gz rust-b4b3ff4e6b34abd2a63f37c19754412d1685d3c2.zip | |
Rollup merge of #103596 - RalfJung:thread-setname, r=cuviper
thread::set_name: debug-assert that things went well r? `@cuviper`
| -rw-r--r-- | library/std/src/sys/unix/thread.rs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/library/std/src/sys/unix/thread.rs b/library/std/src/sys/unix/thread.rs index 69cd2b500a1..c1d30dd9d52 100644 --- a/library/std/src/sys/unix/thread.rs +++ b/library/std/src/sys/unix/thread.rs @@ -137,7 +137,9 @@ impl Thread { unsafe { // Available since glibc 2.12, musl 1.1.16, and uClibc 1.0.20. let name = truncate_cstr(name, TASK_COMM_LEN); - libc::pthread_setname_np(libc::pthread_self(), name.as_ptr()); + let res = libc::pthread_setname_np(libc::pthread_self(), name.as_ptr()); + // We have no good way of propagating errors here, but in debug-builds let's check that this actually worked. + debug_assert_eq!(res, 0); } } @@ -152,7 +154,9 @@ impl Thread { pub fn set_name(name: &CStr) { unsafe { let name = truncate_cstr(name, libc::MAXTHREADNAMESIZE); - libc::pthread_setname_np(name.as_ptr()); + let res = libc::pthread_setname_np(name.as_ptr()); + // We have no good way of propagating errors here, but in debug-builds let's check that this actually worked. + debug_assert_eq!(res, 0); } } @@ -160,11 +164,12 @@ impl Thread { pub fn set_name(name: &CStr) { unsafe { let cname = CStr::from_bytes_with_nul_unchecked(b"%s\0".as_slice()); - libc::pthread_setname_np( + let res = libc::pthread_setname_np( libc::pthread_self(), cname.as_ptr(), name.as_ptr() as *mut libc::c_void, ); + debug_assert_eq!(res, 0); } } @@ -177,9 +182,8 @@ impl Thread { } if let Some(f) = pthread_setname_np.get() { - unsafe { - f(libc::pthread_self(), name.as_ptr()); - } + let res = unsafe { f(libc::pthread_self(), name.as_ptr()) }; + debug_assert_eq!(res, 0); } } |
