[llvm] [OFFLOAD] Add support for indexed per-thread containers (PR #164263)
Kevin Sala Penades via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 23 11:24:46 PDT 2025
================
@@ -16,17 +16,93 @@
#include <list>
#include <memory>
#include <mutex>
+#include <type_traits>
+
+template <typename ObjectType> struct PerThread {
+ struct PerThreadData {
+ std::unique_ptr<ObjectType> ThreadEntry;
+ };
+
+ std::mutex Mutex;
+ std::list<std::shared_ptr<PerThreadData>> ThreadDataList;
+
+ // define default constructors, disable copy and move constructors
+ PerThread() = default;
+ PerThread(const PerThread &) = delete;
+ PerThread(PerThread &&) = delete;
+ PerThread &operator=(const PerThread &) = delete;
+ PerThread &operator=(PerThread &&) = delete;
+ ~PerThread() {
+ std::lock_guard<std::mutex> Lock(Mutex);
+ ThreadDataList.clear();
----------------
kevinsala wrote:
That probably should be more like an assert (i.e., verifying nobody has the lock) than acquiring the lock. At that point, if another thread has the lock, it's probably that something went very wrong.
https://github.com/llvm/llvm-project/pull/164263
More information about the llvm-commits
mailing list