@@ -209,11 +209,19 @@ pub unsafe fn create(stack: uint, p: Thunk) -> rust_thread {
209
209
210
210
#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
211
211
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
215
214
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
+ }
217
225
}
218
226
219
227
#[ cfg( any( target_os = "freebsd" , target_os = "dragonfly" ) ) ]
@@ -270,15 +278,6 @@ fn min_stack_size(_: *const libc::pthread_attr_t) -> libc::size_t {
270
278
PTHREAD_STACK_MIN
271
279
}
272
280
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
-
282
281
#[ cfg( any( target_os = "linux" ) ) ]
283
282
extern {
284
283
pub fn pthread_self ( ) -> libc:: pthread_t ;
@@ -294,15 +293,15 @@ extern {
294
293
#[ cfg( any( target_os = "freebsd" , target_os = "dragonfly" ) ) ]
295
294
extern {
296
295
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 ) ;
298
297
}
299
298
300
299
#[ cfg( target_os = "macos" ) ]
301
300
extern {
302
301
pub fn pthread_self ( ) -> libc:: pthread_t ;
303
302
pub fn pthread_get_stackaddr_np ( thread : libc:: pthread_t ) -> * mut libc:: c_void ;
304
303
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 ;
306
305
}
307
306
308
307
extern {
0 commit comments