Skip to content

Commit b353e19

Browse files
xizheyingitbot
authored and
gitbot
committed
Consistently using as_mut_ptr() and as_ptr() in thread
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
1 parent 86cb43d commit b353e19

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

std/src/sys/pal/unix/thread.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,27 @@ impl Thread {
5050
let p = Box::into_raw(Box::new(p));
5151
let mut native: libc::pthread_t = mem::zeroed();
5252
let mut attr: mem::MaybeUninit<libc::pthread_attr_t> = mem::MaybeUninit::uninit();
53-
assert_eq!(libc::pthread_attr_init((&raw mut attr) as *mut _), 0);
54-
let mut attr: libc::pthread_attr_t = unsafe { attr.assume_init() };
53+
assert_eq!(libc::pthread_attr_init(attr.as_mut_ptr()), 0);
54+
//let mut attr: libc::pthread_attr_t = unsafe { attr.assume_init() };
5555

5656
#[cfg(target_os = "espidf")]
5757
if stack > 0 {
5858
// Only set the stack if a non-zero value is passed
5959
// 0 is used as an indication that the default stack size configured in the ESP-IDF menuconfig system should be used
6060
assert_eq!(
61-
libc::pthread_attr_setstacksize(&mut attr, cmp::max(stack, min_stack_size(&attr))),
61+
libc::pthread_attr_setstacksize(
62+
attr.as_mut_ptr(),
63+
cmp::max(stack, min_stack_size(&attr))
64+
),
6265
0
6366
);
6467
}
6568

6669
#[cfg(not(target_os = "espidf"))]
6770
{
68-
let stack_size = cmp::max(stack, min_stack_size(&attr));
71+
let stack_size = cmp::max(stack, min_stack_size(attr.as_ptr()));
6972

70-
match libc::pthread_attr_setstacksize(&mut attr, stack_size) {
73+
match libc::pthread_attr_setstacksize(attr.as_mut_ptr(), stack_size) {
7174
0 => {}
7275
n => {
7376
assert_eq!(n, libc::EINVAL);
@@ -78,16 +81,16 @@ impl Thread {
7881
let page_size = os::page_size();
7982
let stack_size =
8083
(stack_size + page_size - 1) & (-(page_size as isize - 1) as usize - 1);
81-
assert_eq!(libc::pthread_attr_setstacksize(&mut attr, stack_size), 0);
84+
assert_eq!(libc::pthread_attr_setstacksize(attr.as_mut_ptr(), stack_size), 0);
8285
}
8386
};
8487
}
8588

86-
let ret = libc::pthread_create(&mut native, &attr, thread_start, p as *mut _);
89+
let ret = libc::pthread_create(&mut native, attr.as_ptr(), thread_start, p as *mut _);
8790
// Note: if the thread creation fails and this assert fails, then p will
8891
// be leaked. However, an alternative design could cause double-free
8992
// which is clearly worse.
90-
assert_eq!(libc::pthread_attr_destroy(&mut attr), 0);
93+
assert_eq!(libc::pthread_attr_destroy(attr.as_mut_ptr()), 0);
9194

9295
return if ret != 0 {
9396
// The thread failed to start and as a result p was not consumed. Therefore, it is

0 commit comments

Comments
 (0)