diff --git a/frameworks/libhilog/param/properties.cpp b/frameworks/libhilog/param/properties.cpp index 8b7a5ecbd8b54f254994232e6e11cce30a9e4e89..ac4713ea8de230e5dc6067f1dd814c02d63a968b 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();