contur2
Loading...
Searching...
No Matches
pcb.h
Go to the documentation of this file.
1
6
7#pragma once
8
9#include <memory>
10#include <string>
11#include <string_view>
12
13#include "contur/core/types.h"
14
17
18namespace contur {
19
36
39 {
42 std::uint32_t codeSize = 0;
43 std::uint32_t slot = 0;
44
46 constexpr ProcessAddressInfo() noexcept = default;
47 };
48
54 class PCB
55 {
56 public:
63
65
66 // Non-copyable
67 PCB(const PCB &) = delete;
68 PCB &operator=(const PCB &) = delete;
69
70 // Movable
71 PCB(PCB &&) noexcept;
72 PCB &operator=(PCB &&) noexcept;
73
75 [[nodiscard]] ProcessId id() const noexcept;
76
78 [[nodiscard]] std::string_view name() const noexcept;
79
81 [[nodiscard]] ProcessState state() const noexcept;
82
87 [[nodiscard]] bool setState(ProcessState newState, Tick currentTick = 0);
88
90 [[nodiscard]] const Priority &priority() const noexcept;
91
94
97
99 void setNice(std::int32_t nice);
100
102 [[nodiscard]] const ProcessTiming &timing() const noexcept;
103
105 [[nodiscard]] ProcessTiming &timing() noexcept;
106
108 void addCpuTime(Tick ticks);
109
111 void addWaitTime(Tick ticks);
112
114 void addBlockedTime(Tick ticks);
115
117 [[nodiscard]] const ProcessAddressInfo &addressInfo() const noexcept;
118
120 [[nodiscard]] ProcessAddressInfo &addressInfo() noexcept;
121
122 private:
123 struct Impl;
124 std::unique_ptr<Impl> impl_;
125 };
126
127} // namespace contur
const ProcessTiming & timing() const noexcept
Returns a const reference to the process timing data.
void setEffectivePriority(PriorityLevel level)
Sets only the effective priority level (for dynamic scheduling).
PCB(const PCB &)=delete
PCB & operator=(const PCB &)=delete
void setPriority(const Priority &priority)
Sets the full priority descriptor.
std::unique_ptr< Impl > impl_
Definition pcb.h:124
std::string_view name() const noexcept
Returns the human-readable process name.
void addCpuTime(Tick ticks)
Adds the given number of ticks to the total CPU time.
const ProcessAddressInfo & addressInfo() const noexcept
Returns a const reference to the address mapping info.
void setNice(std::int32_t nice)
Sets the nice value (clamped to valid range).
const Priority & priority() const noexcept
Returns a const reference to the process priority.
bool setState(ProcessState newState, Tick currentTick=0)
Transitions the process to a new state.
ProcessState state() const noexcept
Returns the current process state.
PCB(PCB &&) noexcept
PCB(ProcessId id, std::string name, Priority priority=Priority{}, Tick arrivalTime=0)
Constructs a PCB with the given ID, name, and optional priority.
void addBlockedTime(Tick ticks)
Adds the given number of ticks to the total blocked time.
void addWaitTime(Tick ticks)
Adds the given number of ticks to the total wait time.
Definition block.h:15
ProcessState
All possible states in a process lifecycle.
Definition state.h:29
PriorityLevel
Discrete priority levels, from highest (Realtime) to lowest (Idle).
Definition priority.h:20
constexpr MemoryAddress NULL_ADDRESS
Sentinel value indicating an invalid/null memory address.
Definition types.h:49
std::uint64_t Tick
Simulation clock tick counter.
Definition types.h:18
std::uint32_t ProcessId
Unique identifier for a process.
Definition types.h:12
std::uint32_t MemoryAddress
Represents a memory address (physical or virtual).
Definition types.h:15
Process priority levels and the Priority struct.
ProcessState enum class and validated state transitions.
Composite priority descriptor for a process.
Definition priority.h:46
Aggregate holding virtual memory address mapping for a process.
Definition pcb.h:39
std::uint32_t codeSize
Size of code segment (in blocks).
Definition pcb.h:42
constexpr ProcessAddressInfo() noexcept=default
Default constructor.
std::uint32_t slot
Virtual memory slot index.
Definition pcb.h:43
MemoryAddress codeStart
Start of code segment.
Definition pcb.h:41
MemoryAddress virtualBase
Base address in virtual memory.
Definition pcb.h:40
Aggregate holding process timing statistics.
Definition pcb.h:22
Tick estimatedBurst
Predicted next CPU burst (for SPN/SRT).
Definition pcb.h:30
Tick finishTime
Tick when the process entered Terminated.
Definition pcb.h:25
constexpr ProcessTiming() noexcept=default
Default constructor.
Tick arrivalTime
Tick when the process was created.
Definition pcb.h:23
Tick totalBlockedTime
Cumulative ticks spent in Blocked state.
Definition pcb.h:28
Tick remainingBurst
Remaining ticks in current burst (for SRT).
Definition pcb.h:31
Tick startTime
Tick when the process first entered Running.
Definition pcb.h:24
Tick totalCpuTime
Cumulative ticks spent in Running state.
Definition pcb.h:26
Tick totalWaitTime
Cumulative ticks spent in Ready state.
Definition pcb.h:27
Tick lastStateChange
Tick of the most recent state transition.
Definition pcb.h:29
Common type aliases, sentinel constants, and forward declarations used throughout the Contur 2 kernel...