F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
Os::Task Class Referencefinal

#include <Os/Task.hpp>

Inheritance diagram for Os::Task:
Os::TaskInterface

Classes

class  TaskRoutineWrapper
 Wrapper for task routine that ensures onStart() is called once the task actually begins. More...
 

Public Types

typedef FwSizeType ParamType
 backwards-compatible parameter type More...
 
- Public Types inherited from Os::TaskInterface
enum  Status {
  OP_OK , INVALID_HANDLE , INVALID_PARAMS , INVALID_STACK ,
  UNKNOWN_ERROR , INVALID_AFFINITY , DELAY_ERROR , JOIN_ERROR ,
  ERROR_RESOURCES , ERROR_PERMISSION , INVALID_STATE
}
 
enum  SuspensionType { INTENTIONAL , UNINTENTIONAL }
 
enum  State {
  NOT_STARTED , RUNNING , SUSPENDED_INTENTIONALLY , SUSPENDED_UNINTENTIONALLY ,
  EXITED , UNKNOWN
}
 
typedef void(* taskRoutine) (void *ptr)
 Prototype for task routine started in task context. More...
 

Public Member Functions

 Task ()
 default constructor More...
 
 ~Task () final
 default virtual destructor More...
 
 Task (const Task &other)=delete
 copy constructor is forbidden More...
 
Taskoperator= (const Task &other)=delete
 assignment operator is forbidden More...
 
void suspend ()
 suspend the current task More...
 
State getState ()
 get the task's state More...
 
 DEPRECATED (Status start(const Fw::StringBase &name, const taskRoutine routine, void *const arg=nullptr, const ParamType priority=TASK_DEFAULT, const ParamType stackSize=TASK_DEFAULT, const ParamType cpuAffinity=TASK_DEFAULT, const ParamType identifier=TASK_DEFAULT), "Switch to Task::start(Arguments&)")
 start this task More...
 
Status start (const Arguments &arguments) override
 start the task More...
 
void onStart () override
 perform delegate's required task start actions More...
 
void invokeRoutine ()
 invoke the task's routine More...
 
 DEPRECATED (Status join(void **value_ptr), "Please switch to argument free join.")
 join calling thread to this thread More...
 
Status join () override
 block until the task has ended More...
 
void suspend (SuspensionType suspensionType) override
 suspend the task given the suspension type More...
 
void resume () override
 resume a suspended task More...
 
bool isCooperative () override
 determine if the task is cooperative multitasking (implementation specific) More...
 
TaskHandlegetHandle () override
 return the underlying task handle (implementation specific) More...
 
- Public Member Functions inherited from Os::TaskInterface
 TaskInterface ()=default
 default constructor More...
 
virtual ~TaskInterface ()=default
 default virtual destructor More...
 
 TaskInterface (const TaskInterface &other)=delete
 copy constructor is forbidden More...
 
TaskInterfaceoperator= (const TaskInterface &other)=delete
 assignment operator is forbidden More...
 

Static Public Member Functions

static FwSizeType getNumTasks ()
 get the current number of tasks More...
 
static void registerTaskRegistry (TaskRegistry *registry)
 register a task registry to track Threads More...
 
- Static Public Member Functions inherited from Os::TaskInterface
static Status delay (Fw::Time interval)
 delay the current task More...
 
static TaskInterfacegetDelegate (HandleStorage &aligned_placement_new_memory)
 provide a pointer to a task delegate object More...
 

Additional Inherited Members

- Static Public Attributes inherited from Os::TaskInterface
static constexpr FwSizeType TASK_DEFAULT = std::numeric_limits<FwSizeType>::max()
 

Detailed Description

Task class intended to be used by the rest of the fprime system. This is final as it is not intended to be a parent class. Instead it wraps a delegate provided by TaskInterface::getDelegate() to provide system specific behaviour.

Definition at line 195 of file Task.hpp.

Member Typedef Documentation

◆ ParamType

backwards-compatible parameter type

Definition at line 218 of file Task.hpp.

Constructor & Destructor Documentation

◆ Task() [1/2]

Os::Task::Task ( )

default constructor

Definition at line 60 of file Task.cpp.

◆ ~Task()

Os::Task::~Task ( )
final

default virtual destructor

Definition at line 62 of file Task.cpp.

◆ Task() [2/2]

Os::Task::Task ( const Task other)
delete

copy constructor is forbidden

Member Function Documentation

◆ DEPRECATED() [1/2]

Os::Task::DEPRECATED ( Status   joinvoid **value_ptr,
"Please switch to argument free join."   
)

join calling thread to this thread

