Consistently using as_mut_ptr() and as_ptr() in thread
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
This commit is contained in:
parent
7e7f5d3856
commit
c1ecdf1124
1 changed files with 11 additions and 8 deletions
|
@ -50,24 +50,27 @@ impl Thread {
|
|||
let p = Box::into_raw(Box::new(p));
|
||||
let mut native: libc::pthread_t = mem::zeroed();
|
||||
let mut attr: mem::MaybeUninit<libc::pthread_attr_t> = mem::MaybeUninit::uninit();
|
||||
assert_eq!(libc::pthread_attr_init((&raw mut attr) as *mut _), 0);
|
||||
let mut attr: libc::pthread_attr_t = unsafe { attr.assume_init() };
|
||||
assert_eq!(libc::pthread_attr_init(attr.as_mut_ptr()), 0);
|
||||
//let mut attr: libc::pthread_attr_t = unsafe { attr.assume_init() };
|
||||
|
||||
#[cfg(target_os = "espidf")]
|
||||
if stack > 0 {
|
||||
// Only set the stack if a non-zero value is passed
|
||||
// 0 is used as an indication that the default stack size configured in the ESP-IDF menuconfig system should be used
|
||||
assert_eq!(
|
||||
libc::pthread_attr_setstacksize(&mut attr, cmp::max(stack, min_stack_size(&attr))),
|
||||
libc::pthread_attr_setstacksize(
|
||||
attr.as_mut_ptr(),
|
||||
cmp::max(stack, min_stack_size(&attr))
|
||||
),
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "espidf"))]
|
||||
{
|
||||
let stack_size = cmp::max(stack, min_stack_size(&attr));
|
||||
let stack_size = cmp::max(stack, min_stack_size(attr.as_ptr()));
|
||||
|
||||
match libc::pthread_attr_setstacksize(&mut attr, stack_size) {
|
||||
match libc::pthread_attr_setstacksize(attr.as_mut_ptr(), stack_size) {
|
||||
0 => {}
|
||||
n => {
|
||||
assert_eq!(n, libc::EINVAL);
|
||||
|
@ -78,16 +81,16 @@ impl Thread {
|
|||
let page_size = os::page_size();
|
||||
let stack_size =
|
||||
(stack_size + page_size - 1) & (-(page_size as isize - 1) as usize - 1);
|
||||
assert_eq!(libc::pthread_attr_setstacksize(&mut attr, stack_size), 0);
|
||||
assert_eq!(libc::pthread_attr_setstacksize(attr.as_mut_ptr(), stack_size), 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let ret = libc::pthread_create(&mut native, &attr, thread_start, p as *mut _);
|
||||
let ret = libc::pthread_create(&mut native, attr.as_ptr(), thread_start, p as *mut _);
|
||||
// Note: if the thread creation fails and this assert fails, then p will
|
||||
// be leaked. However, an alternative design could cause double-free
|
||||
// which is clearly worse.
|
||||
assert_eq!(libc::pthread_attr_destroy(&mut attr), 0);
|
||||
assert_eq!(libc::pthread_attr_destroy(attr.as_mut_ptr()), 0);
|
||||
|
||||
return if ret != 0 {
|
||||
// The thread failed to start and as a result p was not consumed. Therefore, it is
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue