31 lines
664 B
C++
31 lines
664 B
C++
/// © MiroZ 2024
|
|
|
|
#include "TaskFactory.h"
|
|
|
|
TaskFactory::TaskFactory()
|
|
{
|
|
m_xMutex = xSemaphoreCreateMutex();
|
|
assert(m_xMutex);
|
|
}
|
|
|
|
TaskFactory::~TaskFactory()
|
|
{
|
|
if(m_xMutex != NULL)
|
|
vSemaphoreDelete(m_xMutex);
|
|
}
|
|
|
|
TaskHandle_t TaskFactory::createTask(TASK_FUNCTION task_function, const char *name, uint32_t stack_size, UBaseType_t priority, BaseType_t core)
|
|
{
|
|
TaskHandle_t task_handle = nullptr;
|
|
|
|
if (xSemaphoreTake(m_xMutex, portMAX_DELAY))
|
|
{
|
|
m_task_function = task_function;
|
|
xTaskCreatePinnedToCore(taskStarter, name, stack_size, this, priority, &task_handle, core);
|
|
xSemaphoreGive(m_xMutex);
|
|
}
|
|
|
|
return task_handle;
|
|
}
|
|
|
|
TaskFactory TASK_FACTORY; |