mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-28 20:03:22 +00:00
Utilize ThreadLocal
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
38fcaaf749
commit
0bfe7aceb8
@ -10,19 +10,27 @@ use crate::{
|
||||
cpu::LinuxAbi,
|
||||
current_userspace,
|
||||
prelude::*,
|
||||
process::{posix_thread::AsPosixThread, signal::handle_pending_signal},
|
||||
process::{
|
||||
posix_thread::{AsPosixThread, AsThreadLocal, ThreadLocal},
|
||||
signal::handle_pending_signal,
|
||||
},
|
||||
syscall::handle_syscall,
|
||||
thread::exception::handle_exception,
|
||||
thread::{exception::handle_exception, AsThread},
|
||||
vm::vmar::is_userspace_vaddr,
|
||||
};
|
||||
|
||||
/// create new task with userspace and parent process
|
||||
pub fn create_new_user_task(user_space: Arc<UserSpace>, thread_ref: Arc<Thread>) -> Task {
|
||||
pub fn create_new_user_task(
|
||||
user_space: Arc<UserSpace>,
|
||||
thread_ref: Arc<Thread>,
|
||||
thread_local: ThreadLocal,
|
||||
) -> Task {
|
||||
fn user_task_entry() {
|
||||
let current_thread = current_thread!();
|
||||
let current_posix_thread = current_thread.as_posix_thread().unwrap();
|
||||
let current_process = current_posix_thread.process();
|
||||
let current_task = Task::current().unwrap();
|
||||
let current_thread = current_task.as_thread().unwrap();
|
||||
let current_posix_thread = current_thread.as_posix_thread().unwrap();
|
||||
let current_thread_local = current_task.as_thread_local().unwrap();
|
||||
let current_process = current_posix_thread.process();
|
||||
|
||||
let user_space = current_task
|
||||
.user_space()
|
||||
@ -41,7 +49,7 @@ pub fn create_new_user_task(user_space: Arc<UserSpace>, thread_ref: Arc<Thread>)
|
||||
user_mode.context().syscall_ret()
|
||||
);
|
||||
|
||||
let child_tid_ptr = *current_posix_thread.set_child_tid().lock();
|
||||
let child_tid_ptr = current_thread_local.set_child_tid().get();
|
||||
|
||||
// The `clone` syscall may require child process to write the thread pid to the specified address.
|
||||
// Make sure the store operation completes before the clone call returns control to user space
|
||||
@ -56,6 +64,7 @@ pub fn create_new_user_task(user_space: Arc<UserSpace>, thread_ref: Arc<Thread>)
|
||||
|
||||
let ctx = Context {
|
||||
process: current_process.as_ref(),
|
||||
thread_local: current_thread_local,
|
||||
posix_thread: current_posix_thread,
|
||||
thread: current_thread.as_ref(),
|
||||
task: current_task.as_ref(),
|
||||
@ -99,6 +108,7 @@ pub fn create_new_user_task(user_space: Arc<UserSpace>, thread_ref: Arc<Thread>)
|
||||
let _ = oops::catch_panics_as_oops(user_task_entry);
|
||||
})
|
||||
.data(thread_ref)
|
||||
.local_data(thread_local)
|
||||
.user_space(Some(user_space))
|
||||
.build()
|
||||
.expect("spawn task failed")
|
||||
|
Reference in New Issue
Block a user