From 0732e7dd8c7db1bf6c56cc4c9eb7a1d0dacd8a7e Mon Sep 17 00:00:00 2001 From: tuxiaohang Date: Thu, 29 May 2025 10:33:35 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"NativeSafeAsyncWork=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E4=BC=98=E5=8C=96"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit f0680ed252bf842e396d71018530156a2da1cd26. Signed-off-by: tuxiaohang Change-Id: I8bba6d9767ab8ae5bdd4d3c12a94a7df4c76c25c --- native_engine/native_event.cpp | 5 ----- native_engine/native_safe_async_work.cpp | 13 ++++++------- native_engine/native_safe_async_work.h | 2 -- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/native_engine/native_event.cpp b/native_engine/native_event.cpp index cd66a152e..1af099336 100644 --- a/native_engine/native_event.cpp +++ b/native_engine/native_event.cpp @@ -245,11 +245,6 @@ NativeEvent::NativeEvent(NativeEngine* engine, func, asyncResource, asyncResourceName, maxQueueSize, threadCount, finalizeData, finalizeCallback, context, callJsCallback) { -#if defined(ENABLE_EVENT_HANDLER) - if (runner_ != nullptr) { - eventHandler_ = std::make_shared(runner_); - } -#endif } bool NativeEvent::Init() diff --git a/native_engine/native_safe_async_work.cpp b/native_engine/native_safe_async_work.cpp index fb764b99b..6c7f38116 100644 --- a/native_engine/native_safe_async_work.cpp +++ b/native_engine/native_safe_async_work.cpp @@ -99,7 +99,10 @@ NativeSafeAsyncWork::NativeSafeAsyncWork(NativeEngine* engine, #endif #if defined(ENABLE_EVENT_HANDLER) - runner_ = EventRunner::Current(); + std::shared_ptr runner = EventRunner::Current(); + if (runner != nullptr) { + eventHandler_ = std::make_shared(runner); + } #endif } @@ -407,8 +410,8 @@ napi_status NativeSafeAsyncWork::PostTask(void *data, int32_t priority, bool isT { #if defined(ENABLE_EVENT_HANDLER) HILOG_DEBUG("NativeSafeAsyncWork::PostTask called"); - if (runner_ == nullptr || engine_ == nullptr) { - HILOG_ERROR("post task failed due to nullptr engine or eventRunner"); + if (engine_ == nullptr || eventHandler_ == nullptr) { + HILOG_ERROR("post task failed due to nullptr engine or eventHandler"); return napi_status::napi_generic_failure; } // the task will be execute at main thread or worker thread @@ -438,10 +441,6 @@ napi_status NativeSafeAsyncWork::PostTask(void *data, int32_t priority, bool isT } } }; - - if (UNLIKELY(eventHandler_ == nullptr)) { - eventHandler_ = std::make_shared(runner_); - } bool res = false; if (isTail) { HILOG_DEBUG("The task is posted from tail"); diff --git a/native_engine/native_safe_async_work.h b/native_engine/native_safe_async_work.h index c11024aa2..ea09ac563 100644 --- a/native_engine/native_safe_async_work.h +++ b/native_engine/native_safe_async_work.h @@ -30,7 +30,6 @@ #if defined(ENABLE_EVENT_HANDLER) namespace OHOS::AppExecFwk { - class EventRunner; class EventHandler; } #endif @@ -102,7 +101,6 @@ protected: std::condition_variable condition_; SafeAsyncStatus status_ = SafeAsyncStatus::UNKNOW; #if defined(ENABLE_EVENT_HANDLER) - std::shared_ptr runner_ = nullptr; std::shared_ptr eventHandler_ = nullptr; std::atomic taskSize_ = 0; #endif -- Gitee