From a7fa5b06de6faa80dbe50d10fd3d1c0250660c7d Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Mon, 2 Sep 2024 15:48:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E6=94=B9=E4=BB=A3=E7=A0=81=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liaoxingxing --- .gitattributes | 1 - BUILD.gn | 16 +++++++++------- include/uv.h | 2 ++ src/heap-inl.h | 2 +- src/threadpool.c | 11 +++++------ src/timer.c | 1 - src/unix/core.c | 6 ++++-- 7 files changed, 21 insertions(+), 18 deletions(-) delete mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 89297cb..0000000 --- a/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -test/fixtures/lorem_ipsum.txt text eol=lf diff --git a/BUILD.gn b/BUILD.gn index 75a85eb..1aca736 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -246,13 +246,13 @@ if (defined(ohos_lite)) { if (is_mac || (defined(is_ios) && is_ios)) { sources += nonwin_srcs + [ "src/unix/bsd-ifaddrs.c", - "src/unix/kqueue.c", - "src/unix/random-getentropy.c", "src/unix/darwin-proctitle.c", "src/unix/darwin.c", "src/unix/fsevents.c", - "src/unix/os390-proctitle.c", + "src/unix/kqueue.c", "src/unix/log_unix.c", + "src/unix/os390-proctitle.c", + "src/unix/random-getentropy.c", "src/unix/trace_unix.c", ] } else if (is_mingw || is_win) { @@ -289,10 +289,10 @@ if (defined(ohos_lite)) { sources += nonwin_srcs + [ "src/unix/linux.c", "src/unix/procfs-exepath.c", + "src/unix/proctitle.c", "src/unix/random-getentropy.c", "src/unix/random-getrandom.c", "src/unix/random-sysctl-linux.c", - "src/unix/proctitle.c", ] if (libuv_use_ffrt) { external_deps += [ "ffrt:libffrt" ] @@ -307,9 +307,11 @@ if (defined(ohos_lite)) { "hitrace:hitrace_meter", ] } + if (is_ohos && enable_async_stack) { sources += [ "src/dfx/async_stack/libuv_async_stack.c" ] } + if (is_android) { sources += [ "src/win/log_win.c", @@ -319,20 +321,20 @@ if (defined(ohos_lite)) { } else if (is_linux) { sources += nonwin_srcs + [ "src/unix/linux.c", + "src/unix/log_unix.c", "src/unix/procfs-exepath.c", + "src/unix/proctitle.c", "src/unix/random-getrandom.c", "src/unix/random-sysctl-linux.c", - "src/unix/proctitle.c", - "src/unix/log_unix.c", "src/unix/trace_unix.c", ] } else { sources += nonwin_srcs + [ "src/unix/linux.c", "src/unix/procfs-exepath.c", + "src/unix/proctitle.c", "src/unix/random-getrandom.c", "src/unix/random-sysctl-linux.c", - "src/unix/proctitle.c", ] } subsystem_name = "thirdparty" diff --git a/include/uv.h b/include/uv.h index 418796d..945c34e 100644 --- a/include/uv.h +++ b/include/uv.h @@ -226,6 +226,7 @@ typedef enum { #define UV_EVENT_MAGIC_OFFSET 0x12345ULL #define UV_EVENT_MAGIC_OFFSETBITS 44 + /* Handle types. */ typedef struct uv_loop_s uv_loop_t; typedef struct uv_handle_s uv_handle_t; @@ -1953,6 +1954,7 @@ UV_EXTERN void uv_loop_set_data(uv_loop_t*, void* data); 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); UV_EXTERN int uv_check_data_valid(struct uv_loop_data* data); + /* String utilities needed internally for dealing with Windows. */ size_t uv_utf16_length_as_wtf8(const uint16_t* utf16, ssize_t utf16_len); diff --git a/src/heap-inl.h b/src/heap-inl.h index 939a523..1e2ed60 100644 --- a/src/heap-inl.h +++ b/src/heap-inl.h @@ -177,7 +177,7 @@ HEAP_EXPORT(void heap_remove(struct heap* heap, path >>= 1; k -= 1; } - + heap->nelts -= 1; /* Unlink the max node. */ diff --git a/src/threadpool.c b/src/threadpool.c index db6dac7..edd724f 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -35,6 +35,9 @@ #include "ffrt_inner.h" #endif #include +#ifdef ASYNC_STACKTRACE +#include "dfx/async_stack/libuv_async_stack.h" +#endif #define MAX_THREADPOOL_SIZE 1024 #define UV_TRACE_NAME "UV_TRACE" @@ -53,10 +56,6 @@ static struct uv__queue run_slow_work_message; static struct uv__queue slow_io_pending_wq; -#ifdef ASYNC_STACKTRACE -#include "dfx/async_stack/libuv_async_stack.h" -#endif - #ifdef UV_STATISTIC #define MAX_DUMP_QUEUE_SIZE 200 static uv_mutex_t dump_queue_mutex; @@ -634,7 +633,7 @@ static int uv__work_cancel(uv_loop_t* loop, uv_req_t* req, struct uv__work* w) { uv__loop_internal_fields_t* lfields = uv__get_internal_fields(w->loop); int qos = (ffrt_qos_t)(intptr_t)req->reserved[0]; - if (uv_check_data_valid((struct uv_loop_data*)(loop->data)) == 0) { + if (uv_check_data_valid((struct uv_loop_data*)(w->loop->data)) == 0) { int status = (w->work == uv__cancelled) ? UV_ECANCELED : 0; struct uv_loop_data* addr = (struct uv_loop_data*)((uint64_t)w->loop->data - (UV_EVENT_MAGIC_OFFSET << UV_EVENT_MAGIC_OFFSETBITS)); @@ -666,7 +665,7 @@ void uv__work_done(uv_async_t* handle) { return; } rdunlock_closed_uv_loop_rwlock(); - + uv_mutex_lock(&loop->wq_mutex); #ifndef USE_FFRT uv__queue_move(&loop->wq, &wq); diff --git a/src/timer.c b/src/timer.c index 0734f43..35548b4 100644 --- a/src/timer.c +++ b/src/timer.c @@ -97,7 +97,6 @@ int uv_timer_start(uv_timer_t* handle, (struct heap_node*) &handle->heap_node, timer_less_than); uv__handle_start(handle); - #ifdef __linux__ if (uv_check_data_valid((struct uv_loop_data*)handle->loop->data) == 0) { uv_async_send(&handle->loop->wq_async); diff --git a/src/unix/core.c b/src/unix/core.c index 359ceeb..ba7c8ce 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -1954,13 +1954,13 @@ int uv_register_task_to_event(struct uv_loop_s* loop, uv_post_task func, void* h #endif } + 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 -1; - loop->data = (struct uv_loop_data*)((uint64_t)loop->data - (UV_EVENT_MAGIC_OFFSET << UV_EVENT_MAGIC_OFFSETBITS)); free(loop->data); @@ -1971,6 +1971,7 @@ int uv_unregister_task_to_event(struct uv_loop_s* loop) #endif } + int uv_check_data_valid(struct uv_loop_data* data) { #if defined(__aarch64__) if (data == NULL || ((uint64_t)data >> UV_EVENT_MAGIC_OFFSETBITS) != (uint64_t)(UV_EVENT_MAGIC_OFFSET)) { @@ -1986,4 +1987,5 @@ int uv_check_data_valid(struct uv_loop_data* data) { #else return -1; #endif -} \ No newline at end of file +} +