From 979d29561385bf0c033f20c01cfc099c251564f5 Mon Sep 17 00:00:00 2001 From: sodanotgreen Date: Sun, 21 Jul 2024 15:56:49 +0800 Subject: [PATCH] log Signed-off-by: sodanotgreen --- .../ability/native/insight_intent_host_client.cpp | 13 ++++--------- .../ability/native/insight_intent_host_client.h | 1 + 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/frameworks/native/ability/native/insight_intent_host_client.cpp b/frameworks/native/ability/native/insight_intent_host_client.cpp index 8a27d6cf0dc..032ca3b77cf 100644 --- a/frameworks/native/ability/native/insight_intent_host_client.cpp +++ b/frameworks/native/ability/native/insight_intent_host_client.cpp @@ -20,18 +20,13 @@ namespace OHOS { namespace AbilityRuntime { sptr InsightIntentHostClient::instance_ = nullptr; std::mutex InsightIntentHostClient::instanceMutex_; +std::once_flag InsightIntentHostClient::singletonFlag_; sptr InsightIntentHostClient::GetInstance() { - if (instance_ == nullptr) { - std::lock_guard lock_l(instanceMutex_); - if (instance_ == nullptr) { - instance_ = new (std::nothrow) InsightIntentHostClient(); - if (instance_ == nullptr) { - TAG_LOGE(AAFwkTag::INTENT, "failed to create InsightIntentHostClient."); - } - } - } + std::call_once(singletonFlag_, []() { + instance_ = new (std::nothrow) InsightIntentHostClient(); + }) return instance_; } diff --git a/interfaces/kits/native/ability/native/insight_intent_host_client.h b/interfaces/kits/native/ability/native/insight_intent_host_client.h index 324d8010adc..5991baca6a2 100644 --- a/interfaces/kits/native/ability/native/insight_intent_host_client.h +++ b/interfaces/kits/native/ability/native/insight_intent_host_client.h @@ -59,6 +59,7 @@ public: private: static std::mutex instanceMutex_; + static std::once_flag singletonFlag_; uint64_t key_ = 0; static sptr instance_; mutable std::mutex insightIntentExecutebackMutex_;