[llvm] 9ef7013 - [ADT][ConcurrentHashTable] Change thread_local to LLVM_THREAD_LOCAL inside unit test.

Alexey Lapshin via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 5 13:17:17 PDT 2023


Author: Alexey Lapshin
Date: 2023-04-05T22:15:51+02:00
New Revision: 9ef701318b4590e1fa8bb61906d5957d7b1f6a2f

URL: https://github.com/llvm/llvm-project/commit/9ef701318b4590e1fa8bb61906d5957d7b1f6a2f
DIFF: https://github.com/llvm/llvm-project/commit/9ef701318b4590e1fa8bb61906d5957d7b1f6a2f.diff

LOG: [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

Added: 
    

Modified: 
    llvm/unittests/ADT/ConcurrentHashtableTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/ADT/ConcurrentHashtableTest.cpp b/llvm/unittests/ADT/ConcurrentHashtableTest.cpp
index 8138633bc6de9..b76ace23120f6 100644
--- a/llvm/unittests/ADT/ConcurrentHashtableTest.cpp
+++ b/llvm/unittests/ADT/ConcurrentHashtableTest.cpp
@@ -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) {


        


More information about the llvm-commits mailing list