From 9ef701318b4590e1fa8bb61906d5957d7b1f6a2f Mon Sep 17 00:00:00 2001 From: Alexey Lapshin Date: Wed, 5 Apr 2023 20:45:00 +0200 Subject: [PATCH] [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 --- llvm/unittests/ADT/ConcurrentHashtableTest.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/llvm/unittests/ADT/ConcurrentHashtableTest.cpp b/llvm/unittests/ADT/ConcurrentHashtableTest.cpp index 8138633..b76ace2 100644 --- a/llvm/unittests/ADT/ConcurrentHashtableTest.cpp +++ b/llvm/unittests/ADT/ConcurrentHashtableTest.cpp @@ -36,19 +36,27 @@ protected: std::array ExtraData; }; -static thread_local BumpPtrAllocator ThreadLocalAllocator; +static LLVM_THREAD_LOCAL BumpPtrAllocator *ThreadLocalAllocator = nullptr; class PerThreadAllocator : public AllocatorBase { 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::Allocate; + +protected: + BumpPtrAllocator *getAllocatorPtr() { + if (ThreadLocalAllocator == nullptr) + ThreadLocalAllocator = new BumpPtrAllocator(); + + return ThreadLocalAllocator; + } } Allocator; TEST(ConcurrentHashTableTest, AddStringEntries) { -- 2.7.4