multitask support

Signed-off-by: linyu <yulin24@huawei.com>
This commit is contained in:
linyu 2023-08-08 19:53:24 +08:00
parent d609c95cbd
commit 8f7c9573c2
5 changed files with 20 additions and 15 deletions

View File

@ -29,9 +29,9 @@ typedef struct ffrt_executor_task {
void* wq[2];
} ffrt_executor_task_t;
typedef void (*ffrt_executor_task_func)(ffrt_executor_task_t* data);
typedef void (*ffrt_executor_task_func)(ffrt_executor_task_t* data, ffrt_qos_t qos);
FFRT_C_API void ffrt_executor_task_register_func(ffrt_executor_task_func func, const char* name);
FFRT_C_API void ffrt_executor_task_register_func(ffrt_executor_task_func func, ffrt_executor_task_type_t type);
FFRT_C_API void ffrt_executor_task_submit(ffrt_executor_task_t *task, const ffrt_task_attr_t *attr);
FFRT_C_API int ffrt_executor_task_cancel(ffrt_executor_task_t *task, const ffrt_qos_t qos);

View File

@ -343,10 +343,10 @@ void ffrt_executor_task_submit(ffrt_executor_task_t *task, const ffrt_task_attr_
}
API_ATTRIBUTE((visibility("default")))
void ffrt_executor_task_register_func(ffrt_executor_task_func func, const char* name)
void ffrt_executor_task_register_func(ffrt_executor_task_func func, ffrt_executor_task_type_t type)
{
ffrt::FuncManager* func_mg = ffrt::FuncManager::Instance();
func_mg->insert(std::string(name), func);
func_mg->insert(type, func);
}
API_ATTRIBUTE((visibility("default")))

View File

@ -39,17 +39,22 @@ void CPUWorker::Run(TaskCtx* task)
}
}
void CPUWorker::Run(ffrt_executor_task_t* data)
void CPUWorker::Run(ffrt_executor_task_t* task, ffrt_qos_t qos)
{
#ifdef FFRT_BBOX_ENABLE
TaskRunCounterInc();
#endif
ffrt_executor_task_func func = FuncManager::Instance()->getFunc("uv");
ffrt_executor_task_func func = nullptr;
if (task->type == ffrt_rust_task) {
func = FuncManager::Instance()->getFunc(ffrt_rust_task);
} else {
func = FuncManager::Instance()->getFunc(ffrt_uv_task);
}
if (func == nullptr) {
FFRT_LOGE("func is nullptr");
return;
}
func(data);
func(task, qos);
#ifdef FFRT_BBOX_ENABLE
TaskFinishCounterInc();
#endif
@ -83,7 +88,7 @@ void CPUWorker::Dispatch(CPUWorker* worker)
if (task->type != 0) {
ffrt_executor_task_t* work = (ffrt_executor_task_t*)task;
Run(work);
Run(work, (int)worker->GetQos());
} else {
UserSpaceLoadRecord::UpdateTaskSwitch(lastTask, task);
task->UpdateState(TaskState::RUNNING);

View File

@ -34,7 +34,7 @@ public:
private:
static void Dispatch(CPUWorker* worker);
static void Run(TaskCtx* task);
static void Run(ffrt_executor_task_t* data);
static void Run(ffrt_executor_task_t* data, ffrt_qos_t qos);
};
} // namespace ffrt
#endif

View File

@ -34,24 +34,24 @@ public:
return &func_mg;
}
void insert(std::string name, ffrt_executor_task_func func)
void insert(ffrt_executor_task_type_t type, ffrt_executor_task_func func)
{
func_map[name] = func;
func_map[type] = func;
}
ffrt_executor_task_func getFunc(std::string name)
ffrt_executor_task_func getFunc(ffrt_executor_task_type_t type)
{
if (func_map.find(name) == func_map.end()) {
if (func_map.find(type) == func_map.end()) {
return nullptr;
}
return func_map[name];
return func_map[type];
}
private:
FuncManager()
{
}
std::map<std::string, ffrt_executor_task_func> func_map;
std::unordered_map<ffrt_executor_task_type_t, ffrt_executor_task_func> func_map;
};
}
#endif /* FFRT_FUNC_MANAGER_HPP */