/// © MiroZ 2024 #include "TaskFactory.h" TaskFactory::TaskFactory() { #ifdef USE_MUTEX m_xMutex = xSemaphoreCreateMutex(); assert(m_xMutex); #endif } TaskFactory::~TaskFactory() { #ifdef USE_MUTEX if(m_xMutex != NULL) vSemaphoreDelete(m_xMutex); #endif } 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; #ifdef USE_MUTEX if (xSemaphoreTake(m_xMutex, portMAX_DELAY)) { #endif m_task_function = task_function; xTaskCreatePinnedToCore(taskStarter, name, stack_size, this, priority, &task_handle, core); #ifdef USE_MUTEX xSemaphoreGive(m_xMutex); } #endif return task_handle; } TaskFactory TASK_FACTORY;