Mark3 Realtime Kernel
cosched.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 =========================================================================== */
20 #include "cosched.h"
21 #include "criticalguard.h"
22 
23 namespace Mark3 {
27 
28 //---------------------------------------------------------------------------
30 {
32  for (auto i = 0; i < PORT_COROUTINE_PRIORITIES; i++) {
35  }
36 }
37 
38 //---------------------------------------------------------------------------
40 {
41  return &m_clPrioMap;
42 }
43 
44 //---------------------------------------------------------------------------
46 {
47  return &m_clStopList;
48 }
49 
50 //---------------------------------------------------------------------------
52 {
53  if (uPriority_ >= PORT_COROUTINE_PRIORITIES) {
54  return nullptr;
55  }
56  return &m_aclPriorities[uPriority_];
57 }
58 
59 //---------------------------------------------------------------------------
61 {
62  const auto cs = CriticalGuard{};
63 
64  auto uPriority = m_clPrioMap.HighestPriority();
65  if (0 == uPriority) {
66  return nullptr;
67  }
68  uPriority--;
69  return m_aclPriorities[uPriority].GetHead();
70 }
71 } // namespace Mark3
CoRoutine Scheduler implementation.
The CoList class The CoList class implements a circular-linked-listed structure for coroutine objects...
Definition: colist.h:35
static CoList m_clStopList
Definition: cosched.h:81
static CoList * GetStopList()
GetStopList Get the pointer to the coroutine list managing initialized coroutines that are not awaiti...
Definition: cosched.cpp:45
void SetPrioMap(CoPrioMap *pclPrioMap_)
SetPrioMap Assign a priority map object to this co-routine list.
Definition: colist.cpp:24
#define PORT_PRIO_TYPE
Type used for bitmap in the PriorityMap class.
Definition: portcfg.h:73
static CoPrioMap * GetPrioMap()
GetPrioMap Get the pointer to the priority map object used by the scheduler.
Definition: cosched.cpp:39
Definition: atomic.cpp:23
static CoPrioMap m_clPrioMap
Definition: cosched.h:82
#define PORT_COROUTINE_PRIORITIES
Definition: portcfg.h:47
static CoList m_aclPriorities[PORT_COROUTINE_PRIORITIES]
Definition: cosched.h:80
void SetPriority(PORT_PRIO_TYPE uPriority_)
SetPriority Set the scheduling priority of this coroutine liss; has no effect unless a SetPrioMap has...
Definition: colist.cpp:30
static CoList * GetCoList(PORT_PRIO_TYPE uPriority_)
GetCoList Retrieve the coroutine list associated with a given priority.
Definition: cosched.cpp:51
The Coroutine class implements a lightweight, run-to-completion task that forms the basis for co-oper...
Definition: coroutine.h:53
RAII Critical Section Implementation.
PriorityMapL1< PORT_PRIO_TYPE, PORT_COROUTINE_PRIORITIES > CoPrioMap
Definition: coroutine.h:30
The PriorityMapL1 class This class implements a priority bitmap data structure. Each bit in the objec...
Definition: priomapl1.h:45
T HighestPriority(void)
HighestPriority Computes the numeric priority of the highest-priority thread represented in the prior...
Definition: priomapl1.h:86
The CriticalGuard class. This class provides an implemention of RAII for critical sections...
Definition: criticalguard.h:38
static void Init()
Init Initialize the coroutine scheduler prior to use. Must be called prior to using any other functio...
Definition: cosched.cpp:29
static Coroutine * Schedule()
Schedule Determine what coroutine (if any) is the next to be executed.
Definition: cosched.cpp:60