!50 多类型任务兼容

Merge pull request !50 from 太帅太烦恼/master
This commit is contained in:
openharmony_ci 2023-07-29 06:15:00 +00:00 committed by Gitee
commit 821615d9ba
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 28 additions and 14 deletions

View File

@ -60,7 +60,7 @@ FFRT_C_API void ffrt_wake_coroutine(void *task);
FFRT_C_API void ffrt_task_handle_destroy(ffrt_task_handle_t handle);
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

@ -55,6 +55,12 @@ typedef enum {
} ffrt_qos_default_t;
typedef int ffrt_qos_t;
typedef enum {
ffrt_normal_task = 0,
ffrt_rust_task = 1,
ffrt_uv_task // only used to register func for libuv
} ffrt_executor_task_type_t;
typedef enum {
ffrt_stack_protect_weak,
ffrt_stack_protect_strong
@ -170,7 +176,7 @@ 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);
#ifdef __cplusplus
namespace ffrt {

View File

@ -454,10 +454,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

@ -47,17 +47,22 @@ void CPUWorker::Run(TaskCtx* task)
#endif
}
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
@ -91,7 +96,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

@ -33,7 +33,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,21 +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)
{
return func_map[name];
if (func_map.find(type) == func_map.end()) {
return nullptr;
}
return func_map[type];
}
private:
FuncManager()
{
}
std::map<std::string, ffrt_executor_task_func> func_map;
std::map<ffrt_executor_task_type_t, ffrt_executor_task_func> func_map;
};
}
#endif /* FFRT_FUNC_MANAGER_HPP */