diff --git a/services/context/inc/base_context.h b/services/context/inc/base_context.h index 68d2b8a25bef25ebe8d0575b6d7057506deecd1c..0e4dd94b520e2b2e26dc70d9ee6451dc06142fa2 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 5867ea5849c7d13871756cdf04ca6de35e417d44..9ac39280cf675f51536f67156b749571b7daacbb 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;