Fix the thread status ordering by limiting the API

This commit is contained in:
Zhang Junyang
2024-09-29 10:29:27 +08:00
committed by Tate, Hongliang Tian
parent 55bf2c847c
commit 1b23182dcc
7 changed files with 58 additions and 47 deletions

View File

@ -71,7 +71,7 @@ pub fn tgkill(tid: Tid, tgid: Pid, signal: Option<UserSignal>, ctx: &Context) ->
let thread = thread_table::get_thread(tid)
.ok_or_else(|| Error::with_message(Errno::ESRCH, "target thread does not exist"))?;
if thread.status().is_exited() {
if thread.is_exited() {
return Ok(());
}

View File

@ -14,7 +14,7 @@ use crate::{
///
/// If the thread is not a POSIX thread, this method will panic.
pub fn do_exit(thread: &Thread, posix_thread: &PosixThread, term_status: TermStatus) -> Result<()> {
if thread.status().is_exited() {
if thread.is_exited() {
return Ok(());
}
thread.exit();

View File

@ -277,7 +277,7 @@ impl PosixThread {
let tasks = process.tasks().lock();
tasks
.iter()
.all(|task| Thread::borrow_from_task(task).status().is_exited())
.all(|task| Thread::borrow_from_task(task).is_exited())
}
/// Gets the read-only credentials of the thread.

View File

@ -31,7 +31,6 @@ use crate::{
get_current_userspace,
prelude::*,
process::{do_exit_group, TermStatus},
thread::status::ThreadStatus,
};
pub trait SignalContext {
@ -107,20 +106,10 @@ pub fn handle_pending_signal(user_ctx: &mut UserContext, ctx: &Context) -> Resul
}
SigDefaultAction::Ign => {}
SigDefaultAction::Stop => {
let _ = ctx.thread.atomic_status().compare_exchange(
ThreadStatus::Running,
ThreadStatus::Stopped,
Ordering::AcqRel,
Ordering::Relaxed,
);
let _ = ctx.thread.stop();
}
SigDefaultAction::Cont => {
let _ = ctx.thread.atomic_status().compare_exchange(
ThreadStatus::Stopped,
ThreadStatus::Running,
Ordering::AcqRel,
Ordering::Relaxed,
);
let _ = ctx.thread.resume();
}
}
}