From 3838efc65f892765a82d644303216a461c68b83b Mon Sep 17 00:00:00 2001 From: liuyifei Date: Wed, 10 Apr 2024 06:30:13 +0000 Subject: [PATCH] =?UTF-8?q?fixed=20a4de3dc=20from=20https://gitee.com/liuy?= =?UTF-8?q?ifeifei/hiviewdfx=5Fhilog/pulls/527=20=E4=BF=AE=E5=A4=8Dcppcras?= =?UTF-8?q?h=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liuyifei --- frameworks/libhilog/param/properties.cpp | 52 +++++++++++++----------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/frameworks/libhilog/param/properties.cpp b/frameworks/libhilog/param/properties.cpp index 8b7a5ec..ac4713e 100644 --- a/frameworks/libhilog/param/properties.cpp +++ b/frameworks/libhilog/param/properties.cpp @@ -339,20 +339,22 @@ uint16_t GetDomainLevel(uint32_t domain) { ReadLock lock(*mtx); it = domainMap->find(domain); + if (it != domainMap->end()) { + LogLevelCache* levelCache = it->second; + return levelCache->getValue(); + } } - if (it == domainMap->end()) { // new domain - InsertLock lock(*mtx); - it = domainMap->find(domain); // secured for two thread went across above condition - if (it == domainMap->end()) { - LogLevelCache* levelCache = new LogLevelCache(TextToLogLevel, LOG_LEVEL_MIN, - PropType::PROP_DOMAIN_LOG_LEVEL, Uint2HexStr(domain)); - auto result = domainMap->insert({ domain, levelCache }); - if (!result.second) { - delete levelCache; - return LOG_LEVEL_MIN; - } - it = result.first; + InsertLock lock(*mtx); + it = domainMap->find(domain); // secured for two thread went across above condition + if (it == domainMap->end()) { + LogLevelCache* levelCache = new LogLevelCache(TextToLogLevel, LOG_LEVEL_MIN, + PropType::PROP_DOMAIN_LOG_LEVEL, Uint2HexStr(domain)); + auto result = domainMap->insert({ domain, levelCache }); + if (!result.second) { + delete levelCache; + return LOG_LEVEL_MIN; } + it = result.first; } LogLevelCache* levelCache = it->second; return levelCache->getValue(); @@ -366,20 +368,22 @@ uint16_t GetTagLevel(const string& tag) { ReadLock lock(*mtx); it = tagMap->find(tag); + if (it != tagMap->end()) { + LogLevelCache* levelCache = it->second; + return levelCache->getValue(); + } } - if (it == tagMap->end()) { // new tag - InsertLock lock(*mtx); - it = tagMap->find(tag); // secured for two thread went across above condition - if (it == tagMap->end()) { - LogLevelCache* levelCache = new LogLevelCache(TextToLogLevel, LOG_LEVEL_MIN, - PropType::PROP_TAG_LOG_LEVEL, tag); - auto result = tagMap->insert({ tag, levelCache }); - if (!result.second) { - delete levelCache; - return LOG_LEVEL_MIN; - } - it = result.first; + InsertLock lock(*mtx); + it = tagMap->find(tag); // secured for two thread went across above condition + if (it == tagMap->end()) { + LogLevelCache* levelCache = new LogLevelCache(TextToLogLevel, LOG_LEVEL_MIN, + PropType::PROP_TAG_LOG_LEVEL, tag); + auto result = tagMap->insert({ tag, levelCache }); + if (!result.second) { + delete levelCache; + return LOG_LEVEL_MIN; } + it = result.first; } LogLevelCache* levelCache = it->second; return levelCache->getValue(); -- Gitee