diff --git a/BUILD.gn b/BUILD.gn index 06882163e57841573d671efd79bfe3d496fdf7fc..c9cbb46e6954697e8cc0c667514ffc986fd02a42 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -297,10 +297,15 @@ if (defined(ohos_lite)) { "hitrace:hitrace_meter", ] } - if (is_ohos && enable_async_stack) { external_deps += [ "faultloggerd:libasync_stack" ] } + if (is_android) { + sources += [ + "src/win/log_win.c", + "src/win/trace_win.c", + ] + } } else if (is_linux) { sources += nonwin_srcs + [ "src/unix/linux-core.c", diff --git a/include/uv.h b/include/uv.h index cbd5ce46c1247e38f256003098f8a76295c2fd6f..49b5a48baee3d9492cfd07246c7f06fa45a82a6e 100644 --- a/include/uv.h +++ b/include/uv.h @@ -1830,13 +1830,7 @@ union uv_any_req { }; #undef XX -enum TaskPriority { - TASK_HIGH, - TASK_NORMAL, - TASK_LOW, -}; - -typedef void (*uv_io_cb)(void* data, int status); +typedef void (*uv_io_cb)(uv_work_t* work, int status); typedef void (*uv_post_task)(void* handler, uv_io_cb func, void* data, int prio); struct uv_loop_data { @@ -1844,6 +1838,11 @@ struct uv_loop_data { uv_post_task post_task_func; }; +struct uv_parm_t { + uv_work_t* work; + int status; +}; + struct uv_loop_s { /* User data - use this for whatever. */ void* data; @@ -1863,8 +1862,8 @@ struct uv_loop_s { UV_EXTERN void* uv_loop_get_data(const uv_loop_t*); UV_EXTERN void uv_loop_set_data(uv_loop_t*, void* data); -UV_EXTERN void uv_register_task_to_event(struct uv_loop_s* loop, uv_post_task func, void* handler); -UV_EXTERN void uv_unregister_task_to_event(struct uv_loop_s* loop); +UV_EXTERN int uv_register_task_to_event(struct uv_loop_s* loop, uv_post_task func, void* handler); +UV_EXTERN int uv_unregister_task_to_event(struct uv_loop_s* loop); /* Don't export the private CPP symbols. */ #undef UV_HANDLE_TYPE_PRIVATE diff --git a/src/threadpool.c b/src/threadpool.c index 1317a8743a4911d3a42439f94cde6d29edf4e0fe..57e3ace6b4d62e224f908e5317697720f2b1a853 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -57,7 +57,7 @@ static int check_data_valid(struct uv_loop_data* data) { if (data == NULL || ((uint64_t)data >> UV_EVENT_MAGIC_OFFSETBITS) != (uint64_t)(UV_EVENT_MAGIC_OFFSET)) { return -1; } - struct uv_loop_data* addr = (struct uv_loop_data*)((uint64_t)loop->data - + struct uv_loop_data* addr = (struct uv_loop_data*)((uint64_t)data - (UV_EVENT_MAGIC_OFFSET << UV_EVENT_MAGIC_OFFSETBITS)); if (addr->post_task_func == NULL) { UV_LOGE("post_task_func is NULL"); @@ -633,9 +633,13 @@ static int uv__work_cancel(uv_loop_t* loop, uv_req_t* req, struct uv__work* w) { int qos = (ffrt_qos_t)(intptr_t)req->reserved[0]; if (check_data_valid((struct uv_loop_data*)(w->loop->data)) == 0) { + struct uv_parm_t parm; + uv_work_t* work_temp = container_of(w, uv_work_t, work_req); + parm.work = req; + parm.status = UV_ECANCELED; struct uv_loop_data* addr = (struct uv_loop_data*)((uint64_t)w->loop->data - (UV_EVENT_MAGIC_OFFSET << UV_EVENT_MAGIC_OFFSETBITS)); - addr->post_task_func(addr->event_handler, w->done, w, qos); + addr->post_task_func(addr->event_handler, work_temp->after_work_cb, (void*) &parm, qos); } else { QUEUE_INSERT_TAIL(&(lfields->wq_sub[qos]), &w->wq); uv_async_send(&loop->wq_async); @@ -678,7 +682,7 @@ void uv__work_done(uv_async_t* handle) { #endif uv_mutex_unlock(&loop->wq_mutex); if (loop->active_reqs.count > TASK_NUMBER_WARNING) { - UV_LOGW("The number of task is too much, task number is %{public}d", loop->active_reqs.count); + UV_LOGW("The number of task is too much, task number is %{public}d", loop->active_reqs.count); } snprintf(str, sizeof(str), "%d", loop->active_reqs.count); strcat(trac_name, str); @@ -744,8 +748,8 @@ void uv__ffrt_work(ffrt_executor_task_t* data, ffrt_qos_t qos) #ifdef UV_STATISTIC uv__post_statistic_work(w, WORK_EXECUTING); #endif -#ifdef ASYNC_STACKTRACE uv_work_t* req = container_of(w, uv_work_t, work_req); +#ifdef ASYNC_STACKTRACE SetStackId((uint64_t)req->reserved[3]); #endif w->work(w); @@ -761,7 +765,6 @@ void uv__ffrt_work(ffrt_executor_task_t* data, ffrt_qos_t qos) || !lfields->wq_sub[qos][0] || !lfields->wq_sub[qos][1]) { rdunlock_closed_uv_loop_rwlock(); - uv_work_t* req = container_of(w, uv_work_t, work_req); UV_LOGE("uv_loop(%{public}zu:%{public}#x) in task(%p:%p) is invalid", (size_t)w->loop, w->loop->magic, req->work_cb, req->after_work_cb); return; @@ -771,9 +774,12 @@ void uv__ffrt_work(ffrt_executor_task_t* data, ffrt_qos_t qos) w->work = NULL; /* Signal uv_cancel() that the work req is done executing. */ if (check_data_valid((struct uv_loop_data*)(w->loop->data)) == 0) { + struct uv_parm_t parm; + parm.work = req; + parm.status = 0; struct uv_loop_data* addr = (struct uv_loop_data*)((uint64_t)w->loop->data - (UV_EVENT_MAGIC_OFFSET << UV_EVENT_MAGIC_OFFSETBITS)); - addr->post_task_func(addr->event_handler, w->done, w, qos); + addr->post_task_func(addr->event_handler, req->after_work_cb, (void*) &parm, qos); } else { QUEUE_INSERT_TAIL(&(lfields->wq_sub[qos]), &w->wq); uv_async_send(&w->loop->wq_async); diff --git a/src/unix/core.c b/src/unix/core.c index e7f73a0c24c3741fa4092b3617111ead13da6d82..14bce30522a7625c309ac1ca8047ee745af78667 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -1678,19 +1678,19 @@ unsigned int uv_available_parallelism(void) { #endif /* __linux__ */ } -void uv_register_task_to_event(struct uv_loop_s* loop, uv_post_task func, void* handler) +int uv_register_task_to_event(struct uv_loop_s* loop, uv_post_task func, void* handler) { #if defined(__aarch64__) if (loop == NULL) - return; + return -1; struct uv_loop_data* data = (struct uv_loop_data*)malloc(sizeof(struct uv_loop_data)); if (data == NULL) - return; + return -1; if ((uint64_t)data >> UV_EVENT_MAGIC_OFFSETBITS != 0x0) { UV_LOGE("malloc address error!"); free(data); - return; + return -1; } (void)memset(data, 0, sizeof(struct uv_loop_data)); @@ -1698,18 +1698,25 @@ void uv_register_task_to_event(struct uv_loop_s* loop, uv_post_task func, void* data->event_handler = handler; data = (struct uv_loop_data*)((uint64_t)data | (UV_EVENT_MAGIC_OFFSET << UV_EVENT_MAGIC_OFFSETBITS)); loop->data = (void *)data; + return 0; #endif + return -1; } -void uv_unregister_task_to_event(struct uv_loop_s* loop) +int uv_unregister_task_to_event(struct uv_loop_s* loop) { #if defined(__aarch64__) - if (loop == NULL || loop->data == NULL || - ((uint64_t)loop->data >> UV_EVENT_MAGIC_OFFSETBITS) != (uint64_t)(UV_EVENT_MAGIC_OFFSET)) - return; + if (loop == NULL || loop->data == NULL) + return -1; + + if ((uint64_t)loop->data >> UV_EVENT_MAGIC_OFFSETBITS) != (uint64_t)(UV_EVENT_MAGIC_OFFSET)) + return -1; + loop->data = (struct uv_loop_data*)((uint64_t)loop->data - (UV_EVENT_MAGIC_OFFSET << UV_EVENT_MAGIC_OFFSETBITS)); free(loop->data); loop->data = NULL; + return 0; #endif + return -1; } \ No newline at end of file