about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-03-23 15:11:12 -0700
committerAlex Crichton <alex@alexcrichton.com>2015-03-23 15:11:12 -0700
commit8a15868206b3bf47cbe8f19d93551adcfda9bb6d (patch)
tree8e9c588de8167db52ff7eb436710f85e4b1b2261 /src/libstd
parent5e06ebbfc0d7c3655656dba1f3255e34fa711b68 (diff)
parentd29d5545b6a5485bb1a51e035889e20330b2e4f7 (diff)
downloadrust-8a15868206b3bf47cbe8f19d93551adcfda9bb6d.tar.gz
rust-8a15868206b3bf47cbe8f19d93551adcfda9bb6d.zip
rollup merge of #23640: nagisa/thread-less-weak
This is more portable as far as linux is concerned.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/sys/unix/thread.rs19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs
index c66d86b7625..eb2a6dc08bf 100644
--- a/src/libstd/sys/unix/thread.rs
+++ b/src/libstd/sys/unix/thread.rs
@@ -229,19 +229,16 @@ pub unsafe fn create(stack: usize, p: Thunk) -> io::Result<rust_thread> {
 
 #[cfg(any(target_os = "linux", target_os = "android"))]
 pub unsafe fn set_name(name: &str) {
-    // pthread_setname_np() since glibc 2.12
-    // availability autodetected via weak linkage
-    type F = unsafe extern fn(libc::pthread_t, *const libc::c_char)
-                              -> libc::c_int;
+    // pthread wrapper only appeared in glibc 2.12, so we use syscall directly.
     extern {
-        #[linkage = "extern_weak"]
-        static pthread_setname_np: *const ();
-    }
-    if !pthread_setname_np.is_null() {
-        let cname = CString::new(name).unwrap();
-        mem::transmute::<*const (), F>(pthread_setname_np)(pthread_self(),
-                                                           cname.as_ptr());
+        fn prctl(option: libc::c_int, arg2: libc::c_ulong, arg3: libc::c_ulong,
+                 arg4: libc::c_ulong, arg5: libc::c_ulong) -> libc::c_int;
     }
+    const PR_SET_NAME: libc::c_int = 15;
+    let cname = CString::new(name).unwrap_or_else(|_| {
+        panic!("thread name may not contain interior null bytes")
+    });
+    prctl(PR_SET_NAME, cname.as_ptr() as libc::c_ulong, 0, 0, 0);
 }
 
 #[cfg(any(target_os = "freebsd",