[ADT][ConcurrentHashTable] Change thread_local to LLVM_THREAD_LOCAL inside unit test.
authorAlexey Lapshin <a.v.lapshin@mail.ru>
Wed, 5 Apr 2023 18:45:00 +0000 (20:45 +0200)
committerAlexey Lapshin <a.v.lapshin@mail.ru>
Wed, 5 Apr 2023 20:15:51 +0000 (22:15 +0200)
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

index 8138633..b76ace2 100644 (file)
@@ -36,19 +36,27 @@ protected:
   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) {