From 56eedb97e3739e6a468382d68e4e7553697629b2 Mon Sep 17 00:00:00 2001 From: liaoxingbin Date: Mon, 28 Apr 2025 10:44:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9uv=5Fqos=5Fuser=5Finteractive?= =?UTF-8?q?=E4=BC=98=E5=85=88=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liaoxingbin --- include/uv.h | 3 ++- src/threadpool.c | 14 +++++++++++--- src/unix/loop.c | 1 + src/uv-common.h | 6 +++++- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/include/uv.h b/include/uv.h index 0d39684..5546298 100644 --- a/include/uv.h +++ b/include/uv.h @@ -1187,7 +1187,8 @@ typedef enum { uv_qos_utility = 1, uv_qos_default = 2, uv_qos_user_initiated = 3, - uv_qos_user_interactive = 4, + uv_qos_reserved = 4, /* Do not use this qos, reserved for now. */ + uv_qos_user_interactive = 5, } uv_qos_t; UV_EXTERN int uv_queue_work_with_qos(uv_loop_t* loop, diff --git a/src/threadpool.c b/src/threadpool.c index ee86f7b..4d1675e 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -693,7 +693,11 @@ void uv__work_done(uv_async_t* handle) { uv__loop_internal_fields_t* lfields = uv__get_internal_fields(loop); int i; uv__queue_init(&wq); - for (i = 4; i >= 0; i--) { + for (i = uv_qos_user_interactive; i >= 0; i--) { + // No task in 4-th lfields->wq_sub queue. + if (i == uv_qos_reserved) { + continue; + } if (!uv__queue_empty(&lfields->wq_sub[i])) { uv__queue_append(&lfields->wq_sub[i], &wq); } @@ -940,8 +944,12 @@ int uv_queue_work_with_qos(uv_loop_t* loop, STATIC_ASSERT(uv_qos_utility == ffrt_qos_utility); STATIC_ASSERT(uv_qos_default == ffrt_qos_default); STATIC_ASSERT(uv_qos_user_initiated == ffrt_qos_user_initiated); - STATIC_ASSERT(uv_qos_user_interactive == ffrt_qos_deadline_request); - if (qos < ffrt_qos_background || qos > ffrt_qos_deadline_request) { + STATIC_ASSERT(uv_qos_user_interactive == ffrt_qos_user_interactive); + if (qos == uv_qos_reserved) { + UV_LOGW("Invaild qos %{public}d", (int)qos); + return UV_EINVAL; + } + if (qos < ffrt_qos_background || qos > ffrt_qos_user_interactive) { return UV_EINVAL; } diff --git a/src/unix/loop.c b/src/unix/loop.c index 2a30408..32206a2 100644 --- a/src/unix/loop.c +++ b/src/unix/loop.c @@ -57,6 +57,7 @@ int uv_loop_init(uv_loop_t* loop) { uv__queue_init(&(lfields_qos->wq_sub[uv_qos_utility])); uv__queue_init(&(lfields_qos->wq_sub[uv_qos_default])); uv__queue_init(&(lfields_qos->wq_sub[uv_qos_user_initiated])); + uv__queue_init(&(lfields_qos->wq_sub[uv_qos_reserved])); uv__queue_init(&(lfields_qos->wq_sub[uv_qos_user_interactive])); #endif diff --git a/src/uv-common.h b/src/uv-common.h index ac0bbb9..25b9011 100644 --- a/src/uv-common.h +++ b/src/uv-common.h @@ -41,6 +41,10 @@ # include #endif +#ifdef USE_FFRT +#define WQ_SUB_QUEUE_LEN 6 +#endif + #if defined(USE_OHOS_DFX) && defined(__aarch64__) #define MULTI_THREAD_CHECK_LOOP_INIT 0x80000000 #endif @@ -451,7 +455,7 @@ struct uv__loop_internal_fields_s { void* inv; /* used by uv__platform_invalidate_fd() */ #endif /* __linux__ */ #ifdef USE_FFRT - struct uv__queue wq_sub[5]; + struct uv__queue wq_sub[WQ_SUB_QUEUE_LEN]; #endif #if defined(USE_OHOS_DFX) && defined(__aarch64__) unsigned int thread_id; -- Gitee