Skip to content

Commit fb74bc6

Browse files
committed
Explicit memory order for storing unique_type_id_ value
1 parent d0545f4 commit fb74bc6

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

clickhouse/types/types.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ uint64_t Type::GetTypeUniqueId() const {
121121
// 1. going to be the same
122122
// 2. going to be stored atomically
123123

124-
if (type_unique_id_ == 0) {
124+
if (type_unique_id_.load(std::memory_order::memory_order_relaxed) == 0) {
125125
const auto name = GetName();
126-
type_unique_id_ = CityHash64WithSeed(name.c_str(), name.size(), code_);
126+
type_unique_id_.store(CityHash64WithSeed(name.c_str(), name.size(), code_), std::memory_order::memory_order_relaxed);
127127
}
128128

129129
return type_unique_id_;

clickhouse/types/types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class Type {
7575

7676
/// Is given type same as current one.
7777
bool IsEqual(const Type& other) const {
78+
// Types are equal only if both code_ and type_unique_id_ are equal.
7879
return this == &other
7980
// GetTypeUniqueId() is relatively heavy, so avoid calling it when comparing obviously different types.
8081
|| (this->GetCode() == other.GetCode() && this->GetTypeUniqueId() == other.GetTypeUniqueId());

0 commit comments

Comments
 (0)