Mark3 Realtime Kernel
threadlist.cpp
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 ===========================================================================*/
22 #include "mark3.h"
23 #include "threadlistlist.h"
24 namespace Mark3
25 {
26 //---------------------------------------------------------------------------
28  : m_uXPriority(0)
29  , m_pclMap(nullptr)
30 {
31 }
32 
33 //---------------------------------------------------------------------------
35 {
36  m_uXPriority = uXPriority_;
37 }
38 
39 //---------------------------------------------------------------------------
41 {
42  KERNEL_ASSERT(pclMap_ != nullptr);
43  m_pclMap = pclMap_;
44 }
45 
46 //---------------------------------------------------------------------------
47 void ThreadList::Add(Thread* pclThread_)
48 {
49  KERNEL_ASSERT(pclThread_ != nullptr);
50 
51  // If list was empty, add the object for global threadlist tracking
52  if (!GetHead()) {
53  ThreadListList::Add(this);
54  }
56  PivotForward();
57 
58  // We've specified a bitmap for this threadlist
59  if (nullptr != m_pclMap) {
60  // Set the flag for this priority level
62  }
63 }
64 
65 //---------------------------------------------------------------------------
67 {
68  KERNEL_ASSERT(node_ != nullptr);
69  auto* pclCurr = GetHead();
70  if (nullptr == pclCurr) {
71  Add(pclThread_);
72  return;
73  }
74  auto uXHeadPri = pclCurr->GetCurPriority();
75  auto* pclTail = GetTail();
76 
77  // Set the threadlist's priority level, flag pointer, and then add the
78  // thread to the threadlist
79  auto uXPriority = pclThread_->GetCurPriority();
80  do {
81  if (uXPriority > pclCurr->GetCurPriority()) {
82  break;
83  }
84  pclCurr = pclCurr->GetNext();
85  } while (pclCurr != pclTail);
86 
87  // Insert pclNode before pclCurr in the linked list.
88  InsertNodeBefore(pclThread_, pclCurr);
89 
90  // If the priority is greater than current head, reset
91  // the head pointer.
92  if (uXPriority > uXHeadPri) {
93  SetHead(pclThread_);
94  SetTail(GetHead()->GetPrev());
95  } else if (pclThread_->GetNext() == GetHead()) {
96  SetTail(pclThread_);
97  }
98 }
99 
100 //---------------------------------------------------------------------------
101 void ThreadList::Add(Thread* node_, PriorityMap* pclMap_, PORT_PRIO_TYPE uXPriority_)
102 {
103  // Set the threadlist's priority level, flag pointer, and then add the
104  // thread to the threadlist
105  SetPriority(uXPriority_);
106  SetMapPointer(pclMap_);
107  Add(node_);
108 }
109 
110 //---------------------------------------------------------------------------
112 {
113  // Remove the thread from the list
115 
116  // If the list is empty...
117  if (nullptr == GetHead()) {
118  // No more threads - remove this object from global threadlist tracking
120  if (nullptr != m_pclMap) {
121  // Clear the bit in the bitmap at this priority level
123  }
124  }
125 }
126 
127 //---------------------------------------------------------------------------
129 {
130  return GetHead();
131 }
132 } // namespace Mark3
void SetMapPointer(PriorityMap *pclMap_)
SetMapPointer Set the pointer to a bitmap to use for this threadlist. Once again, only needed when th...
Definition: threadlist.cpp:40
PriorityMap * m_pclMap
Pointer to the bitmap/flag to set when used for scheduling.
Definition: threadlist.h:116
PORT_PRIO_TYPE m_uXPriority
Priority of the threadlist.
Definition: threadlist.h:113
#define PORT_PRIO_TYPE
Type used for bitmap in the PriorityMap class.
Definition: portcfg.h:73
#define KERNEL_ASSERT(x)
Definition: kerneldebug.h:36
Class implementing a doubly-linked list of thread lists.
static void Add(ThreadList *pclThreadList_)
Add Add a ThreadList to the list for tracking.
void Remove(Thread *node_)
Remove Remove the specified thread from the threadlist.
Definition: threadlist.cpp:111
Definition: atomic.cpp:23
PORT_PRIO_TYPE GetCurPriority(void)
GetCurPriority Return the priority of the current thread.
Definition: thread.h:181
void SetPriority(PORT_PRIO_TYPE uXPriority_)
SetPriority Set the priority of this threadlist (if used for a scheduler).
Definition: threadlist.cpp:34
static void Remove(ThreadList *pclThreadList_)
Remove Remove a threadlist from tracking.
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 ...
Definition: thread.h:64
void AddPriority(Thread *node_)
AddPriority Add a thread to the list such that threads are ordered from highest to lowest priority fr...
Definition: threadlist.cpp:66
The PriorityMapL1 class This class implements a priority bitmap data structure. Each bit in the objec...
Definition: priomapl1.h:45
Thread * HighestWaiter()
HighestWaiter Return a pointer to the highest-priority thread in the thread-list. ...
Definition: threadlist.cpp:128
ThreadList()
ThreadList Default constructor - zero-initializes the data.
Definition: threadlist.cpp:27
void Add(Thread *node_)
Add Add a thread to the threadlist.
Definition: threadlist.cpp:47
void Set(T uXPrio_)
Set Set the priority map bitmap data, at all levels, for the given priority.
Definition: priomapl1.h:62
void Clear(T uXPrio_)
Clear Clear the priority map bitmap data, at all levels, for the given priority.
Definition: priomapl1.h:73