[PATCH] D147656: [DWARFLinkerParallel] change thread_local to LLVM_THREAD_LOCAL for StringPool.
Alexey Lapshin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 5 12:49:10 PDT 2023
avl created this revision.
avl added reviewers: SeanP, JDevlieghere.
Herald added a subscriber: hiraditya.
Herald added a project: All.
avl requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Not all platforms support C++11 thread_local. Use portable
LLVM_THREAD_LOCAL macro instead.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D147656
Files:
llvm/include/llvm/DWARFLinkerParallel/StringPool.h
llvm/lib/DWARFLinkerParallel/StringPool.cpp
Index: llvm/lib/DWARFLinkerParallel/StringPool.cpp
===================================================================
--- llvm/lib/DWARFLinkerParallel/StringPool.cpp
+++ llvm/lib/DWARFLinkerParallel/StringPool.cpp
@@ -8,5 +8,5 @@
#include "llvm/DWARFLinkerParallel/StringPool.h"
-thread_local llvm::BumpPtrAllocator
- llvm::dwarflinker_parallel::PerThreadStringAllocator::ThreadLocalAllocator;
+LLVM_THREAD_LOCAL llvm::BumpPtrAllocator
+ *llvm::dwarflinker_parallel::PerThreadStringAllocator::ThreadLocalAllocator;
Index: llvm/include/llvm/DWARFLinkerParallel/StringPool.h
===================================================================
--- llvm/include/llvm/DWARFLinkerParallel/StringPool.h
+++ llvm/include/llvm/DWARFLinkerParallel/StringPool.h
@@ -27,14 +27,21 @@
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));
}
// Pull in base class overloads.
using AllocatorBase<PerThreadStringAllocator>::Allocate;
private:
- static thread_local BumpPtrAllocator ThreadLocalAllocator;
+ BumpPtrAllocator *getAllocatorPtr() {
+ if (ThreadLocalAllocator == nullptr)
+ ThreadLocalAllocator = new BumpPtrAllocator();
+
+ return ThreadLocalAllocator;
+ }
+
+ static LLVM_THREAD_LOCAL BumpPtrAllocator *ThreadLocalAllocator;
};
class StringPoolEntryInfo {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147656.511186.patch
Type: text/x-patch
Size: 1529 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230405/bb93d496/attachment.bin>
More information about the llvm-commits
mailing list