[llvm] [OFFLOAD] Add support for indexed per-thread containers (PR #164263)
Alex Duran via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 24 22:34:39 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);
----------------
adurang wrote:
As @kevinsala says I'd rather create the object outside the critical section.
https://github.com/llvm/llvm-project/pull/164263
More information about the llvm-commits
mailing list