From 3d7f9ca15e55829f9141728079a55f6a2f767082 Mon Sep 17 00:00:00 2001 From: Artemkin Pavel Date: Tue, 18 Jun 2019 19:03:44 +0500 Subject: [PATCH] #55 thread safe ast cache (#74) --- clickhouse/types/type_parser.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/clickhouse/types/type_parser.cpp b/clickhouse/types/type_parser.cpp index 0b1fa20..62d471d 100644 --- a/clickhouse/types/type_parser.cpp +++ b/clickhouse/types/type_parser.cpp @@ -1,6 +1,8 @@ #include "type_parser.h" #include "../base/string_utils.h" +#include +#include #include namespace clickhouse { @@ -167,8 +169,10 @@ const TypeAst* ParseTypeName(const std::string& type_name) { // Cache for type_name. // Usually we won't have too many type names in the cache, so do not try to // limit cache size. - static std::unordered_map ast_cache; + static std::map ast_cache; + static std::mutex lock; + std::lock_guard guard(lock); auto it = ast_cache.find(type_name); if (it != ast_cache.end()) { return &it->second;