Skip to content

Commit 3d7f9ca

Browse files
authored
ClickHouse#55 thread safe ast cache (ClickHouse#74)
1 parent 8088706 commit 3d7f9ca

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

clickhouse/types/type_parser.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "type_parser.h"
22
#include "../base/string_utils.h"
33

4+
#include <map>
5+
#include <mutex>
46
#include <unordered_map>
57

68
namespace clickhouse {
@@ -167,8 +169,10 @@ const TypeAst* ParseTypeName(const std::string& type_name) {
167169
// Cache for type_name.
168170
// Usually we won't have too many type names in the cache, so do not try to
169171
// limit cache size.
170-
static std::unordered_map<std::string, TypeAst> ast_cache;
172+
static std::map<std::string, TypeAst> ast_cache;
173+
static std::mutex lock;
171174

175+
std::lock_guard<std::mutex> guard(lock);
172176
auto it = ast_cache.find(type_name);
173177
if (it != ast_cache.end()) {
174178
return &it->second;

0 commit comments

Comments
 (0)