Skip to content

Commit

Permalink
[ADT][ConcurrentHashTable] Change thread_local to LLVM_THREAD_LOCAL i…
Browse files Browse the repository at this point in the history
…nside unit test.

Not all platform support C++11 thread_local. Use portable
LLVM_THREAD_LOCAL macro instead.

Differential Revision: https://reviews.llvm.org/D147649
  • Loading branch information
avl-llvm committed Apr 5, 2023
1 parent f5459fc commit 9ef7013
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions llvm/unittests/ADT/ConcurrentHashtableTest.cpp
Expand Up @@ -36,19 +36,27 @@ class String {
std::array<char, 0x20> ExtraData;
};

static thread_local BumpPtrAllocator ThreadLocalAllocator;
static LLVM_THREAD_LOCAL BumpPtrAllocator *ThreadLocalAllocator = nullptr;
class PerThreadAllocator : public AllocatorBase<PerThreadAllocator> {
public:
inline LLVM_ATTRIBUTE_RETURNS_NONNULL void *Allocate(size_t Size,
size_t Alignment) {
return ThreadLocalAllocator.Allocate(Size, Align(Alignment));
return getAllocatorPtr()->Allocate(Size, Align(Alignment));
}
inline size_t getBytesAllocated() const {
return ThreadLocalAllocator.getBytesAllocated();
inline size_t getBytesAllocated() {
return getAllocatorPtr()->getBytesAllocated();
}

// Pull in base class overloads.
using AllocatorBase<PerThreadAllocator>::Allocate;

protected:
BumpPtrAllocator *getAllocatorPtr() {
if (ThreadLocalAllocator == nullptr)
ThreadLocalAllocator = new BumpPtrAllocator();

return ThreadLocalAllocator;
}
} Allocator;

TEST(ConcurrentHashTableTest, AddStringEntries) {
Expand Down

0 comments on commit 9ef7013

Please sign in to comment.