From f0cfe13721bf249a38d3f367d141ee8bc53720c4 Mon Sep 17 00:00:00 2001 From: Tianshi Liu Date: Wed, 6 Aug 2025 13:11:45 +0800 Subject: [PATCH] send executor msg in seperate thread Change-Id: Ia47484adabeab5e939c44c28850b45ffd6dc1666 Signed-off-by: Tianshi Liu --- services/context/src/simple_auth_context.cpp | 24 ++++++++++++++++---- services/core/src/resource_node_utils.cpp | 1 + 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/services/context/src/simple_auth_context.cpp b/services/context/src/simple_auth_context.cpp index 97fd79a67..1031b868e 100644 --- a/services/context/src/simple_auth_context.cpp +++ b/services/context/src/simple_auth_context.cpp @@ -26,6 +26,7 @@ #include "resource_node_utils.h" #include "schedule_node.h" #include "schedule_node_callback.h" +#include "thread_handler_manager.h" #include "user_idm_database.h" #define LOG_TAG "USER_AUTH_SA" @@ -203,8 +204,8 @@ void SimpleAuthContext::OnResult(int32_t resultCode, const std::shared_ptrGetAuthExecutorMsgs(); - for (auto &authExecutorMsg : authExecutorMsgs) { - ResourceNodeUtils::SendMsgToExecutor( - authExecutorMsg.executorIndex, authExecutorMsg.commandId, authExecutorMsg.msg); + auto &threadManager = ThreadHandlerManager::GetInstance(); + + for (uint32_t msgIndex = 0; msgIndex < authExecutorMsgs.size(); msgIndex++) { + auto authExecutorMsg = authExecutorMsgs[msgIndex]; + std::string threadName = std::to_string(GetContextId()) + "_msg_" + std::to_string(msgIndex); + if (!threadManager.CreateThreadHandler(threadName)) { + IAM_LOGE("Failed to create thread handler for executor message"); + continue; + } + + threadManager.PostTask(threadName, [authExecutorMsg, threadName]() { + ResourceNodeUtils::SendMsgToExecutor( + authExecutorMsg.executorIndex, authExecutorMsg.commandId, authExecutorMsg.msg); + }); + + threadManager.DestroyThreadHandler(threadName); } + IAM_LOGI("end"); } bool SimpleAuthContext::UpdateScheduleResult(const std::shared_ptr &scheduleResultAttr, diff --git a/services/core/src/resource_node_utils.cpp b/services/core/src/resource_node_utils.cpp index ef8ea9ab3..c83695350 100644 --- a/services/core/src/resource_node_utils.cpp +++ b/services/core/src/resource_node_utils.cpp @@ -62,6 +62,7 @@ int32_t ResourceNodeUtils::NotifyExecutorToDeleteTemplates( void ResourceNodeUtils::SendMsgToExecutor(uint64_t executorIndex, int32_t commandId, const std::vector &msg) { + IAM_LOGI("send msg to ****%{public}hx begin", static_cast(executorIndex)); auto resourceNode = ResourceNodePool::Instance().Select(executorIndex).lock(); if (resourceNode == nullptr) { IAM_LOGE("failed to find ****%{public}hx", static_cast(executorIndex)); -- Gitee