File tree Expand file tree Collapse file tree 1 file changed +11
-10
lines changed
library/std/src/sys/thread Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ use crate::ffi::CStr;
22use crate :: io;
33use crate :: num:: NonZeroUsize ;
44use crate :: sys:: map_motor_error;
5+ use crate :: thread:: ThreadInit ;
56use crate :: time:: Duration ;
67
78pub const DEFAULT_MIN_STACK_SIZE : usize = 1024 * 256 ;
@@ -14,21 +15,21 @@ unsafe impl Send for Thread {}
1415unsafe impl Sync for Thread { }
1516
1617impl 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 } )
You can’t perform that action at this time.
0 commit comments