Skip to content

Commit 9ef7013

Browse files
committed
[ADT][ConcurrentHashTable] Change thread_local to LLVM_THREAD_LOCAL inside unit test.
Not all platform support C++11 thread_local. Use portable LLVM_THREAD_LOCAL macro instead. Differential Revision: https://reviews.llvm.org/D147649
1 parent f5459fc commit 9ef7013

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

llvm/unittests/ADT/ConcurrentHashtableTest.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,27 @@ class String {
3636
std::array<char, 0x20> ExtraData;
3737
};
3838

39-
static thread_local BumpPtrAllocator ThreadLocalAllocator;
39+
static LLVM_THREAD_LOCAL BumpPtrAllocator *ThreadLocalAllocator = nullptr;
4040
class PerThreadAllocator : public AllocatorBase<PerThreadAllocator> {
4141
public:
4242
inline LLVM_ATTRIBUTE_RETURNS_NONNULL void *Allocate(size_t Size,
4343
size_t Alignment) {
44-
return ThreadLocalAllocator.Allocate(Size, Align(Alignment));
44+
return getAllocatorPtr()->Allocate(Size, Align(Alignment));
4545
}
46-
inline size_t getBytesAllocated() const {
47-
return ThreadLocalAllocator.getBytesAllocated();
46+
inline size_t getBytesAllocated() {
47+
return getAllocatorPtr()->getBytesAllocated();
4848
}
4949

5050
// Pull in base class overloads.
5151
using AllocatorBase<PerThreadAllocator>::Allocate;
52+
53+
protected:
54+
BumpPtrAllocator *getAllocatorPtr() {
55+
if (ThreadLocalAllocator == nullptr)
56+
ThreadLocalAllocator = new BumpPtrAllocator();
57+
58+
return ThreadLocalAllocator;
59+
}
5260
} Allocator;
5361

5462
TEST(ConcurrentHashTableTest, AddStringEntries) {

0 commit comments

Comments
 (0)