From 44847c5bda6f05f1564fa2c37caf1279fd96072d Mon Sep 17 00:00:00 2001 From: liaoxingxing Date: Tue, 30 Jul 2024 20:09:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BB=B4=E6=B5=8B=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liaoxingxing --- src/heap-inl.h | 11 +++++++++-- src/threadpool.c | 4 ++++ src/unix/signal.c | 32 ++++++++++++++++++++++++++++---- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/heap-inl.h b/src/heap-inl.h index 1e2ed60..cbe6a47 100644 --- a/src/heap-inl.h +++ b/src/heap-inl.h @@ -178,12 +178,19 @@ HEAP_EXPORT(void heap_remove(struct heap* heap, k -= 1; } - heap->nelts -= 1; - /* Unlink the max node. */ child = *max; *max = NULL; +#ifdef OHOS_USE_DFX + if (child == NULL) { + UV_LOGF("Child is NULL, this may be due to multi-threaded calls."); + return; + } +#endif + + heap->nelts -= 1; + if (child == node) { /* We're removing either the max or the last node in the tree. */ if (child == heap->min) { diff --git a/src/threadpool.c b/src/threadpool.c index 4a1ac04..3aefe7c 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -313,9 +313,13 @@ int is_uv_loop_good_magic(const uv_loop_t* loop) { void on_uv_loop_close(uv_loop_t* loop) { time_t t1, t2; time(&t1); + uv_start_trace(UV_TRACE_TAG, "Get Write Lock"); uv_rwlock_wrlock(&g_closed_uv_loop_rwlock); + uv_end_trace(UV_TRACE_TAG); loop->magic = ~UV_LOOP_MAGIC; + uv_start_trace(UV_TRACE_TAG, "Release Write Lock"); uv_rwlock_wrunlock(&g_closed_uv_loop_rwlock); + uv_end_trace(UV_TRACE_TAG); time(&t2); UV_LOGI("uv_loop(%{public}zu) closed in %{public}zds", (size_t)loop, (ssize_t)(t2 - t1)); } diff --git a/src/unix/signal.c b/src/unix/signal.c index bc4206e..f15355f 100644 --- a/src/unix/signal.c +++ b/src/unix/signal.c @@ -103,8 +103,14 @@ static void uv__signal_global_reinit(void) { if (uv__make_pipe(uv__signal_lock_pipefd, 0)) abort(); - if (uv__signal_unlock()) + if (uv__signal_unlock()) { +#ifdef OHOS_USE_DFX + UV_LOGF("errno is %d, uv__signal_lock_pipefd[1] is %d (%s:%s:%d)", errno, uv__signal_lock_pipefd[1], __FILE__, __func__, __LINE__); + return; +#else abort(); +#endif + } } @@ -148,14 +154,26 @@ static void uv__signal_block_and_lock(sigset_t* saved_sigmask) { if (pthread_sigmask(SIG_SETMASK, &new_mask, saved_sigmask)) abort(); - if (uv__signal_lock()) + if (uv__signal_lock()) { +#ifdef OHOS_USE_DFX + UV_LOGF("errno is %d, uv__signal_lock_pipefd[0] is %d (%s:%s:%d)", errno, uv__signal_lock_pipefd[0], __FILE__, __func__, __LINE__); + return; +#else abort(); +#endif + } } static void uv__signal_unlock_and_unblock(sigset_t* saved_sigmask) { - if (uv__signal_unlock()) + if (uv__signal_unlock()) { +#ifdef OHOS_USE_DFX + UV_LOGF("errno is %d, uv__signal_lock_pipefd[1] is %d (%s:%s:%d)", errno, uv__signal_lock_pipefd[1], __FILE__, __func__, __LINE__); + return; +#else abort(); +#endif + } if (pthread_sigmask(SIG_SETMASK, saved_sigmask, NULL)) abort(); @@ -461,8 +479,14 @@ static void uv__signal_event(uv_loop_t* loop, } /* Other errors really should never happen. */ - if (r == -1) + if (r == -1) { +#ifdef OHOS_USE_DFX + UV_LOGF("errno is %d, uv__signal_lock_pipefd[0] is %d (%s:%s:%d)", errno, uv__signal_lock_pipefd[0], __FILE__, __func__, __LINE__); + return; +#else abort(); +#endif + } bytes += r; -- Gitee