diff --git a/frameworks/native/executors/include/executor.h b/frameworks/native/executors/include/executor.h index fdec91cf7..e002a2eba 100644 --- a/frameworks/native/executors/include/executor.h +++ b/frameworks/native/executors/include/executor.h @@ -53,6 +53,7 @@ private: void RegisterExecutorCallback(ExecutorInfo &executorInfo); void UnregisterExecutorCallback(); void RespondCallbackOnDisconnect(); + bool IsExecutorRegistered(); std::recursive_mutex registerMutex_; std::recursive_mutex mutex_; std::shared_ptr executorCallback_ {nullptr}; diff --git a/frameworks/native/executors/src/executor.cpp b/frameworks/native/executors/src/executor.cpp index 38981ddb8..c6786cfde 100644 --- a/frameworks/native/executors/src/executor.cpp +++ b/frameworks/native/executors/src/executor.cpp @@ -86,6 +86,16 @@ void Executor::OnFrameworkReady() RegisterExecutorCallback(executorInfo); } +bool Executor::IsExecutorRegistered() +{ + std::lock_guard lockExecutorIndex(mutex_); + if (executorIndex_.has_value()) { + IAM_LOGI("%{public}s executor already registered", GetDescription()); + return true; + } + return false; +} + void Executor::RegisterExecutorCallback(ExecutorInfo &executorInfo) { IAM_LOGI("%{public}s start", GetDescription()); @@ -101,11 +111,10 @@ void Executor::RegisterExecutorCallback(ExecutorInfo &executorInfo) IF_FALSE_LOGE_AND_RETURN(executorCallback_ != nullptr); } executorCallback = executorCallback_; - - if (executorIndex_.has_value()) { - IAM_LOGI("%{public}s executor already registered, try unregister", GetDescription()); - UnregisterExecutorCallback(); - } + } + if (IsExecutorRegistered()) { + IAM_LOGI("%{public}s executor already registered, try unregister", GetDescription()); + UnregisterExecutorCallback(); } IF_FALSE_LOGE_AND_RETURN(executorMgrWrapper_ != nullptr); uint64_t executorIndex = executorMgrWrapper_->Register(executorInfo, executorCallback);