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)
35 FW_ASSERT(state != Task::State::NOT_STARTED);
37 if (state == Task::State::STARTING) {
39 wrapper.
m_task.m_state = Task::State::RUNNING;
54 Mutex Task::s_taskMutex;
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;
98 this->m_state = State::STARTING;
100 Arguments wrapped_arguments = arguments;
105 wrapped_arguments.m_routine_argument = &this->m_wrapper;
110 this->m_priority = wrapped_arguments.m_priority;
111 Task::m_lock.unlock();
112 Task::s_taskMutex.
lock();
114 Task::s_taskMutex.
unlock();
117 if (Task::s_taskRegistry) {
118 Task::s_taskRegistry->
addTask(
this);
119 this->m_registered =
true;
139 status = this->m_delegate.
join();
142 this->m_state = Task::State::EXITED;
144 this->m_state = Task::State::UNKNOWN;
153 this->m_delegate.
suspend(suspensionType);
155 this->m_state = (suspensionType == Task::SuspensionType::INTENTIONAL) ? State::SUSPENDED_INTENTIONALLY : State::SUSPENDED_UNINTENTIONALLY;
161 this->m_delegate.
resume();
171 return this->m_priority;
180 Task::s_taskMutex.
lock();
182 Task::s_taskMutex.
unlock();
188 return this->m_delegate.
_delay(interval);
201 static Task s_singleton;
206 Task::s_taskRegistry = registry;
unsigned int PlatformUIntType
PlatformSizeType FwSizeType
void unlock()
alias for unLock to meet BasicLockable requirements
void lock()
lock the mutex and assert success
locks a mutex within the current scope
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)
static Status delay(Fw::TimeInterval interval)
delay the current task
Task()
default constructor
TaskHandle * getHandle() override
return the underlying task handle (implementation specific)
State getState()
get the task's state
FwSizeType getPriority()
get the task priority
FwSizeType ParamType
backwards-compatible parameter type
static Task & getSingleton()
get a reference to singleton
static void init()
initialize singleton
void resume() override
resume a suspended task
void onStart() override
perform delegate's required task start actions
Status _delay(Fw::TimeInterval interval) override
delay the current task
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)
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 Status _delay(Fw::TimeInterval interval)=0
delay the currently scheduled task using the given architecture
static TaskInterface * getDelegate(TaskHandleStorage &aligned_placement_new_memory)
provide a pointer to a task delegate object
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 succeeded.