From 8687fb24adb7b92d08b9cab0fc305b6e6e75d562 Mon Sep 17 00:00:00 2001 From: XKK Date: Tue, 5 Sep 2023 15:32:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E9=94=81=E4=BF=9D=E6=8A=A4wantAgent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: XKK --- frameworks/js/napi/include/common.h | 1 + frameworks/js/napi/src/common.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/frameworks/js/napi/include/common.h b/frameworks/js/napi/include/common.h index 1c8f831e8..d7bb8acf9 100644 --- a/frameworks/js/napi/include/common.h +++ b/frameworks/js/napi/include/common.h @@ -1576,6 +1576,7 @@ private: static const int32_t ONLY_CALLBACK_MAX_PARA = 1; static const int32_t ONLY_CALLBACK_MIN_PARA = 0; static std::set> wantAgent_; + static std::mutex mutex_; }; } // namespace NotificationNapi } // namespace OHOS diff --git a/frameworks/js/napi/src/common.cpp b/frameworks/js/napi/src/common.cpp index c14aae32e..e5244053e 100644 --- a/frameworks/js/napi/src/common.cpp +++ b/frameworks/js/napi/src/common.cpp @@ -21,6 +21,7 @@ namespace OHOS { namespace NotificationNapi { std::set> Common::wantAgent_; +std::mutex Common::mutex_; namespace { static const std::unordered_map ERROR_CODE_MESSAGE { @@ -4598,7 +4599,10 @@ napi_value Common::CreateWantAgentByJS(const napi_env &env, return nullptr; } - wantAgent_.insert(agent); + { + std::lock_guard lock(mutex_); + wantAgent_.insert(agent); + } napi_value wantAgent = nullptr; napi_value wantAgentClass = nullptr; napi_define_class(env, @@ -4621,6 +4625,7 @@ napi_value Common::CreateWantAgentByJS(const napi_env &env, AbilityRuntime::WantAgent::WantAgent *objectInfo = static_cast(data); if (objectInfo) { + std::lock_guard lock(mutex_); for (auto it = wantAgent_.begin(); it != wantAgent_.end(); ++it) { if ((*it).get() == objectInfo) { wantAgent_.erase(it); -- Gitee