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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,7 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use super::{Thread, Tid}; 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()); 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 self::timer_manager::PosixTimerManager;
use super::{ use super::{
posix_thread::{allocate_posix_tid, PosixThreadExt}, posix_thread::{allocate_posix_tid, AsPosixThread},
process_table, process_table,
process_vm::{Heap, InitStackReader, ProcessVm}, process_vm::{Heap, InitStackReader, ProcessVm},
rlimit::ResourceLimits, rlimit::ResourceLimits,
@ -21,7 +21,7 @@ use crate::{
fs::{file_table::FileTable, fs_resolver::FsResolver, utils::FileCreationMask}, fs::{file_table::FileTable, fs_resolver::FsResolver, utils::FileCreationMask},
prelude::*, prelude::*,
sched::priority::{AtomicNice, Nice}, sched::priority::{AtomicNice, Nice},
thread::{Thread, ThreadExt}, thread::{AsThread, Thread},
time::clocks::ProfClock, time::clocks::ProfClock,
vm::vmar::Vmar, vm::vmar::Vmar,
}; };

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -5,7 +5,7 @@ use core::sync::atomic::Ordering;
use super::SyscallReturn; use super::SyscallReturn;
use crate::{ use crate::{
prelude::*, 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}, sched::priority::{Nice, NiceRange},
}; };

View File

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

View File

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

View File

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

View File

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

View File

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