From bb63befbdd42b64b200488825c7ce51923e717da Mon Sep 17 00:00:00 2001 From: abonadon-hk Date: Wed, 27 Aug 2025 11:39:10 +0800 Subject: [PATCH] fix :add mutex Signed-off-by: abonadon-hk Change-Id: I4ef523a453f37c93f66fc92e6b9c297f24dd74cd --- services/context/inc/base_context.h | 2 +- services/context/src/base_context.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/services/context/inc/base_context.h b/services/context/inc/base_context.h index 68d2b8a25..0e4dd94b5 100644 --- a/services/context/inc/base_context.h +++ b/services/context/inc/base_context.h @@ -68,7 +68,7 @@ private: uint64_t contextId_ = INVALID_CONTEXT_ID; std::string description_; bool hasStarted_ = false; - std::mutex mutex_; + mutable std::recursive_mutex mutex_; int32_t latestError_ = ResultCode::GENERAL_ERROR; }; } // namespace UserAuth diff --git a/services/context/src/base_context.cpp b/services/context/src/base_context.cpp index 5867ea584..9ac39280c 100644 --- a/services/context/src/base_context.cpp +++ b/services/context/src/base_context.cpp @@ -81,7 +81,7 @@ std::string BaseContext::GetCallerName() const bool BaseContext::Start() { - std::lock_guard guard(mutex_); + std::lock_guard guard(mutex_); IAM_LOGD("%{public}s start", GetDescription()); if (hasStarted_) { IAM_LOGI("%{public}s context has started, cannot start again", GetDescription()); @@ -93,12 +93,14 @@ bool BaseContext::Start() bool BaseContext::Stop() { + std::lock_guard guard(mutex_); IAM_LOGD("%{public}s start", GetDescription()); return OnStop(); } std::shared_ptr BaseContext::GetScheduleNode(uint64_t scheduleId) const { + std::lock_guard guard(mutex_); for (auto const &schedule : scheduleList_) { if (schedule == nullptr) { continue; -- Gitee