Note: this function is deprecated as the value_ptr object is not used anyway and should always be set to nullptr.

Parameters
value_ptrmust be set to nullptr
Returns
status of the join

◆ DEPRECATED() [2/2]

Os::Task::DEPRECATED ( Status   startconst Fw::StringBase &name, const taskRoutine routine, void *const arg=nullptr, const ParamType priority=TASK_DEFAULT, const ParamType stackSize=TASK_DEFAULT, const ParamType cpuAffinity=TASK_DEFAULT, const ParamType identifier=TASK_DEFAULT,
"Switch to Task::start(Arguments&)"   
)

start this task

Start this task with supplied name, task routine (run function), priority, stack, affinity, and task identifier. These arguments are supplied into an Arguments class and that version of the function is called. It is illegal to supply a nullptr as routine.

Parameters
namename of the task to start
routineuser routine to run
arg(optional) user argument to supply to task routine
priority(optional) priority of this task
stackSize(optional) stack size of this task
cpuAffinity(optional) affinity of this task. Use Task::start(Arguments&) to supply affinity set.
identifier(optional) identifier of this task
Returns
: status of the start call

◆ getHandle()

TaskHandle * Os::Task::getHandle ( )
overridevirtual

return the underlying task handle (implementation specific)

Returns
internal task handle representation

Implements Os::TaskInterface.

Definition at line 165 of file Task.cpp.

◆ getNumTasks()

FwSizeType Os::Task::getNumTasks ( )
static

get the current number of tasks

Returns
current number of tasks

Definition at line 170 of file Task.cpp.

◆ getState()

Task::State Os::Task::getState ( )

get the task's state

Returns the task state: not started, running, suspended (intentionally), suspended (unintentionally), and exited.

Returns
task state

Definition at line 74 of file Task.cpp.

◆ invokeRoutine()

void Os::Task::invokeRoutine ( )

invoke the task's routine

This will invoke the task's routine passing this as the argument to that call. This is used as a helper when running this task (e.g. repetitive cooperative calls).

Definition at line 126 of file Task.cpp.

◆ isCooperative()

bool Os::Task::isCooperative ( )
overridevirtual

determine if the task is cooperative multitasking (implementation specific)

Returns
true if cooperative, false otherwise

Reimplemented from Os::TaskInterface.

Definition at line 160 of file Task.cpp.

◆ join()

Task::Status Os::Task::join ( )
overridevirtual

block until the task has ended

Blocks the current (calling) task until this task execution has ended. Callers should ensure that any signals required to stop this task have already been emitted or will be emitted by another task.

Returns
status of the block Wait for task to finish

Implements Os::TaskInterface.

Definition at line 130 of file Task.cpp.

◆ onStart()

void Os::Task::onStart ( )
overridevirtual

perform delegate's required task start actions

Implements Os::TaskInterface.

Definition at line 121 of file Task.cpp.

◆ operator=()

Task& Os::Task::operator= ( const Task other)
delete

assignment operator is forbidden

◆ registerTaskRegistry()

void Os::Task::registerTaskRegistry ( TaskRegistry registry)
static

register a task registry to track Threads

Definition at line 177 of file Task.cpp.

◆ resume()

void Os::Task::resume ( )
overridevirtual

resume a suspended task

Resumes this task. Not started, running, and exited tasks take no action.

Implements Os::TaskInterface.

Definition at line 155 of file Task.cpp.

◆ start()

Task::Status Os::Task::start ( const Arguments arguments)
overridevirtual

start the task

Starts the task given the supplied arguments. This is done via the a task routine wrapper intermediary that ensures that setStarted is called once the task has actually started to run. The task then runs the user routine. This function may return before the new task begins to run. It is illegal for arguments.m_routine to be null.

Parameters
argumentsarguments supplied to the task start call
Returns
status of the task start

Implements Os::TaskInterface.

Definition at line 82 of file Task.cpp.

◆ suspend() [1/2]

void Os::Task::suspend ( )

suspend the current task

Suspend the current task unintentionally. If the user needs to indicate that the task was suspended intentionally then a call to suspend(SuspensionType::INTENTIONAL) should be used.

Definition at line 70 of file Task.cpp.

◆ suspend() [2/2]

void Os::Task::suspend ( Task::SuspensionType  suspensionType)
overridevirtual

suspend the task given the suspension type

Suspends the task. Some implementations track if the suspension of a task was intentional or unintentional. The supplied suspensionType parameter indicates that this was intentional or unintentional. The type of suspension is also returned when calling isSuspended.

Parameters
suspensionTypeintentionality of the suspension

Implements Os::TaskInterface.

Definition at line 147 of file Task.cpp.


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