[PATCH] D147649: [ADT][ConcurrentHashTable] Change thread_local to LLVM_THREAD_LOCAL inside unit test.

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


This revision was automatically updated to reflect the committed changes.
Closed by commit rG9ef701318b45: [ADT][ConcurrentHashTable] Change thread_local to LLVM_THREAD_LOCAL inside unit… (authored by avl).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147649/new/

https://reviews.llvm.org/D147649

Files:
  llvm/unittests/ADT/ConcurrentHashtableTest.cpp


Index: llvm/unittests/ADT/ConcurrentHashtableTest.cpp
===================================================================
--- llvm/unittests/ADT/ConcurrentHashtableTest.cpp
+++ llvm/unittests/ADT/ConcurrentHashtableTest.cpp
@@ -36,19 +36,27 @@
   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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147649.511196.patch
Type: text/x-patch
Size: 1331 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230405/7e5951a0/attachment.bin>


More information about the llvm-commits mailing list