[llvm] [OFFLOAD] Add support for indexed per-thread containers (PR #164263)
Joseph Huber via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 21 10:36:19 PST 2025
================
@@ -14,101 +14,256 @@
#define OFFLOAD_PERTHREADTABLE_H
#include <list>
+#include <llvm/ADT/SmallVector.h>
+#include <llvm/Support/Error.h>
#include <memory>
#include <mutex>
+#include <type_traits>
+
+template <typename ObjectType> class PerThread {
+ std::mutex Mutex;
+ llvm::SmallVector<std::shared_ptr<ObjectType>> ThreadDataList;
+
+ ObjectType &getThreadData() {
+ static thread_local std::shared_ptr<ObjectType> ThreadData = nullptr;
+ if (!ThreadData) {
+ ThreadData = std::make_shared<ObjectType>();
+ std::lock_guard<std::mutex> Lock(Mutex);
+ ThreadDataList.push_back(ThreadData);
----------------
jhuber6 wrote:
Could we do an emplace back here instead to create the smart pointer directly?
https://github.com/llvm/llvm-project/pull/164263
More information about the llvm-commits
mailing list