Rename (Posix)ThreadExt to As(Posix)Thread

This commit is contained in:
Ruihan Li
2024-11-12 09:53:01 +08:00
committed by Tate, Hongliang Tian
parent 9233d1cdbb
commit e6c613f538
19 changed files with 30 additions and 30 deletions

View File

@ -9,7 +9,7 @@ use ostd::{
};
use super::{
posix_thread::{thread_table, PosixThread, PosixThreadBuilder, PosixThreadExt, ThreadName},
posix_thread::{thread_table, AsPosixThread, PosixThread, PosixThreadBuilder, ThreadName},
process_table,
process_vm::ProcessVm,
signal::{constants::SIGCHLD, sig_disposition::SigDispositions, sig_num::SigNum},
@ -21,7 +21,7 @@ use crate::{
get_current_userspace,
prelude::*,
process::posix_thread::allocate_posix_tid,
thread::{ThreadExt, Tid},
thread::{AsThread, Tid},
};
bitflags! {

View File

@ -4,10 +4,10 @@ use super::{process_table, Pid, Process, TermStatus};
use crate::{
prelude::*,
process::{
posix_thread::{do_exit, PosixThreadExt},
posix_thread::{do_exit, AsPosixThread},
signal::signals::kernel::KernelSignal,
},
thread::ThreadExt,
thread::AsThread,
};
pub fn do_exit_group(term_status: TermStatus) {

View File

@ -1,7 +1,7 @@
// SPDX-License-Identifier: MPL-2.0
use super::{
posix_thread::{thread_table, PosixThreadExt},
posix_thread::{thread_table, AsPosixThread},
process_table,
signal::{
constants::SIGCONT,

View File

@ -22,7 +22,7 @@ use crate::{
events::Observer,
prelude::*,
process::signal::constants::SIGCONT,
thread::{Thread, ThreadExt, Tid},
thread::{AsThread, Thread, Tid},
time::{clocks::ProfClock, Timer, TimerManager},
};
@ -37,7 +37,7 @@ pub mod thread_table;
pub use builder::PosixThreadBuilder;
pub use exit::do_exit;
pub use name::{ThreadName, MAX_THREAD_NAME_LEN};
pub use posix_thread_ext::{create_posix_task_from_executable, PosixThreadExt};
pub use posix_thread_ext::{create_posix_task_from_executable, AsPosixThread};
pub use robust_list::RobustListHead;
pub struct PosixThread {

View File

@ -11,22 +11,22 @@ use crate::{
fs::fs_resolver::{FsPath, FsResolver, AT_FDCWD},
prelude::*,
process::{process_vm::ProcessVm, program_loader::load_program_to_vm, Credentials, Process},
thread::{Thread, ThreadExt, Tid},
thread::{AsThread, Thread, Tid},
};
/// An extension trait for some [`PosixThread`]-like types.
pub trait PosixThreadExt {
/// A trait to provide the `as_posix_thread` method for tasks and threads.
pub trait AsPosixThread {
/// Returns the associated [`PosixThread`].
fn as_posix_thread(&self) -> Option<&PosixThread>;
}
impl PosixThreadExt for Thread {
impl AsPosixThread for Thread {
fn as_posix_thread(&self) -> Option<&PosixThread> {
self.data().downcast_ref::<PosixThread>()
}
}
impl PosixThreadExt for Task {
impl AsPosixThread for Task {
fn as_posix_thread(&self) -> Option<&PosixThread> {
self.as_thread()?.as_posix_thread()
}

View File

@ -1,7 +1,7 @@
// SPDX-License-Identifier: MPL-2.0
use super::{Thread, Tid};
use crate::{prelude::*, process::posix_thread::PosixThreadExt};
use crate::{prelude::*, process::posix_thread::AsPosixThread};
static THREAD_TABLE: SpinLock<BTreeMap<Tid, Arc<Thread>>> = SpinLock::new(BTreeMap::new());

View File

@ -4,7 +4,7 @@ use core::sync::atomic::{AtomicU32, Ordering};
use self::timer_manager::PosixTimerManager;
use super::{
posix_thread::{allocate_posix_tid, PosixThreadExt},
posix_thread::{allocate_posix_tid, AsPosixThread},
process_table,
process_vm::{Heap, InitStackReader, ProcessVm},
rlimit::ResourceLimits,
@ -21,7 +21,7 @@ use crate::{
fs::{file_table::FileTable, fs_resolver::FsResolver, utils::FileCreationMask},
prelude::*,
sched::priority::{AtomicNice, Nice},
thread::{Thread, ThreadExt},
thread::{AsThread, Thread},
time::clocks::ProfClock,
vm::vmar::Vmar,
};

View File

@ -17,7 +17,7 @@ use ostd::{
use super::Process;
use crate::{
process::{
posix_thread::PosixThreadExt,
posix_thread::AsPosixThread,
signal::{constants::SIGALRM, signals::kernel::KernelSignal},
},
thread::{

View File

@ -7,8 +7,8 @@ use ostd::sync::{WaitQueue, Waiter};
use super::sig_mask::SigMask;
use crate::{
prelude::*,
process::posix_thread::PosixThreadExt,
thread::ThreadExt,
process::posix_thread::AsPosixThread,
thread::AsThread,
time::wait::{ManagedTimeout, TimeoutExt},
};

View File

@ -6,7 +6,7 @@ use super::{process_filter::ProcessFilter, signal::constants::SIGCHLD, ExitCode,
use crate::{
prelude::*,
process::{
posix_thread::{thread_table, PosixThreadExt},
posix_thread::{thread_table, AsPosixThread},
process_table,
signal::with_signal_blocked,
},

View File

@ -8,7 +8,7 @@ use super::SyscallReturn;
use crate::{
prelude::*,
process::{
posix_thread::{thread_table, PosixThreadExt},
posix_thread::{thread_table, AsPosixThread},
process_table,
},
time::{

View File

@ -347,7 +347,7 @@ macro_rules! log_syscall_entry {
let syscall_name_str = stringify!($syscall_name);
let pid = $crate::current!().pid();
let tid = {
use $crate::process::posix_thread::PosixThreadExt;
use $crate::process::posix_thread::AsPosixThread;
$crate::current_thread!().as_posix_thread().unwrap().tid()
};
log::info!(

View File

@ -5,7 +5,7 @@ use core::sync::atomic::Ordering;
use super::SyscallReturn;
use crate::{
prelude::*,
process::{posix_thread::PosixThreadExt, process_table, Pgid, Pid, Process, Uid},
process::{posix_thread::AsPosixThread, process_table, Pgid, Pid, Process, Uid},
sched::priority::{Nice, NiceRange},
};

View File

@ -7,7 +7,7 @@ use super::{
use crate::{
prelude::*,
process::{
posix_thread::{thread_table, PosixThreadExt},
posix_thread::{thread_table, AsPosixThread},
process_table,
signal::{
c_types::{sigevent_t, SigNotify},

View File

@ -5,7 +5,7 @@ use ostd::{
task::{Task, TaskOptions},
};
use super::{oops, status::ThreadStatus, Thread, ThreadExt};
use super::{oops, status::ThreadStatus, AsThread, Thread};
use crate::{prelude::*, sched::priority::Priority};
/// The inner data of a kernel thread.

View File

@ -162,13 +162,13 @@ impl Thread {
}
}
/// An extension trait for [`Thread`]-like types.
pub trait ThreadExt {
/// A trait to provide the `as_thread` method for tasks.
pub trait AsThread {
/// Returns the associated [`Thread`].
fn as_thread(&self) -> Option<&Arc<Thread>>;
}
impl ThreadExt for Task {
impl AsThread for Task {
fn as_thread(&self) -> Option<&Arc<Thread>> {
self.data().downcast_ref::<Arc<Thread>>()
}

View File

@ -10,7 +10,7 @@ use crate::{
cpu::LinuxAbi,
get_current_userspace,
prelude::*,
process::{posix_thread::PosixThreadExt, signal::handle_pending_signal},
process::{posix_thread::AsPosixThread, signal::handle_pending_signal},
syscall::handle_syscall,
thread::exception::handle_exception,
vm::vmar::is_userspace_vaddr,

View File

@ -11,7 +11,7 @@ use super::worker_pool::WorkerPool;
use crate::{
prelude::*,
sched::priority::{Priority, PriorityRange},
thread::{kernel_thread::ThreadOptions, ThreadExt},
thread::{kernel_thread::ThreadOptions, AsThread},
};
/// A worker thread. A `Worker` will attempt to retrieve unfinished

View File

@ -17,7 +17,7 @@ use super::{simple_scheduler::SimpleScheduler, worker::Worker, WorkItem, WorkPri
use crate::{
prelude::*,
sched::priority::{Priority, PriorityRange},
thread::{kernel_thread::ThreadOptions, ThreadExt},
thread::{kernel_thread::ThreadOptions, AsThread},
};
/// A pool of workers.