52 static auto u8ThreadID = uint8_t { 0 };
71 #if KERNEL_NAMED_THREADS 74 #if KERNEL_ROUND_ROBIN 92 #if KERNEL_THREAD_CREATE_CALLOUT 94 if (
nullptr != pfCallout) {
103 auto* pclNew = AutoAlloc::NewObject<Thread, AutoAllocType::Thread>();
105 pclNew->Init(pwStack, u16StackSize_, uXPriority_, pfEntryPoint_, pvArg_);
124 #if KERNEL_ROUND_ROBIN 145 auto bReschedule =
false;
156 #if KERNEL_ROUND_ROBIN 191 auto bReschedule =
false;
204 #if KERNEL_ROUND_ROBIN 235 #if KERNEL_THREAD_EXIT_CALLOUT 237 if (
nullptr != pfCallout) {
253 auto lTimerCallback = [](
Thread* ,
void* pvData_) {
254 auto* pclSemaphore =
static_cast<Semaphore*
>(pvData_);
255 pclSemaphore->
Post();
259 clSemaphore.Init(0, 1);
264 pclTimer->Start(
false, u32TimeMs_, lTimerCallback, &clSemaphore);
269 #if KERNEL_STACK_CHECK 275 auto wBottom = uint16_t { 0 };
277 auto wMid =
static_cast<uint16_t
>(((wTop + wBottom) + 1) / 2);
284 while ((wTop - wBottom) > 1) {
285 #if PORT_STACK_GROWS_DOWN 286 if (
m_pwStack[wMid] != static_cast<K_WORD>(-1))
288 if (
m_pwStack[wMid] == static_cast<K_WORD>(-1))
295 wMid = (wTop + wBottom + 1) / 2;
299 return wMid *
sizeof(
K_WORD);
313 #if KERNEL_ROUND_ROBIN 344 auto bSchedule =
false;
353 #if KERNEL_ROUND_ROBIN 370 #if KERNEL_ROUND_ROBIN 395 #if KERNEL_STACK_CHECK 400 #if KERNEL_CONTEXT_SWITCH_CALLOUT 402 if (
nullptr != pfCallout) {
uint16_t m_u16Quantum
Thread quantum (in milliseconds)
K_WORD * m_pwStack
Pointer to the thread's stack.
static void Remove(Timer *pclListNode_)
Remove Remove a timer from the timer scheduler. May implicitly stop the timer if this is the only act...
static void Update(Thread *pclTargetThread_)
Update Update the current thread being tracked for round-robing scheduling. Note - this has no effect...
#define K_WORD
Size of a data word.
Basic data type primatives used throughout the OS.
static bool IsEnabled()
IsEnabled Return the current state of the scheduler - whether or not scheudling is enabled or disable...
static ThreadList * GetStopList()
GetStopList Return the pointer to the list of threads that are in the scheduler's stopped state...
void PivotForward()
PivotForward Pivot the head of the circularly linked list forward ( Head = Head->next, Tail = Tail->next )
static void Add(Thread *pclThread_)
Add Add a thread to the scheduler at its current priority level.
void Exit()
Exit. Remove the thread from being scheduled again. The thread is effectively destroyed when this occ...
void(*)(Thread *pclThread_) ThreadExitCallout
void(*)(Thread *pclThread_) ThreadCreateCallout
PORT_PRIO_TYPE m_uXCurPriority
Current priority of the thread (priority inheritence)
PORT_PRIO_TYPE m_uXPriority
Default priority of the thread.
void Init(K_WORD *pwStack_, uint16_t u16StackSize_, PORT_PRIO_TYPE uXPriority_, ThreadEntryFunc pfEntryPoint_, void *pvArg_)
Init Initialize a thread prior to its use. Initialized threads are placed in the stopped state...
void Init()
Init Re-initialize the Timer to default values.
static void CoopYield(void)
CoopYield Cooperative yield - This forces the system to not only call the scheduler, but also move the currently executing thread to the back of the current thread list, allowing other same-priority threads the opportunity to run. This is used primarily for cooperative scheduling between threads in the same priority level.
ThreadList * m_pclCurrent
Pointer to the thread-list where the thread currently resides.
uint16_t m_u16StackSize
Size of the stack (in bytes)
#define PORT_PRIO_TYPE
Type used for bitmap in the PriorityMap class.
the Semaphore class provides Binary & Counting semaphore objects, based on BlockingObject base class...
bool m_bExpired
Indicate whether or not a blocking-object timeout has occurred.
K_WORD * m_pwStackTop
Pointer to the top of the thread's stack.
static void ContextSwitchSWI(void)
ContextSwitchSWI This code is used to trigger the context switch interrupt. Called whenever the kerne...
ThreadEntryFunc m_pfEntryPoint
The entry-point function called when the thread starts.
bool IsInitialized()
IsInitialized Used to check whether or not a thread has been initialized prior to use...
void InheritPriority(PORT_PRIO_TYPE uXPriority_)
InheritPriority Allow the thread to run at a different priority level (temporarily) for the purpose o...
static ThreadList * GetThreadList(PORT_PRIO_TYPE uXPriority_)
GetThreadList Return the pointer to the active list of threads that are at the given priority level i...
#define PANIC_RUNNING_THREAD_DESCOPED
static void Trigger(void)
Trigger Call the software interrupt.
void * m_pvArg
Pointer to the argument passed into the thread's entrypoint.
uint16_t GetStackSlack()
GetStackSlack Performs a (somewhat lengthy) check on the thread stack to check the amount of stack ma...
static ThreadCreateCallout GetThreadCreateCallout()
GetThreadCreateCallout Return the current function called on every Thread::Init();.
void Remove(Thread *node_)
Remove Remove the specified thread from the threadlist.
Mark3 Kernel Configuration This file is used to configure the kernel for your specific application in...
Timer m_clTimer
Timer used for blocking-object timeouts.
void ClearNode()
ClearNode.
Mark3::Thread * g_pclCurrent
PORT_PRIO_TYPE GetCurPriority(void)
GetCurPriority Return the priority of the current thread.
static void QueueScheduler()
QueueScheduler Tell the kernel to perform a scheduling operation as soon as the scheduler is re-enabl...
Single include file given to users of the Mark3 Kernel API.
The Thread Class. This object providing the fundamental thread control data structures and functions ...
const char * m_szName
Thread name.
void SetExpired(bool bExpired_)
SetExpired Set the status of the current blocking call on the thread.
void SetCurrent(ThreadList *pclNewList_)
SetCurrent. Set the thread's current to the specified thread list.
#define PANIC_STACK_SLACK_VIOLATED
Mark3::Thread * g_pclNext
static ThreadContextCallout GetThreadContextSwitchCallout()
GetThreadContextSwitchCallout Return the current function called on every Thread::ContextSwitchSWI() ...
static void InitStack(Thread *pstThread_)
InitStack Initialize the thread's stack.
void Start()
Start Start the thread - remove it from the stopped list, add it to the scheduler's list of threads (...
ThreadState m_eState
Enum indicating the thread's current state.
static void Yield(void)
Yield Yield the thread - this forces the system to call the scheduler and determine what thread shoul...
void SetOwner(ThreadList *pclNewList_)
SetOwner. Set the thread's owner to the specified thread list.
#define THREAD_QUANTUM_DEFAULT
void Stop()
Stop Stop a thread that's actively scheduled without destroying its stacks. Stopped threads can be re...
static void Schedule()
Schedule Run the scheduler, determines the next thread to run based on the current state of the threa...
static bool IsStarted()
IsStarted.
The CriticalGuard class. This class provides an implemention of RAII for critical sections...
void(*)(void *pvArg_) ThreadEntryFunc
static void Sleep(uint32_t u32TimeMs_)
Sleep Put the thread to sleep for the specified time (in milliseconds). Actual time slept may be long...
bool GetExpired()
GetExpired Return the status of the most-recent blocking call on the thread.
void Add(Thread *node_)
Add Add a thread to the threadlist.
The Timer Class. This class provides kernel-managed timers, used to provide high-precision delays...
static void * NewRawData(size_t sSize_)
NewRawData Attempt to allocate a blob of raw data from the heap.
ThreadList * GetCurrent(void)
GetCurrent Return the ThreadList where the thread is currently located.
bool Post()
Increment the semaphore count. If the semaphore count is zero at the time this is called...
static void Remove(Thread *pclThread_)
Remove Remove a thread from the scheduler at its current priority level.
static uint16_t GetStackGuardThreshold()
void SetPriorityBase(PORT_PRIO_TYPE uXPriority_)
SetPriorityBase.
#define PORT_TOP_OF_STACK(x, y)
Macro to find the top of a stack given its size and top address.
uint8_t m_u8ThreadID
Thread ID.
static ThreadExitCallout GetThreadExitCallout()
GetThreadExitCallout Return the current function called on every Thread::Exit();. ...
PORT_PRIO_TYPE GetPriority(void)
GetPriority Return the priority of the current thread.
static Thread * GetCurrentThread()
GetCurrentThread Return the pointer to the currently-running thread.
ThreadList * m_pclOwner
Pointer to the thread-list where the thread resides when active.
void SetPriority(PORT_PRIO_TYPE uXPriority_)
SetPriority. Set the priority of the Thread (running or otherwise) to a different level...
static void Panic(uint16_t u16Cause_)
Panic Cause the kernel to enter its panic state.