Skip to content

Commit 01f59f6

Browse files
committed
---
yaml --- r: 177592 b: refs/heads/auto c: 33a3d6d h: refs/heads/master v: v3
1 parent f0ba6b7 commit 01f59f6

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: c155208de42de5761231726e35614b4499b5a137
13+
refs/heads/auto: 33a3d6d88f76bfae770983ee50e36e23cc4c7655
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/libstd/sys/common/thread_info.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ pub fn stack_guard() -> uint {
5656

5757
pub fn set(stack_bounds: (uint, uint), stack_guard: uint, thread: Thread) {
5858
THREAD_INFO.with(|c| assert!(c.borrow().is_none()));
59+
match thread.name() {
60+
Some(name) => unsafe { ::sys::thread::set_name(name.as_slice()); },
61+
None => {}
62+
}
5963
THREAD_INFO.with(move |c| *c.borrow_mut() = Some(ThreadInfo{
6064
stack_bounds: stack_bounds,
6165
stack_guard: stack_guard,

branches/auto/src/libstd/sys/unix/thread.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,19 @@ pub unsafe fn create(stack: uint, p: Thunk) -> rust_thread {
209209

210210
#[cfg(any(target_os = "linux", target_os = "android"))]
211211
pub unsafe fn set_name(name: &str) {
212-
// Using prctl() rather than pthread_setname_np(),
213-
// because pthread_setname_np() wasn't added until glibc 2.12
214-
// PR_SET_NAME since Linux 2.6.9
212+
// pthread_setname_np() since glibc 2.12
213+
// availability autodetected via weak linkage
215214
let cname = CString::from_slice(name.as_bytes());
216-
prctl(15i32 /* = PR_SET_NAME */, cname.as_ptr() as u64, 0u64, 0u64, 0u64);
215+
type F = unsafe extern "C" fn(libc::pthread_t, *const libc::c_char) -> libc::c_int;
216+
extern {
217+
#[linkage = "extern_weak"]
218+
static pthread_setname_np: *const ();
219+
}
220+
if !pthread_setname_np.is_null() {
221+
unsafe {
222+
mem::transmute::<*const (), F>(pthread_setname_np)(pthread_self(), cname.as_ptr());
223+
}
224+
}
217225
}
218226

219227
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
@@ -270,15 +278,6 @@ fn min_stack_size(_: *const libc::pthread_attr_t) -> libc::size_t {
270278
PTHREAD_STACK_MIN
271279
}
272280

273-
#[cfg(any(target_os = "linux", target_os = "android"))]
274-
extern {
275-
fn prctl(option: libc::c_int,
276-
arg2: libc::c_ulong,
277-
arg3: libc::c_ulong,
278-
arg4: libc::c_ulong,
279-
arg5: libc::c_ulong) -> libc::c_int;
280-
}
281-
282281
#[cfg(any(target_os = "linux"))]
283282
extern {
284283
pub fn pthread_self() -> libc::pthread_t;
@@ -294,15 +293,15 @@ extern {
294293
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
295294
extern {
296295
pub fn pthread_self() -> libc::pthread_t;
297-
fn pthread_set_name_np(tid: libc::pthread_t, name: *const c_char);
296+
fn pthread_set_name_np(tid: libc::pthread_t, name: *const libc::c_char);
298297
}
299298

300299
#[cfg(target_os = "macos")]
301300
extern {
302301
pub fn pthread_self() -> libc::pthread_t;
303302
pub fn pthread_get_stackaddr_np(thread: libc::pthread_t) -> *mut libc::c_void;
304303
pub fn pthread_get_stacksize_np(thread: libc::pthread_t) -> libc::size_t;
305-
fn pthread_setname_np(name: *const c_char) -> libc::c_int;
304+
fn pthread_setname_np(name: *const libc::c_char) -> libc::c_int;
306305
}
307306

308307
extern {

branches/auto/src/libstd/thread.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,6 @@ impl Builder {
275275
unsafe {
276276
stack::record_os_managed_stack_bounds(my_stack_bottom, my_stack_top);
277277
}
278-
match their_thread.name() {
279-
Some(thename) => unsafe { imp::set_name(thename.as_slice()); },
280-
None => {}
281-
}
282278
thread_info::set(
283279
(my_stack_bottom, my_stack_top),
284280
unsafe { imp::guard::current() },

0 commit comments

Comments
 (0)