diff options
| author | bors <bors@rust-lang.org> | 2015-01-31 03:57:01 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-01-31 03:57:01 +0000 |
| commit | 474b324eda10440d6568ef872a7307d38e7de95b (patch) | |
| tree | 53fc5aaa615f1c6e5abd757e42a75b3d19ce3abb /src/libstd/sys | |
| parent | 1d00c545ede609b9d43fdf9f252c15da5a66dac7 (diff) | |
| parent | e8fd9d3d0bf0f4974460337df29c0d3ceb514987 (diff) | |
| download | rust-474b324eda10440d6568ef872a7307d38e7de95b.tar.gz rust-474b324eda10440d6568ef872a7307d38e7de95b.zip | |
Auto merge of #21791 - alexcrichton:rollup, r=alexcrichton
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/common/backtrace.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/common/thread_info.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/unix/os.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/unix/process.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/unix/stack_overflow.rs | 6 | ||||
| -rw-r--r-- | src/libstd/sys/unix/thread.rs | 43 | ||||
| -rw-r--r-- | src/libstd/sys/windows/backtrace.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/windows/stack_overflow.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/windows/thread.rs | 7 | ||||
| -rw-r--r-- | src/libstd/sys/windows/thread_local.rs | 2 |
10 files changed, 61 insertions, 11 deletions
diff --git a/src/libstd/sys/common/backtrace.rs b/src/libstd/sys/common/backtrace.rs index c3e12586829..a71676c6bf2 100644 --- a/src/libstd/sys/common/backtrace.rs +++ b/src/libstd/sys/common/backtrace.rs @@ -54,7 +54,7 @@ pub fn demangle(writer: &mut Writer, s: &str) -> IoResult<()> { let mut chars = inner.chars(); while valid { let mut i = 0; - for c in chars { + for c in chars.by_ref() { if c.is_numeric() { i = i * 10 + c as uint - '0' as uint; } else { diff --git a/src/libstd/sys/common/thread_info.rs b/src/libstd/sys/common/thread_info.rs index 92b936e74f6..7c9758ca924 100644 --- a/src/libstd/sys/common/thread_info.rs +++ b/src/libstd/sys/common/thread_info.rs @@ -56,6 +56,10 @@ pub fn stack_guard() -> uint { pub fn set(stack_bounds: (uint, uint), stack_guard: uint, thread: Thread) { THREAD_INFO.with(|c| assert!(c.borrow().is_none())); + match thread.name() { + Some(name) => unsafe { ::sys::thread::set_name(name.as_slice()); }, + None => {} + } THREAD_INFO.with(move |c| *c.borrow_mut() = Some(ThreadInfo{ stack_bounds: stack_bounds, stack_guard: stack_guard, diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 5d5cda03f01..dd343baa7c9 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -196,7 +196,7 @@ pub fn load_self() -> Option<Vec<u8>> { #[cfg(target_os = "dragonfly")] pub fn load_self() -> Option<Vec<u8>> { - use std::io; + use old_io; match old_io::fs::readlink(&Path::new("/proc/curproc/file")) { Ok(path) => Some(path.into_vec()), diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs index 3fcca2f35e1..b004a47f8a3 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -509,7 +509,7 @@ impl Process { // which will wake up the other end at some point, so we just allow this // signal to be coalesced with the pending signals on the pipe. extern fn sigchld_handler(_signum: libc::c_int) { - let msg = 1i; + let msg = 1; match unsafe { libc::write(WRITE_FD, &msg as *const _ as *const libc::c_void, 1) } { diff --git a/src/libstd/sys/unix/stack_overflow.rs b/src/libstd/sys/unix/stack_overflow.rs index 2b5ced5085b..a526f3393f2 100644 --- a/src/libstd/sys/unix/stack_overflow.rs +++ b/src/libstd/sys/unix/stack_overflow.rs @@ -162,7 +162,7 @@ mod imp { pub static SIGSTKSZ: libc::size_t = 8192; - pub const SIG_DFL: sighandler_t = 0i as sighandler_t; + pub const SIG_DFL: sighandler_t = 0 as sighandler_t; // This definition is not as accurate as it could be, {si_addr} is // actually a giant union. Currently we're only interested in that field, @@ -214,7 +214,7 @@ mod imp { pub const SIGSTKSZ: libc::size_t = 131072; - pub const SIG_DFL: sighandler_t = 0i as sighandler_t; + pub const SIG_DFL: sighandler_t = 0 as sighandler_t; pub type sigset_t = u32; @@ -271,7 +271,7 @@ mod imp { } pub unsafe fn make_handler() -> super::Handler { - super::Handler { _data: 0i as *mut libc::c_void } + super::Handler { _data: 0 as *mut libc::c_void } } pub unsafe fn drop_handler(_handler: &mut super::Handler) { diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index ac51b68795f..26a450b8599 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -17,6 +17,7 @@ use ptr; use libc::consts::os::posix01::{PTHREAD_CREATE_JOINABLE, PTHREAD_STACK_MIN}; use libc; use thunk::Thunk; +use ffi::CString; use sys_common::stack::RED_ZONE; use sys_common::thread::*; @@ -206,6 +207,37 @@ pub unsafe fn create(stack: uint, p: Thunk) -> rust_thread { native } +#[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 + let cname = CString::from_slice(name.as_bytes()); + type F = unsafe extern "C" fn(libc::pthread_t, *const libc::c_char) -> libc::c_int; + extern { + #[linkage = "extern_weak"] + static pthread_setname_np: *const (); + } + if !pthread_setname_np.is_null() { + unsafe { + mem::transmute::<*const (), F>(pthread_setname_np)(pthread_self(), cname.as_ptr()); + } + } +} + +#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] +pub unsafe fn set_name(name: &str) { + // pthread_set_name_np() since almost forever on all BSDs + let cname = CString::from_slice(name.as_bytes()); + pthread_set_name_np(pthread_self(), cname.as_ptr()); +} + +#[cfg(any(target_os = "macos", target_os = "ios"))] +pub unsafe fn set_name(name: &str) { + // pthread_setname_np() since OS X 10.6 and iOS 3.2 + let cname = CString::from_slice(name.as_bytes()); + pthread_setname_np(cname.as_ptr()); +} + pub unsafe fn join(native: rust_thread) { assert_eq!(pthread_join(native, ptr::null_mut()), 0); } @@ -246,7 +278,7 @@ fn min_stack_size(_: *const libc::pthread_attr_t) -> libc::size_t { PTHREAD_STACK_MIN } -#[cfg(any(target_os = "linux"))] +#[cfg(any(target_os = "linux", target_os = "android"))] extern { pub fn pthread_self() -> libc::pthread_t; pub fn pthread_getattr_np(native: libc::pthread_t, @@ -258,11 +290,18 @@ extern { stacksize: *mut libc::size_t) -> libc::c_int; } -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] +extern { + pub fn pthread_self() -> libc::pthread_t; + fn pthread_set_name_np(tid: libc::pthread_t, name: *const libc::c_char); +} + +#[cfg(any(target_os = "macos", target_os = "ios"))] extern { pub fn pthread_self() -> libc::pthread_t; pub fn pthread_get_stackaddr_np(thread: libc::pthread_t) -> *mut libc::c_void; pub fn pthread_get_stacksize_np(thread: libc::pthread_t) -> libc::size_t; + fn pthread_setname_np(name: *const libc::c_char) -> libc::c_int; } extern { diff --git a/src/libstd/sys/windows/backtrace.rs b/src/libstd/sys/windows/backtrace.rs index a186465f234..1be1a412ffa 100644 --- a/src/libstd/sys/windows/backtrace.rs +++ b/src/libstd/sys/windows/backtrace.rs @@ -333,7 +333,7 @@ pub fn write(w: &mut Writer) -> IoResult<()> { let _c = Cleanup { handle: process, SymCleanup: SymCleanup }; // And now that we're done with all the setup, do the stack walking! - let mut i = 0i; + let mut i = 0; try!(write!(w, "stack backtrace:\n")); while StackWalk64(image, process, thread, &mut frame, &mut context, ptr::null_mut(), diff --git a/src/libstd/sys/windows/stack_overflow.rs b/src/libstd/sys/windows/stack_overflow.rs index e8b447022cb..0cb4c573ae3 100644 --- a/src/libstd/sys/windows/stack_overflow.rs +++ b/src/libstd/sys/windows/stack_overflow.rs @@ -81,7 +81,7 @@ pub unsafe fn make_handler() -> Handler { panic!("failed to reserve stack space for exception handling"); } - Handler { _data: 0i as *mut libc::c_void } + Handler { _data: 0 as *mut libc::c_void } } pub struct EXCEPTION_RECORD { diff --git a/src/libstd/sys/windows/thread.rs b/src/libstd/sys/windows/thread.rs index 30707488b30..a94adcb3bc7 100644 --- a/src/libstd/sys/windows/thread.rs +++ b/src/libstd/sys/windows/thread.rs @@ -67,6 +67,13 @@ pub unsafe fn create(stack: uint, p: Thunk) -> rust_thread { return ret; } +pub unsafe fn set_name(_name: &str) { + // Windows threads are nameless + // The names in MSVC debugger are obtained using a "magic" exception, + // which requires a use of MS C++ extensions. + // See https://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx +} + pub unsafe fn join(native: rust_thread) { use libc::consts::os::extra::INFINITE; WaitForSingleObject(native, INFINITE); diff --git a/src/libstd/sys/windows/thread_local.rs b/src/libstd/sys/windows/thread_local.rs index 655195a3c28..0f8ceed39a6 100644 --- a/src/libstd/sys/windows/thread_local.rs +++ b/src/libstd/sys/windows/thread_local.rs @@ -235,7 +235,7 @@ unsafe extern "system" fn on_tls_callback(h: LPVOID, unsafe fn run_dtors() { let mut any_run = true; - for _ in 0..5i { + for _ in 0..5 { if !any_run { break } any_run = false; let dtors = { |
