contur2
Loading...
Searching...
No Matches
state.h
Go to the documentation of this file.
1
19
20#pragma once
21
22#include <cstdint>
23#include <string_view>
24
25namespace contur {
26
28 enum class ProcessState : std::uint8_t
29 {
36 };
37
53 [[nodiscard]] constexpr bool isValidTransition(ProcessState from, ProcessState to) noexcept
54 {
55 switch (from)
56 {
58 return to == ProcessState::Ready;
59
62
65
67 return to == ProcessState::Ready || to == ProcessState::Suspended;
68
70 return to == ProcessState::Ready;
71
73 return false; // Terminal state — no outgoing transitions.
74 }
75 return false;
76 }
77
79 [[nodiscard]] constexpr std::string_view processStateName(ProcessState state) noexcept
80 {
81 switch (state)
82 {
84 return "New";
86 return "Ready";
88 return "Running";
90 return "Blocked";
92 return "Suspended";
94 return "Terminated";
95 }
96 return "Unknown";
97 }
98
99} // namespace contur
Definition block.h:15
ProcessState
All possible states in a process lifecycle.
Definition state.h:29
@ New
Process has been created but not yet admitted to the ready queue.
Definition state.h:30
@ Blocked
Process is waiting for an event (I/O, sync primitive, etc.).
Definition state.h:33
@ Running
Process is currently executing on the CPU.
Definition state.h:32
@ Suspended
Process has been swapped out of main memory.
Definition state.h:34
@ Ready
Process is waiting in the ready queue for CPU time.
Definition state.h:31
@ Terminated
Process has finished execution (exit or error).
Definition state.h:35
constexpr std::string_view processStateName(ProcessState state) noexcept
Returns a human-readable name for the given process state.
Definition state.h:79
constexpr bool isValidTransition(ProcessState from, ProcessState to) noexcept
Validates whether a transition from one process state to another is legal.
Definition state.h:53