Mark3 Realtime Kernel
coroutine.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 =========================================================================== */
19 #pragma once
20 
21 #include "mark3cfg.h"
22 #include "ll.h"
23 #include "priomapl1.h"
24 #include "priomapl2.h"
25 
26 namespace Mark3 {
27 
28 // Priority map type declaration, based on port configuration
29 #if PORT_COROUTINE_PRIORITIES <= (PORT_PRIO_MAP_WORD_SIZE * 8u)
31 #else
33 #endif
34 
35 // Forward declarations
36 class CoList;
37 class Coroutine;
38 
39 // CoRoutine functino handler type definition
40 using CoroutineHandler = void (*)(Coroutine* pclCaller_, void* pvContext_);
41 
53 class Coroutine : public TypedLinkListNode<Coroutine>
54 {
55 public:
56  void* operator new(size_t sz, void* pv) { return reinterpret_cast<Coroutine*>(pv); }
57  ~Coroutine();
58 
70  void Init(PORT_PRIO_TYPE uPriority_, CoroutineHandler pfHandler_, void* pvContext_);
71 
77  void Run();
78 
84  void Activate();
85 
93  void SetPriority(PORT_PRIO_TYPE uPriority_);
94 
102 
103 private:
106  void* m_pvContext;
108  bool m_bQueued;
109 };
110 } // namespace Mark3
The CoList class The CoList class implements a circular-linked-listed structure for coroutine objects...
Definition: colist.h:35
void * m_pvContext
Definition: coroutine.h:106
CoList * m_pclOwner
Definition: coroutine.h:104
CoroutineHandler m_pfHandler
Definition: coroutine.h:105
PORT_PRIO_TYPE m_uPriority
Definition: coroutine.h:107
#define PORT_PRIO_TYPE
Type used for bitmap in the PriorityMap class.
Definition: portcfg.h:73
void Activate()
Activate Tag the co-routine as pending execution. Has no effect if the co-routine is already pending ...
Definition: coroutine.cpp:67
Definition: atomic.cpp:23
Mark3 Kernel Configuration This file is used to configure the kernel for your specific application in...
2-Level priority allocator template-class used for scheduler implementation
The PriorityMapL2 class This class implements a priority bitmap data structure. Each bit in the objec...
Definition: priomapl2.h:50
void SetPriority(PORT_PRIO_TYPE uPriority_)
SetPriority Update the scheduling priority of the co-routine. Can be called from within the co-routin...
Definition: coroutine.cpp:82
void(*)(Coroutine *pclCaller_, void *pvContext_) CoroutineHandler
Definition: coroutine.h:40
PORT_PRIO_TYPE GetPriority()
GetPriority Retrieve the current scheduling priority of the co-routine.
Definition: coroutine.cpp:97
The Coroutine class implements a lightweight, run-to-completion task that forms the basis for co-oper...
Definition: coroutine.h:53
The PriorityMapL1 class This class implements a priority bitmap data structure. Each bit in the objec...
Definition: priomapl1.h:45
void Run()
Run Clear the co-routine&#39;s pending execution flag, and execute the coroutine&#39;s handler function...
Definition: coroutine.cpp:53
1-Level bitmap allocator template-class used for scheduler implementation
void Init(PORT_PRIO_TYPE uPriority_, CoroutineHandler pfHandler_, void *pvContext_)
Init Initialize the coroutine object prior to use. Must be called before using the other methods in t...
Definition: coroutine.cpp:39
Core linked-list declarations, used by all kernel list types At the heart of RTOS data structures are...