22
33use crate::io;
44use crate::sys::pal::abi::{thread, usercalls};
5+ use crate::thread::ThreadInit;
56use crate::time::Duration;
67
78pub struct Thread(task_queue::JoinHandle);
@@ -13,6 +14,7 @@ pub use self::task_queue::JoinNotifier;
1314mod task_queue {
1415 use super::wait_notify;
1516 use crate::sync::{Mutex, MutexGuard};
17+ use crate::thread::ThreadInit;
1618
1719 pub type JoinHandle = wait_notify::Waiter;
1820
@@ -25,19 +27,20 @@ mod task_queue {
2527 }
2628
2729 pub(super) struct Task {
28- p : Box<dyn FnOnce() + Send >,
30+ init : Box<ThreadInit >,
2931 done: JoinNotifier,
3032 }
3133
3234 impl Task {
33- pub(super) fn new(p : Box<dyn FnOnce() + Send >) -> (Task, JoinHandle) {
35+ pub(super) fn new(init : Box<ThreadInit >) -> (Task, JoinHandle) {
3436 let (done, recv) = wait_notify::new();
3537 let done = JoinNotifier(Some(done));
36- (Task { p , done }, recv)
38+ (Task { init , done }, recv)
3739 }
3840
3941 pub(super) fn run(self) -> JoinNotifier {
40- (self.p)();
42+ let rust_start = self.init.init();
43+ rust_start();
4144 self.done
4245 }
4346 }
@@ -93,14 +96,10 @@ pub mod wait_notify {
9396
9497impl Thread {
9598 // unsafe: see thread::Builder::spawn_unchecked for safety requirements
96- pub unsafe fn new(
97- _stack: usize,
98- _name: Option<&str>,
99- p: Box<dyn FnOnce() + Send>,
100- ) -> io::Result<Thread> {
99+ pub unsafe fn new(_stack: usize, init: Box<ThreadInit>) -> io::Result<Thread> {
101100 let mut queue_lock = task_queue::lock();
102101 unsafe { usercalls::launch_thread()? };
103- let (task, handle) = task_queue::Task::new(p );
102+ let (task, handle) = task_queue::Task::new(init );
104103 queue_lock.push(task);
105104 Ok(Thread(handle))
106105 }
0 commit comments