12 void*
const routine_argument,
19 m_routine_argument(routine_argument),
21 m_stackSize(stackSize),
22 m_cpuAffinity(cpuAffinity),
23 m_identifier(identifier) {
37 FW_ASSERT(state != Task::State::NOT_STARTED);
39 if (state == Task::State::STARTING) {
41 wrapper.
m_task.m_state = Task::State::RUNNING;
56 Mutex Task::s_taskMutex;
66 if ((Task::s_taskRegistry !=
nullptr) && this->m_registered) {
73 this->
suspend(Task::SuspensionType::UNINTENTIONAL);
79 state = this->m_state;
85 const taskRoutine routine,
93 Task::Arguments(name, routine, arg, priority, stackSize, cpuAffinity, static_cast<FwTaskIdType>(identifier)));
102 FW_ASSERT(&this->m_delegate == reinterpret_cast<TaskInterface*>(&this->m_handle_storage[0]));
104 this->m_name = arguments.
m_name;
105 this->m_state = State::STARTING;
107 Arguments wrapped_arguments = arguments;
112 wrapped_arguments.m_routine_argument = &this->m_wrapper;
117 this->m_priority = wrapped_arguments.m_priority;
118 Task::m_lock.unlock();
119 Task::s_taskMutex.
lock();
121 Task::s_taskMutex.
unlock();
124 if (Task::s_taskRegistry) {
125 Task::s_taskRegistry->
addTask(
this);
126 this->m_registered =
true;
133 FW_ASSERT(&this->m_delegate == reinterpret_cast<TaskInterface*>(&this->m_handle_storage[0]));
142 FW_ASSERT(&this->m_delegate == reinterpret_cast<TaskInterface*>(&this->m_handle_storage[0]));
146 status = this->m_delegate.
join();
149 this->m_state = Task::State::EXITED;
151 this->m_state = Task::State::UNKNOWN;
159 FW_ASSERT(&this->m_delegate == reinterpret_cast<TaskInterface*>(&this->m_handle_storage[0]));
160 this->m_delegate.
suspend(suspensionType);
162 this->m_state = (suspensionType == Task::SuspensionType::INTENTIONAL) ? State::SUSPENDED_INTENTIONALLY
163 : State::SUSPENDED_UNINTENTIONALLY;
168 FW_ASSERT(&this->m_delegate == reinterpret_cast<TaskInterface*>(&this->m_handle_storage[0]));
169 this->m_delegate.
resume();
173 FW_ASSERT(&this->m_delegate == reinterpret_cast<TaskInterface*>(&this->m_handle_storage[0]));
184 return this->m_priority;
188 FW_ASSERT(&this->m_delegate == reinterpret_cast<TaskInterface*>(&this->m_handle_storage[0]));
193 Task::s_taskMutex.
lock();
195 Task::s_taskMutex.
unlock();
200 FW_ASSERT(&this->m_delegate == reinterpret_cast<TaskInterface*>(&this->m_handle_storage[0]));
201 return this->m_delegate.
_delay(interval);
214 static Task s_singleton;
219 Task::s_taskRegistry = registry;
static Status delay(Fw::TimeInterval interval)
delay the current task
virtual ~TaskInterface()=default
default virtual destructor
PlatformTaskIdType FwTaskIdType
The type of task priorities used.
TaskHandle * getHandle() override
return the underlying task handle (implementation specific)
Task handle representation.
PlatformSizeType FwSizeType
virtual void resume()=0
resume a suspended task
FwTaskPriorityType getPriority()
get the task priority
static Task & getSingleton()
get a reference to singleton
virtual void addTask(Task *task)=0
add supplied task to the registry
virtual Status _delay(Fw::TimeInterval interval)=0
delay the currently scheduled task using the given architecture
State getState()
get the task's state
static void registerTaskRegistry(TaskRegistry *registry)
register a task registry to track Threads
Task()
default constructor
Status start(const Arguments &arguments) override
start the task
Status _delay(Fw::TimeInterval interval) override
delay the current task
virtual Status join()=0
block until the task has ended
~Task() final
default virtual destructor
virtual void onStart()=0
perform required task start actions
void * m_user_argument
Argument to user function.
void * m_routine_argument
virtual void removeTask(Task *task)=0
remove supplied task to the registry
void unlock()
alias for unLock to meet BasicLockable requirements
static TaskInterface * getDelegate(TaskHandleStorage &aligned_placement_new_memory)
provide a pointer to a task delegate object
bool isCooperative() override
determine if the task is cooperative multitasking (implementation specific)
virtual void suspend(SuspensionType suspensionType)=0
suspend the task given the suspension type
virtual Status start(const Arguments &arguments)=0
start the task
void suspend()
suspend the current task
Status join() override
block until the task has ended
TaskString getName()
get the task name
static FwSizeType getNumTasks()
get the current number of tasks
static void run(void *task_pointer)
run the task routine wrapper
Wrapper for task routine that ensures onStart() is called once the task actually begins.
Task & m_task
Reference to owning task.
const Os::TaskString m_name
PlatformTaskPriorityType FwTaskPriorityType
The type of task priorities used.
FwSizeType ParamType
backwards-compatible parameter type
void onStart() override
perform delegate's required task start actions
A read-only abstract superclass for StringBase.
locks a mutex within the current scope
TaskRoutineWrapper(Task &self)
void invokeRoutine()
invoke the task's routine
void resume() override
resume a suspended task
void invoke()
invoke the run method with "self" as argument
taskRoutine m_user_function
User function to run once started.
static void init()
initialize singleton
virtual TaskHandle * getHandle()=0
return the underlying task handle (implementation specific)
void(* taskRoutine)(void *ptr)
Prototype for task routine started in task context.
Arguments(const Fw::ConstStringBase &name, const taskRoutine routine, void *const routine_argument=nullptr, const FwTaskPriorityType priority=TASK_PRIORITY_DEFAULT, const FwSizeType stackSize=TASK_DEFAULT, const FwSizeType cpuAffinity=TASK_DEFAULT, const FwTaskIdType identifier=static_cast< FwTaskIdType >(TASK_DEFAULT))
construct a set of arguments to start a task
virtual bool isCooperative()
determine if the task requires cooperative multitasking
void lock()
lock the mutex and assert success