Signed-off-by: liuziwei <liuziwei12@huawei.com>
This commit is contained in:
liuziwei 2024-09-09 16:56:11 +08:00
parent 1a87d030d9
commit 2c6644fbd9
2 changed files with 15 additions and 5 deletions

View File

@ -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<ExecutorRegisterCallback> executorCallback_ {nullptr};

View File

@ -86,6 +86,16 @@ void Executor::OnFrameworkReady()
RegisterExecutorCallback(executorInfo);
}
bool Executor::IsExecutorRegistered()
{
std::lock_guard<std::recursive_mutex> 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);