Motorcortex Core  version: 2.7.6
mcx::container::Task Class Reference

Event loop and concurrency primitive for Motorcortex modules. More...

#include <ct_task.h>

Public Member Functions

 Task (const char *name, parameter_server::Parameter *parent)
 Creates new task. More...
 
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.
 
Taskoperator= (Task &orig)=delete
 Copy constructors are deleted.
 
void setName (const char *name)
 Sets the name of the task. More...
 
const char * getName () const
 Returns the name of the task. More...
 
bool running () const
 Returns true if task is running.
 
void setStackSize (uint64_t size_bytes)
 Sets stack size of the task bytes. More...
 
uint64_t getStackSize () const
 Returns stack size of the task im bytes. More...
 
void add (Module *module)
 Adds module to the task. More...
 
void add (const std::vector< Module * > &modules)
 Adds list of modules to the task. More...
 
void configure ()
 Starts Configuration Phase of the task. More...
 
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. More...
 
void start (cmd_line::Task)
 
void stop ()
 Stops Operation Phase of the task. More...
 
void setCycleTimeMicroS (uint64_t cycle_time_micro_s)
 Sets a cycle time of the event-loop of the task. More...
 
uint64_t getCycleMicroS () const
 Gets cycle time of the event-loop of the task in microseconds. More...
 
double getCycleTimeS () const
 Gets cycle time of the event-loop of the task in seconds. More...
 
uint64_t getNrOfCycles () const
 Gets number of execution cycles. More...
 
bool setSchedPolicy (uint32_t policy)
 Sets task scheduler policy. More...
 
uint32_t getSchedPolicy () const
 Gets task scheduler policy. More...
 
bool setSchedPriority (int priority)
 Sets task scheduler priority. More...
 
int getSchedPriority () const
 Gets task scheduler priority. More...
 
bool setCpuAffinity (const std::vector< uint32_t > &cpu_affinity_list)
 Binds task to the list of CPUs. More...
 
const std::vector< uint32_t > & getCpuAffinity () const
 Gets list of CPUs to which task is bound. More...
 

Detailed Description

Event loop and concurrency primitive for Motorcortex modules.

Constructor & Destructor Documentation

◆ Task()

mcx::container::Task::Task ( const char *  name,
parameter_server::Parameter parent 
)

Creates new task.

Parameters
name- unique name.
parameter_server- pointer to the root.

Member Function Documentation

◆ add() [1/2]

void mcx::container::Task::add ( const std::vector< Module * > &  modules)

Adds list of modules to the task.

Parameters
modules- list of pointers to the modules.

◆ add() [2/2]

void mcx::container::Task::add ( Module module)

Adds module to the task.

Parameters
module- pointer to the module.

◆ configure()

void mcx::container::Task::configure ( )

Starts Configuration Phase of the task.

◆ getCpuAffinity()

const std::vector< uint32_t > & mcx::container::Task::getCpuAffinity ( ) const

Gets list of CPUs to which task is bound.

Returns
list of CPUs to which task is bound.

◆ getCycleMicroS()

uint64_t mcx::container::Task::getCycleMicroS ( ) const

Gets cycle time of the event-loop of the task in microseconds.

Returns
cycle time in microseconds.

◆ getCycleTimeS()

double mcx::container::Task::getCycleTimeS ( ) const

Gets cycle time of the event-loop of the task in seconds.

Returns
cycle time in seconds.

◆ getName()

const char * mcx::container::Task::getName ( ) const

Returns the name of the task.

Returns
name of the task.

◆ getNrOfCycles()

uint64_t mcx::container::Task::getNrOfCycles ( ) const

Gets number of execution cycles.

Returns
number of execution cycles.

◆ getSchedPolicy()

uint32_t mcx::container::Task::getSchedPolicy ( ) const

Gets task scheduler policy.

Returns
scheduler policy.

◆ getSchedPriority()

int mcx::container::Task::getSchedPriority ( ) const

Gets task scheduler priority.

Returns
scheduler priority of the task.

◆ getStackSize()

uint64_t mcx::container::Task::getStackSize ( ) const

Returns stack size of the task im bytes.

Returns
stack size in bytes.

◆ setCpuAffinity()

bool mcx::container::Task::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.
Returns
true on success.

◆ setCycleTimeMicroS()

void mcx::container::Task::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.

◆ setName()

void mcx::container::Task::setName ( const char *  name)

Sets the name of the task.

Parameters
name- name of the task.

◆ setSchedPolicy()

bool mcx::container::Task::setSchedPolicy ( uint32_t  policy)

Sets task scheduler policy.

Parameters
policy- new scheduler policy: SCHED_OTHER, SCHED_FIFO etc.:
Returns
true on success.
Note
For more information about Linux scheduler policies check: http://man7.org/linux/man-pages/man7/sched.7.html

◆ setSchedPriority()

bool mcx::container::Task::setSchedPriority ( int  priority)

Sets task scheduler priority.

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.

Returns
true on success.

◆ setStackSize()

void mcx::container::Task::setStackSize ( uint64_t  size_bytes)

Sets stack size of the task bytes.

Parameters
size_bytes- new size of the stack.

◆ start()

void mcx::container::Task::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.
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);

◆ stop()

void mcx::container::Task::stop ( )

Stops Operation Phase of the task.


The documentation for this class was generated from the following files: