about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-08-02 19:06:53 +0000
committerbors <bors@rust-lang.org>2019-08-02 19:06:53 +0000
commitb0e40bfba44836ad30051ffb077c1cfc5bf4a59f (patch)
tree9cfea933bc8f7a60f707e3e2b7cf284460d9251e /src
parentcf048cc115860cc110865f460f3f2b9b4308ad92 (diff)
parent6be2d9ae864ae2a9b7f9d68ef8c073aad2b1efdc (diff)
downloadrust-b0e40bfba44836ad30051ffb077c1cfc5bf4a59f.tar.gz
rust-b0e40bfba44836ad30051ffb077c1cfc5bf4a59f.zip
Auto merge of #62309 - jlevon:62302, r=alexcrichton
provide thread name to OS for Solarish systems

Fixes #62302

Passes a Linux bootstrap build. python x.py test src/tools/tidy happy.
I tested this with a small test binary that spawns a few threads, and verified
that:

 - on an illumos system lacking the libc function, the binary runs but no OS-level
    thread names are set
 - on an illumos system with the feature, the binary runs, and the thread names are
    visible and correct under tools like MDB, pstack, core dump, etc.
Diffstat (limited to 'src')
-rw-r--r--src/libstd/sys/unix/thread.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs
index f4a1783ce89..122fc11ec27 100644
--- a/src/libstd/sys/unix/thread.rs
+++ b/src/libstd/sys/unix/thread.rs
@@ -122,8 +122,21 @@ impl Thread {
                                      name.as_ptr() as *mut libc::c_void);
         }
     }
+
+    #[cfg(target_os = "solaris")]
+    pub fn set_name(name: &CStr) {
+        weak! {
+            fn pthread_setname_np(
+                libc::pthread_t, *const libc::c_char
+            ) -> libc::c_int
+        }
+
+        if let Some(f) = pthread_setname_np.get() {
+            unsafe { f(libc::pthread_self(), name.as_ptr()); }
+        }
+    }
+
     #[cfg(any(target_env = "newlib",
-              target_os = "solaris",
               target_os = "haiku",
               target_os = "l4re",
               target_os = "emscripten",