Mark3 Realtime Kernel
scheduler.h
Go to the documentation of this file.
1 /*===========================================================================
2  _____ _____ _____ _____
3  ___| _|__ __|_ |__ __|__ |__ __| __ |__ ______
4 | \ / | || \ || | || |/ / ||___ |
5 | \/ | || \ || \ || \ ||___ |
6 |__/\__/|__|_||__|\__\ __||__|\__\ __||__|\__\ __||______|
7  |_____| |_____| |_____| |_____|
8 
9 --[Mark3 Realtime Platform]--------------------------------------------------
10 
11 Copyright (c) 2012 - 2019 m0slevin, all rights reserved.
12 See license.txt for more information
13 =========================================================================== */
45 #pragma once
46 
47 #include "kerneltypes.h"
48 #include "thread.h"
49 #include "ithreadport.h"
50 #include "priomap.h"
51 
52 extern Mark3::Thread* g_pclNext;
54 
55 namespace Mark3
56 {
57 //---------------------------------------------------------------------------
63 class Scheduler
64 {
65 public:
70  static void Init();
71 
78  static void Schedule();
79 
86  static void Add(Thread* pclThread_);
87 
95  static void Remove(Thread* pclThread_);
96 
108  static bool SetScheduler(bool bEnable_);
109 
116  static Thread* GetCurrentThread() { return g_pclCurrent; }
124  static volatile Thread* GetNextThread() { return g_pclNext; }
134  static ThreadList* GetThreadList(PORT_PRIO_TYPE uXPriority_) { return &m_aclPriorities[uXPriority_]; }
142  static ThreadList* GetStopList() { return &m_clStopList; }
150  static bool IsEnabled() { return m_bEnabled; }
156  static void QueueScheduler() { m_bQueuedSchedule = true; }
157 
158 private:
159  static constexpr auto m_uNumPriorities = size_t { KERNEL_NUM_PRIORITIES };
160 
162  static bool m_bEnabled;
163 
165  static bool m_bQueuedSchedule;
166 
169 
172 
175 };
176 } // namespace Mark3
Mark3::Thread * g_pclNext
Definition: scheduler.cpp:24
static PriorityMap m_clPrioMap
Priority bitmap lookup structure, 1-bit per thread priority.
Definition: scheduler.h:174
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...
Definition: scheduler.h:150
static ThreadList * GetStopList()
GetStopList Return the pointer to the list of threads that are in the scheduler's stopped state...
Definition: scheduler.h:142
static void Add(Thread *pclThread_)
Add Add a thread to the scheduler at its current priority level.
Definition: scheduler.cpp:59
Thread porting interface.
The ThreadList Class. This class is used for building thread-management facilities, such as schedulers, and blocking objects.
Definition: threadlist.h:38
static bool m_bEnabled
Scheduler's state - enabled or disabled.
Definition: scheduler.h:162
static bool m_bQueuedSchedule
Variable representing whether or not there's a queued scheduler operation.
Definition: scheduler.h:165
#define PORT_PRIO_TYPE
Type used for bitmap in the PriorityMap class.
Definition: portcfg.h:73
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...
Definition: scheduler.h:134
static ThreadList m_clStopList
ThreadList for all stopped threads.
Definition: scheduler.h:168
Definition: atomic.cpp:23
static ThreadList m_aclPriorities[m_uNumPriorities]
ThreadLists for all threads at all priorities.
Definition: scheduler.h:171
Platform independent thread class declarations Threads are an atomic unit of execution, and each instance of the thread class represents an instance of a program running of the processor. The Thread is the fundmanetal user-facing object in the kernel - it is what makes multiprocessing possible from application code.
static void QueueScheduler()
QueueScheduler Tell the kernel to perform a scheduling operation as soon as the scheduler is re-enabl...
Definition: scheduler.h:156
The Thread Class. This object providing the fundamental thread control data structures and functions ...
Definition: thread.h:64
The Scheduler Class. This class provides priority-based round-robin Thread scheduling for all active ...
Definition: scheduler.h:63
#define KERNEL_NUM_PRIORITIES
Definition: portcfg.h:35
Priority map data structure.
The PriorityMapL1 class This class implements a priority bitmap data structure. Each bit in the objec...
Definition: priomapl1.h:45
static void Schedule()
Schedule Run the scheduler, determines the next thread to run based on the current state of the threa...
Definition: scheduler.cpp:45
static void Init()
Init Intiailize the scheduler, must be called before use.
Definition: scheduler.cpp:36
static void Remove(Thread *pclThread_)
Remove Remove a thread from the scheduler at its current priority level.
Definition: scheduler.cpp:67
static constexpr auto m_uNumPriorities
Definition: scheduler.h:159
static Thread * GetCurrentThread()
GetCurrentThread Return the pointer to the currently-running thread.
Definition: scheduler.h:116
static volatile Thread * GetNextThread()
GetNextThread Return the pointer to the thread that should run next, according to the last run of the...
Definition: scheduler.h:124
Mark3::Thread * g_pclCurrent
Definition: scheduler.cpp:25
static bool SetScheduler(bool bEnable_)
SetScheduler Set the active state of the scheduler. When the scheduler is disabled, the next thread is never set; the currently running thread will run forever until the scheduler is enabled again. Care must be taken to ensure that we don't end up trying to block while the scheduler is disabled, otherwise the system ends up in an unusable state.
Definition: scheduler.cpp:75