11 void *
const routine_argument,
const FwSizeType priority,
13 const PlatformUIntType identifier) :
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;
90 static_cast<PlatformUIntType>(identifier)));
95 FW_ASSERT(&this->m_delegate == reinterpret_cast<TaskInterface*>(&this->m_handle_storage[0]));
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;
126 FW_ASSERT(&this->m_delegate == reinterpret_cast<TaskInterface*>(&this->m_handle_storage[0]));
135 FW_ASSERT(&this->m_delegate == reinterpret_cast<TaskInterface*>(&this->m_handle_storage[0]));
139 status = this->m_delegate.
join();
142 this->m_state = Task::State::EXITED;
144 this->m_state = Task::State::UNKNOWN;
152 FW_ASSERT(&this->m_delegate == reinterpret_cast<TaskInterface*>(&this->m_handle_storage[0]));
153 this->m_delegate.
suspend(suspensionType);
155 this->m_state = (suspensionType == Task::SuspensionType::INTENTIONAL) ? State::SUSPENDED_INTENTIONALLY : State::SUSPENDED_UNINTENTIONALLY;
160 FW_ASSERT(&this->m_delegate == reinterpret_cast<TaskInterface*>(&this->m_handle_storage[0]));
161 this->m_delegate.
resume();
165 FW_ASSERT(&this->m_delegate == reinterpret_cast<TaskInterface*>(&this->m_handle_storage[0]));
171 return this->m_priority;
175 FW_ASSERT(&this->m_delegate == reinterpret_cast<TaskInterface*>(&this->m_handle_storage[0]));
180 Task::s_taskMutex.
lock();
182 Task::s_taskMutex.
unlock();
187 FW_ASSERT(&this->m_delegate == reinterpret_cast<TaskInterface*>(&this->m_handle_storage[0]));
188 return this->m_delegate.
_delay(interval);
201 static Task s_singleton;
206 Task::s_taskRegistry = registry;
static Status delay(Fw::TimeInterval interval)
delay the current task
virtual ~TaskInterface()=default
default virtual destructor
TaskHandle * getHandle() override
return the underlying task handle (implementation specific)
Task handle representation.
PlatformSizeType FwSizeType
virtual void resume()=0
resume a suspended task
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
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
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)
FwSizeType getPriority()
get the task priority
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
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
FwSizeType ParamType
backwards-compatible parameter type
void onStart() override
perform delegate's required task start actions
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.
virtual bool isCooperative()
determine if the task requires cooperative multitasking
void lock()
lock the mutex and assert success