mcx::container::Task
5 minute read
mcx::container::Task
Module: Container
Event loop and concurrency primitive for Motorcortex modules.
#include <ct_task.h>
Public Functions
Name | |
---|---|
Task(const char * name, parameter_server::Parameter * parent) Creates new task. |
|
virtual | ~Task() Destructor brings all the task modules to a destroy phase. |
Task() =delete Default constructor is deleted. |
|
Task(Task & orig) =delete Copy constructors are deleted. |
|
Task & | operator=(Task & orig) =delete Copy constructors are deleted. |
void | setName(const char * name) Sets the name of the task. |
const char * | getName() const Returns the name of the task. |
bool | running() const Returns true if task is running. |
void | setStackSize(uint64_t size_bytes) Sets stack size of the task bytes. |
uint64_t | getStackSize() const Returns stack size of the task im bytes. |
void | add(Module * module) Adds module to the task. |
void | add(const std::vector< Module * > & modules) Adds list of modules to the task. |
void | configure() Starts Configuration Phase of the task. |
void | start(uint64_t cycle_time_micro_s, TaskSched task_sched, const std::vector< uint32_t > & cpu_affinity_list ={}, uint32_t priority =0) Starts Operation Phase of the task. |
void | start(cmd_line::Task task) |
void | stop() Stops Operation Phase of the task. |
void | setCycleTimeMicroS(uint64_t cycle_time_micro_s) Sets a cycle time of the event-loop of the task. |
uint64_t | getCycleMicroS() const Gets cycle time of the event-loop of the task in microseconds. |
double | getCycleTimeS() const Gets cycle time of the event-loop of the task in seconds. |
uint64_t | getNrOfCycles() const Gets number of execution cycles. |
bool | setSchedPolicy(uint32_t policy) Sets task scheduler policy. |
uint32_t | getSchedPolicy() const Gets task scheduler policy. |
bool | setSchedPriority(int priority) Sets task scheduler priority. |
int | getSchedPriority() const Gets task scheduler priority. |
bool | setCpuAffinity(const std::vector< uint32_t > & cpu_affinity_list) Binds task to the list of CPUs. |
const std::vector< uint32_t > & | getCpuAffinity() const Gets list of CPUs to which task is bound. |
Public Functions Documentation
function Task
Task(
const char * name,
parameter_server::Parameter * parent
)
Creates new task.
Parameters:
- name - unique name.
- parameter_server - pointer to the root.
function ~Task
virtual ~Task()
Destructor brings all the task modules to a destroy phase.
function Task
Task() =delete
Default constructor is deleted.
function Task
Task(
Task & orig
) =delete
Copy constructors are deleted.
function operator=
Task & operator=(
Task & orig
) =delete
Copy constructors are deleted.
function setName
void setName(
const char * name
)
Sets the name of the task.
Parameters:
- name - name of the task.
function getName
const char * getName() const
Returns the name of the task.
Return: name of the task.
function running
bool running() const
Returns true if task is running.
function setStackSize
void setStackSize(
uint64_t size_bytes
)
Sets stack size of the task bytes.
Parameters:
- size_bytes - new size of the stack.
function getStackSize
uint64_t getStackSize() const
Returns stack size of the task im bytes.
Return: stack size in bytes.
function add
void add(
Module * module
)
Adds module to the task.
Parameters:
- module - pointer to the module.
function add
void add(
const std::vector< Module * > & modules
)
Adds list of modules to the task.
Parameters:
- modules - list of pointers to the modules.
function configure
void configure()
Starts Configuration Phase of the task.
function start
void start(
uint64_t cycle_time_micro_s,
TaskSched task_sched,
const std::vector< uint32_t > & cpu_affinity_list ={},
uint32_t priority =0
)
Starts Operation Phase of the task.
Parameters:
- cycle_time_micro_s - a cycle time of the event loop of the task.
- task_sched - scheduler policy of the task: REALTIME for the tasks, which require realtime and NORMAL for everything else.
- cpu_affinity_list - binding task to the list of CPUs.
- priority - tasks scheduled with NORMAL priority have static priority 0, processes scheduled under REALTIME can have a static priority in the range 1 to 99.
Par: Example Usage:
// Start control task with cycle-time 1000 microseconds,
// realtime scheduling policy on CPU 0 with priority 80.
control_task.start(1000, container::TaskSched::REALTIME , {0}, 80);
// Start publisher task with cycle-time 1000 microseconds,
// non-realtime scheduling policy on CPU 1, 2.
comm_task.start(1000, container::TaskSched::NORMAL, {1, 2});
// Start logic task with cycle-time 5000 microseconds,
// non-realtime scheduling policy on any non-isolated CPU.
logic_task.start(5000, container::TaskSched::NORMAL);
function start
void start(
cmd_line::Task task
)
function stop
void stop()
Stops Operation Phase of the task.
function setCycleTimeMicroS
void setCycleTimeMicroS(
uint64_t cycle_time_micro_s
)
Sets a cycle time of the event-loop of the task.
Parameters:
- cycle_time_micro_s - new cycle time in microseconds.
function getCycleMicroS
uint64_t getCycleMicroS() const
Gets cycle time of the event-loop of the task in microseconds.
Return: cycle time in microseconds.
function getCycleTimeS
double getCycleTimeS() const
Gets cycle time of the event-loop of the task in seconds.
Return: cycle time in seconds.
function getNrOfCycles
uint64_t getNrOfCycles() const
Gets number of execution cycles.
Return: number of execution cycles.
function setSchedPolicy
bool setSchedPolicy(
uint32_t policy
)
Sets task scheduler policy.
Parameters:
- policy - new scheduler policy: SCHED_OTHER, SCHED_FIFO etc.:
Return: true on success.
Note: For more information about Linux scheduler policies check: http://man7.org/linux/man-pages/man7/sched.7.html
function getSchedPolicy
uint32_t getSchedPolicy() const
Gets task scheduler policy.
Return: scheduler policy.
function setSchedPriority
bool setSchedPriority(
int priority
)
Sets task scheduler priority.
Return: true on success.
Tasks scheduled with SCHED_OTHER (NORMAL) have static priority 0. Processes scheduled under SCHED_FIFO or SCHED_RR (REALTIME) can have a static priority in the range 1 to 99.
function getSchedPriority
int getSchedPriority() const
Gets task scheduler priority.
Return: scheduler priority of the task.
function setCpuAffinity
bool setCpuAffinity(
const std::vector< uint32_t > & cpu_affinity_list
)
Binds task to the list of CPUs.
Parameters:
- cpu_affinity_list - list of CPUs, to which the task is bound to.
Return: true on success.
function getCpuAffinity
const std::vector< uint32_t > & getCpuAffinity() const
Gets list of CPUs to which task is bound.
Return: list of CPUs to which task is bound.
Updated on 2022-04-05 at 16:21:27 +0200