-
Notifications
You must be signed in to change notification settings - Fork 5
feat: update state machine for process #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
dc2f85b
a7411b9
2f2bb17
5586ee1
e9c410d
c40e98f
ed92122
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,9 +5,10 @@ use alloc::{ | |||||
| }; | ||||||
| use core::{ | ||||||
| fmt, | ||||||
| sync::atomic::{AtomicBool, Ordering}, | ||||||
| sync::atomic::{AtomicU8, Ordering}, | ||||||
| }; | ||||||
|
|
||||||
| use bitflags::bitflags; | ||||||
| use kspin::SpinNoIrq; | ||||||
| use lazyinit::LazyInit; | ||||||
| use weak_map::StrongMap; | ||||||
|
|
@@ -21,10 +22,19 @@ pub(crate) struct ThreadGroup { | |||||
| pub(crate) group_exited: bool, | ||||||
| } | ||||||
|
|
||||||
| bitflags! { | ||||||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||||||
| pub(crate) struct ProcessState: u8 { | ||||||
| const RUNNING = 1 << 0; | ||||||
| const STOPPED = 1 << 1; | ||||||
| const ZOMBIE = 1 << 2; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /// A process. | ||||||
| pub struct Process { | ||||||
| pid: Pid, | ||||||
| is_zombie: AtomicBool, | ||||||
| state: AtomicU8, | ||||||
| pub(crate) tg: SpinNoIrq<ThreadGroup>, | ||||||
|
|
||||||
| // TODO: child subreaper9 | ||||||
|
|
@@ -191,10 +201,110 @@ impl Process { | |||||
| impl Process { | ||||||
| /// Returns `true` if the [`Process`] is a zombie process. | ||||||
| pub fn is_zombie(&self) -> bool { | ||||||
| self.is_zombie.load(Ordering::Acquire) | ||||||
| let bits = self.state.load(Ordering::Acquire); | ||||||
| ProcessState::from_bits_truncate(bits).contains(ProcessState::ZOMBIE) | ||||||
| } | ||||||
|
|
||||||
| /// Returns `true` if the [`Process`] is running. | ||||||
| pub fn is_running(&self) -> bool { | ||||||
| let bits = self.state.load(Ordering::Acquire); | ||||||
| ProcessState::from_bits_truncate(bits).contains(ProcessState::RUNNING) | ||||||
| } | ||||||
|
|
||||||
| /// Returns `true` if the [`Process`] is stopped. | ||||||
| pub fn is_stopped(&self) -> bool { | ||||||
| let bits = self.state.load(Ordering::Acquire); | ||||||
| ProcessState::from_bits_truncate(bits).contains(ProcessState::STOPPED) | ||||||
| } | ||||||
|
|
||||||
| /// Change the [`Process`] from `Running` to `Stopped`. | ||||||
|
||||||
| /// Change the [`Process`] from `Running` to `Stopped`. | |
| /// Transitions the [`Process`] to `Stopped` state. |
Copilot
AI
Dec 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Similar to transition_to_stopped, the documentation says "Change the [Process] from Stopped to Running" but should more accurately reflect what the method does. Consider: "Transitions the [Process] to Running state."
| /// Change the [`Process`] from `Stopped` to `Running`. | |
| /// Transitions the [`Process`] to `Running` state. |
Uh oh!
There was an error while loading. Please reload this page.