F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
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>
11 namespace 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 
25  FW_ASSERT(m_index < TASK_REGISTRY_CAP);
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
Definition: TaskRunner.hpp:13
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
Definition: TaskCommon.cpp:21
static void registerTaskRegistry(TaskRegistry *registry)
Definition: TaskCommon.cpp:37
POINTER_CAST getRawHandle()
Definition: TaskCommon.cpp:33
void removeTask(Task *task)
Definition: TaskRunner.cpp:30
TaskRunner()
< Nothing constructor
Definition: TaskRunner.cpp:13
void addTask(Task *task)
Definition: TaskRunner.cpp:24
Definition: File.cpp:6