11 void *
const routine_argument,
const FwSizeType priority,
16 m_routine_argument(routine_argument),
18 m_stackSize(stackSize),
19 m_cpuAffinity(cpuAffinity),
20 m_identifier(identifier)
37 if (state == Task::State::NOT_STARTED) {
39 wrapper.
m_task.m_state = Task::State::RUNNING;
64 if ((Task::s_taskRegistry !=
nullptr) && this->m_registered) {
71 this->
suspend(Task::SuspensionType::UNINTENTIONAL);
77 state = this->m_state;
97 this->m_name = arguments.
m_name;
99 Arguments wrapped_arguments = arguments;
104 wrapped_arguments.m_routine_argument = &this->m_wrapper;
108 Task::s_taskMutex.
lock();
110 Task::s_taskMutex.
unlock();
113 if (Task::s_taskRegistry) {
114 Task::s_taskRegistry->
addTask(
this);
115 this->m_registered =
true;
135 status = this->m_delegate.
join();
138 this->m_state = Task::State::EXITED;
140 this->m_state = Task::State::UNKNOWN;
149 this->m_delegate.
suspend(suspensionType);
151 this->m_state = (suspensionType == Task::SuspensionType::INTENTIONAL) ? State::SUSPENDED_INTENTIONALLY : State::SUSPENDED_UNINTENTIONALLY;
157 this->m_delegate.
resume();
171 Task::s_taskMutex.
lock();
173 Task::s_taskMutex.
unlock();
178 Task::s_taskRegistry = registry;
unsigned int PlatformUIntType
PlatformSizeType FwSizeType
void unlock()
alias for unLock to meet BasicLockable requirements
void lock()
lock the mutex
Wrapper for task routine that ensures onStart() is called once the task actually begins.
void invoke()
invoke the run method with "self" as argument
static void run(void *task_pointer)
run the task routine wrapper
void * m_user_argument
Argument to user function.
TaskRoutineWrapper(Task &self)
Task & m_task
Reference to owning task.
taskRoutine m_user_function
User function to run once started.
Task handle representation.
static FwSizeType getNumTasks()
get the current number of tasks
bool isCooperative() override
determine if the task is cooperative multitasking (implementation specific)
Task()
default constructor
TaskHandle * getHandle() override
return the underlying task handle (implementation specific)
State getState()
get the task's state
FwSizeType ParamType
backwards-compatible parameter type
void resume() override
resume a suspended task
void onStart() override
perform delegate's required task start actions
void invokeRoutine()
invoke the task's routine
void suspend()
suspend the current task
static void registerTaskRegistry(TaskRegistry *registry)
register a task registry to track Threads
Status start(const Arguments &arguments) override
start the task
~Task() final
default virtual destructor
Status join() override
block until the task has ended
Arguments(const Fw::StringBase &name, const taskRoutine routine, void *const routine_argument=nullptr, const FwSizeType priority=TASK_DEFAULT, const FwSizeType stackSize=TASK_DEFAULT, const FwSizeType cpuAffinity=TASK_DEFAULT, const PlatformUIntType identifier=static_cast< PlatformUIntType >(TASK_DEFAULT))
construct a set of arguments to start a task
void * m_routine_argument
const Os::TaskString m_name
virtual TaskHandle * getHandle()=0
return the underlying task handle (implementation specific)
static TaskInterface * getDelegate(HandleStorage &aligned_placement_new_memory)
provide a pointer to a task delegate object
virtual Status start(const Arguments &arguments)=0
start the task
virtual void suspend(SuspensionType suspensionType)=0
suspend the task given the suspension type
virtual Status join()=0
block until the task has ended
virtual void resume()=0
resume a suspended task
virtual ~TaskInterface()=default
default virtual destructor
void(* taskRoutine)(void *ptr)
Prototype for task routine started in task context.
virtual void onStart()=0
perform required task start actions
virtual bool isCooperative()
determine if the task requires cooperative multitasking
virtual void addTask(Task *task)=0
add supplied task to the registry
virtual void removeTask(Task *task)=0
remove supplied task to the registry
@ OP_OK
Operation was successful.