From bf44ec65c73263b77e2076c78de9495782efc211 Mon Sep 17 00:00:00 2001 From: shilei Date: Thu, 18 Apr 2024 07:03:49 +0000 Subject: [PATCH] add interface of napi_call_threadsafe_function_with_priority Signed-off-by: shilei Change-Id: Id626368f3108854730ebc2da355105eec214f665 --- arkui/napi/common.h | 24 ++++++++++++++++++++++++ arkui/napi/libnapi.ndk.json | 4 ++++ arkui/napi/native_api.h | 17 +++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/arkui/napi/common.h b/arkui/napi/common.h index 031e2c327..e5e5c8d5e 100644 --- a/arkui/napi/common.h +++ b/arkui/napi/common.h @@ -43,4 +43,28 @@ typedef enum { napi_event_mode_nowait = 1, } napi_event_mode; +/** + * @brief Indicates the priority of a task dispatched from native thread to ArkTS thread. + * + * @since 12 + */ +typedef enum { + /** + * The immediate priority tasks should be promptly processed whenever feasible. + */ + napi_priority_immediate = 0, + /** + * The high priority tasks, as sorted by their handle time, should be prioritized over tasks with low priority. + */ + napi_priority_high = 1, + /** + * The low priority tasks, as sorted by their handle time, should be processed before idle priority tasks. + */ + napi_priority_low = 2, + /** + * The idle priority tasks should be processed immediately only if there are no other priority tasks. + */ + napi_priority_idle = 3, +} napi_task_priority; + #endif /* FOUNDATION_ACE_NAPI_INTERFACES_KITS_NAPI_NATIVE_API_H */ \ No newline at end of file diff --git a/arkui/napi/libnapi.ndk.json b/arkui/napi/libnapi.ndk.json index 2770ec27b..af9814611 100644 --- a/arkui/napi/libnapi.ndk.json +++ b/arkui/napi/libnapi.ndk.json @@ -194,5 +194,9 @@ { "first_introduced": "12", "name": "napi_delete_serialization_data" + }, + { + "first_introduced": "12", + "name": "napi_call_threadsafe_function_with_priority" } ] diff --git a/arkui/napi/native_api.h b/arkui/napi/native_api.h index fd52d439b..6e8558d38 100644 --- a/arkui/napi/native_api.h +++ b/arkui/napi/native_api.h @@ -256,6 +256,23 @@ NAPI_EXTERN napi_status napi_deserialize(napi_env env, void* buffer, napi_value* */ NAPI_EXTERN napi_status napi_delete_serialization_data(napi_env env, void* buffer); +/** + * @brief Dispatch a task with specified priority from a native thread to an ArkTS thread, the task will execute + * the given thread safe function. + * + * @param func Indicates the thread safe function. + * @param data Indicates the data anticipated to be transferred to the ArkTS thread. + * @param priority Indicates the priority of the task dispatched. + * @param isTail Indicates the way of the task dispatched into the native event queue. When "isTail" is true, + * the task will be dispatched to the tail of the native event queue. Conversely, when "isTail" is false, the + * tasks will be dispatched to the head of the native event queue. + * @return Return the function execution status. + * @since 12 + */ +NAPI_EXTERN napi_status napi_call_threadsafe_function_with_priority(napi_threadsafe_function func, + void *data, + napi_task_priority priority, + bool isTail); #ifdef __cplusplus } #endif -- Gitee