10#ifndef NSBACI_SERVICES_RUNTIME_THREAD_H
11#define NSBACI_SERVICES_RUNTIME_THREAD_H
46 nsbaci::types::ThreadID
getId()
const;
70 void setPriority(nsbaci::types::Priority newPriority);
77 void push(int32_t value);
94 uint32_t
getPC()
const {
return pc; }
99 void setPC(uint32_t addr) { pc = addr; }
108 uint32_t getBP()
const {
return bp; }
109 void setBP(uint32_t addr) { bp = addr; }
111 uint32_t getSP()
const {
return sp; }
112 void setSP(uint32_t addr) { sp = addr; }
126 if (callStack.empty())
return 0;
127 uint32_t addr = callStack.back();
128 callStack.pop_back();
140 void pushFrame(
const std::vector<int32_t>& savedLocals) {
141 frameStack.push_back(savedLocals);
148 if (frameStack.empty())
return {};
149 auto frame = frameStack.back();
150 frameStack.pop_back();
160 nsbaci::types::ThreadID id;
162 nsbaci::types::Priority priority;
172 std::vector<int32_t> stack;
175 std::vector<uint32_t> callStack;
178 std::vector<std::vector<int32_t>> frameStack;
180 static nsbaci::types::ThreadID nextThreadId;
nsbaci::types::ThreadState getState() const
Gets the current state of the thread.
Definition thread.cpp:22
uint32_t getPC() const
Get the program counter.
Definition thread.h:94
void setPC(uint32_t addr)
Set the program counter.
Definition thread.h:99
nsbaci::types::Priority getPriority() const
Gets the priority of the thread.
Definition thread.cpp:26
void setPriority(nsbaci::types::Priority newPriority)
Sets the priority of the thread.
Definition thread.cpp:28
bool callStackEmpty() const
Check if call stack is empty.
Definition thread.h:135
void setState(nsbaci::types::ThreadState newState)
Sets the state of the thread.
Definition thread.cpp:24
nsbaci::types::ThreadID getId() const
Gets the thread ID.
Definition thread.cpp:20
void pushReturnAddress(uint32_t addr)
Push return address onto call stack.
Definition thread.h:119
int32_t pop()
Pop a value from the thread's stack.
Definition thread.cpp:35
void advancePC()
Increment the program counter.
Definition thread.h:104
void push(int32_t value)
Push a value onto the thread's stack.
Definition thread.cpp:30
uint32_t popReturnAddress()
Pop return address from call stack.
Definition thread.h:125
int32_t top() const
Peek at the top of the stack without removing.
Definition thread.cpp:45
void pushFrame(const std::vector< int32_t > &savedLocals)
Push a frame with saved local variable values.
Definition thread.h:140
bool frameStackEmpty() const
Check if frame stack is empty.
Definition thread.h:157
std::vector< int32_t > popFrame()
Pop a frame and get saved local variable values.
Definition thread.h:147
Runtime services namespace for nsbaci.
Type definitions namespace for nsbaci (runtime-specific).
std::queue< nsbaci::services::runtime::Thread > ThreadQueue
Queue of threads for scheduler operations.
Definition thread.h:194
ThreadState
Definition runtimeTypes.h:26
@ Ready
Thread is ready to run.
Definition runtimeTypes.h:27
Type definitions for runtime-related operations.