Skip to content

Commit 220e887

Browse files
authored
Rollup merge of #149579 - moturus:fix-thread-new, r=joboet
Motor OS: fix compile error [PR 148765](#148765) changed the expected signature of Thread::new(), which broke Motor OS target. Also set thread name while at it.
2 parents 432c466 + 537a8d7 commit 220e887

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

library/std/src/sys/thread/motor.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::ffi::CStr;
22
use crate::io;
33
use crate::num::NonZeroUsize;
44
use crate::sys::map_motor_error;
5+
use crate::thread::ThreadInit;
56
use crate::time::Duration;
67

78
pub const DEFAULT_MIN_STACK_SIZE: usize = 1024 * 256;
@@ -14,21 +15,21 @@ unsafe impl Send for Thread {}
1415
unsafe impl Sync for Thread {}
1516

1617
impl Thread {
17-
pub unsafe fn new(
18-
stack: usize,
19-
_name: Option<&str>,
20-
p: Box<dyn FnOnce()>,
21-
) -> io::Result<Thread> {
18+
pub unsafe fn new(stack: usize, init: Box<ThreadInit>) -> io::Result<Thread> {
2219
extern "C" fn __moto_rt_thread_fn(thread_arg: u64) {
2320
unsafe {
24-
Box::from_raw(
25-
core::ptr::with_exposed_provenance::<Box<dyn FnOnce()>>(thread_arg as usize)
26-
.cast_mut(),
27-
)();
21+
let init = Box::from_raw(core::ptr::with_exposed_provenance_mut::<ThreadInit>(
22+
thread_arg as usize,
23+
));
24+
let rust_start = init.init();
25+
if let Some(name) = crate::thread::current().name() {
26+
let _ = moto_rt::thread::set_name(name);
27+
}
28+
rust_start();
2829
}
2930
}
3031

31-
let thread_arg = Box::into_raw(Box::new(p)).expose_provenance() as u64;
32+
let thread_arg = Box::into_raw(init).expose_provenance() as u64;
3233
let sys_thread = moto_rt::thread::spawn(__moto_rt_thread_fn, stack, thread_arg)
3334
.map_err(map_motor_error)?;
3435
Ok(Self { sys_thread })

0 commit comments

Comments
 (0)