diff --git a/arkui/napi/common.h b/arkui/napi/common.h index 031e2c3278df862108fabc2797efd78b02b1e4cb..e5e5c8d5e219b6dd8929c702c469186742d31c7d 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 2770ec27b3ddd77a05f13f9bee18a30c92a1a75a..af981461106401d1d5c133eab1c190453fbd64bb 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 fd52d439bd18fd8790cc11652f45f4dc2c483a4c..6e8558d38f28ee30e3757df79ac80746f91c7d4d 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