F´ Flight Software - C/C++ Documentation devel
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TaskRunner.cpp
Go to the documentation of this file.
1/*
2 * TaskRunner.cpp
3 *
4 * Created on: Feb 28, 2019
5 * Author: lestarch
6 */
7#include <Fw/Types/Assert.hpp>
8#include <FpConfig.hpp>
11namespace Os {
12
14 m_index(0),
15 m_cont(true)
16{
17 for (U32 i = 0; i < TASK_REGISTRY_CAP; i++) {
18 this->m_task_table[i] = 0;
19 }
21}
23
26 this->m_task_table[m_index] = task;
27 m_index++;
28}
29
31 bool found = false;
32 //Squash that existing task
33 for (U32 i = 0; i < TASK_REGISTRY_CAP; i++) {
34 found = found | (task == this->m_task_table[i]);
35 //If not found, keep looking
36 if (!found) {
37 continue;
38 }
39 //If we are less than the end of the array, shift variables over
40 else if (i < TASK_REGISTRY_CAP - 1) {
41 this->m_task_table[i] = this->m_task_table[i+1];
42 }
43 //If the last element, mark NULL
44 else {
45 this->m_task_table[i] = nullptr;
46 }
47 }
48}
49
51 m_cont = false;
52}
53
55 U32 i = 0;
56 if (!m_cont) {
57 return;
58 }
59 //Loop through full table
60 for (i = 0; i < TASK_REGISTRY_CAP; i++) {
61 //Break at end of table
62 if (m_task_table[i] == nullptr) {
63 break;
64 }
65 //Get bare task or break
66 BareTaskHandle* handle = reinterpret_cast<BareTaskHandle*>(m_task_table[i]->getRawHandle());
67 if (handle == nullptr || handle->m_routine == nullptr || !handle->m_enabled) {
68 continue;
69 }
70 //Run-it!
71 handle->m_routine(handle->m_argument);
72 //Disable tasks that have "exited" or stopped
73 handle->m_enabled = m_task_table[i]->isStarted();
74 }
75 //Check if no tasks, and stop
76 if (i == 0) {
77 m_cont = false;
78 }
79}
80}
#define FW_ASSERT(...)
Definition Assert.hpp:14
C++-compatible configuration header for fprime configuration.
#define TASK_REGISTRY_CAP
bool m_enabled
Save the priority.
Task::taskRoutine m_routine
Argument input pointer.
forward declaration
Definition Task.hpp:15
bool isStarted()
check to see if task is started
static void registerTaskRegistry(TaskRegistry *registry)
POINTER_CAST getRawHandle()
void removeTask(Task *task)
TaskRunner()
< Nothing constructor
void addTask(Task *task)
Definition File.cpp:6