Skip to content

Commit b13bf1d

Browse files
derekmaurocopybara-github
authored andcommitted
Avoid using a thread_local in an inline function since this
causes issues on some platforms. Fixes #1946 PiperOrigin-RevId: 827571630 Change-Id: I217acb5778fa1224422e4893cc71c896e2c795fa
1 parent 982f425 commit b13bf1d

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

absl/container/internal/raw_hash_set.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@ inline void* PrevSlot(void* slot, size_t slot_size) {
131131

132132
} // namespace
133133

134+
// Must be defined out-of-line to avoid MSVC error C2482 on some platforms,
135+
// which is caused by non-constexpr initialization.
136+
uint16_t HashtableSize::NextSeed() {
137+
static_assert(PerTableSeed::kBitCount == 16);
138+
thread_local uint16_t seed =
139+
static_cast<uint16_t>(reinterpret_cast<uintptr_t>(&seed));
140+
seed += uint16_t{0xad53};
141+
return seed;
142+
}
143+
134144
GenerationType* EmptyGeneration() {
135145
if (SwisstableGenerationsEnabled()) {
136146
constexpr size_t kNumEmptyGenerations = 1024;

absl/container/internal/raw_hash_set.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -461,15 +461,6 @@ class PerTableSeed {
461461
const uint16_t seed_;
462462
};
463463

464-
// Returns next per-table seed.
465-
inline uint16_t NextSeed() {
466-
static_assert(PerTableSeed::kBitCount == 16);
467-
thread_local uint16_t seed =
468-
static_cast<uint16_t>(reinterpret_cast<uintptr_t>(&seed));
469-
seed += uint16_t{0xad53};
470-
return seed;
471-
}
472-
473464
// The size and also has additionally
474465
// 1) one bit that stores whether we have infoz.
475466
// 2) PerTableSeed::kBitCount bits for the seed.
@@ -517,6 +508,9 @@ class HashtableSize {
517508

518509
void set_no_seed_for_testing() { data_ &= ~kSeedMask; }
519510

511+
// Returns next per-table seed.
512+
static uint16_t NextSeed();
513+
520514
private:
521515
void set_seed(uint16_t seed) {
522516
data_ = (data_ & ~kSeedMask) | (seed | PerTableSeed::kSignBit);

absl/container/internal/raw_hash_set_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2560,7 +2560,7 @@ std::vector<int> OrderOfIteration(const T& t) {
25602560
// in seed.
25612561
void GenerateIrrelevantSeeds(int cnt) {
25622562
for (int i = cnt % 17; i > 0; --i) {
2563-
NextSeed();
2563+
HashtableSize::NextSeed();
25642564
}
25652565
}
25662566

0 commit comments

Comments
 (0)