From 3ba32f3a8c2df46312da85d68f079dc6f81873b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E9=80=B8=E9=A3=9E?= Date: Fri, 8 Apr 2022 15:52:00 +0800 Subject: [PATCH] fix: fix OpenHarmony-3.0-LTS optimize lock problem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡逸飞 --- frameworks/resmgr_lite/include/lock.h | 4 +++- frameworks/resmgr_lite/src/res_locale.cpp | 6 +++--- .../test/unittest/lite/common/string_utils_test.cpp | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/frameworks/resmgr_lite/include/lock.h b/frameworks/resmgr_lite/include/lock.h index d200f07..39e5f58 100644 --- a/frameworks/resmgr_lite/include/lock.h +++ b/frameworks/resmgr_lite/include/lock.h @@ -31,8 +31,10 @@ public: private: std::mutex* mtx_; + + Lock(const Lock &src) = delete; }; } // namespace Resource } // namespace Global } // namespace OHOS -#endif \ No newline at end of file +#endif diff --git a/frameworks/resmgr_lite/src/res_locale.cpp b/frameworks/resmgr_lite/src/res_locale.cpp index 62ad69c..378262e 100644 --- a/frameworks/resmgr_lite/src/res_locale.cpp +++ b/frameworks/resmgr_lite/src/res_locale.cpp @@ -32,7 +32,7 @@ namespace OHOS { namespace Global { namespace Resource { LocaleInfo *ResLocale::defaultLocale_ = nullptr; -Lock ResLocale::lock_ = Lock(); +Lock ResLocale::lock_; ResLocale::ResLocale() : language_(nullptr), region_(nullptr), script_(nullptr) { @@ -426,7 +426,7 @@ void FindAndSort(std::string localeStr, std::vector &candidateLocal ResLocale *currentLocale = ResLocale::BuildFromString(localeStr.c_str(), DASH_SEP, state); LocaleMatcher::Normalize(currentLocale); std::vector::const_iterator iter; - for (iter = candidateLocale.cbegin(); iter != candidateLocale.cend(); iter++) { + for (iter = candidateLocale.cbegin(); iter != candidateLocale.cend(); ++iter) { ResLocale *resLocale = ResLocale::BuildFromString(iter->c_str(), DASH_SEP, state); if (state == SUCCESS) { LocaleMatcher::Normalize(resLocale); @@ -467,4 +467,4 @@ void FindAndSort(std::string localeStr, std::vector &candidateLocal } } // namespace Resource } // namespace Global -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/frameworks/resmgr_lite/test/unittest/lite/common/string_utils_test.cpp b/frameworks/resmgr_lite/test/unittest/lite/common/string_utils_test.cpp index 08cfbca..5ad5ed5 100644 --- a/frameworks/resmgr_lite/test/unittest/lite/common/string_utils_test.cpp +++ b/frameworks/resmgr_lite/test/unittest/lite/common/string_utils_test.cpp @@ -100,7 +100,7 @@ HWTEST_F(StringUtilsTest, LockFuncTest001, TestSize.Level1) int num = 0; int threadNum = 3; int result = num + threadNum; - Lock lock = Lock(); + Lock lock; TestThread(&num, threadNum, &lock); EXPECT_EQ(result, num); -} \ No newline at end of file +} -- Gitee