[llvm] [OFFLOAD] Add support for indexed per-thread containers (PR #164263)
    Shilei Tian via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Thu Oct 23 10:24:52 PDT 2025
    
    
  
================
@@ -100,15 +176,101 @@ template <typename ContainerType, typename ObjectType> struct PerThreadTable {
   }
 
   template <class F> void clear(F f) {
-    std::lock_guard<std::mutex> Lock(Mtx);
-    for (auto ThData : ThreadDataList) {
-      if (!ThData->ThEntry || ThData->NElements == 0)
+    for (auto ThreadData : ThreadDataList) {
+      if (!ThreadData->ThreadEntry || ThreadData->NElements == 0)
         continue;
-      ThData->ThEntry->clear(f);
-      ThData->NElements = 0;
+      if constexpr (has_clearAll<ContainerType>::value) {
+        ThreadData->ThreadEntry->clearAll(f);
+      } else if constexpr (has_iterator<ContainerType>::value &&
+                           has_clear<ContainerType>::value) {
+        for (auto &Obj : *ThreadData->ThreadEntry) {
+          if constexpr (is_associative<ContainerType>::value) {
+            f(Obj.second);
+          } else {
+            f(Obj);
+          }
+        }
+        ThreadData->ThreadEntry->clear();
+      } else {
+        static_assert(true, "Container type not supported");
+      }
+      ThreadData->NElements = 0;
     }
     ThreadDataList.clear();
   }
+
+  template <class F> llvm::Error deinit(F f) {
+    for (auto ThreadData : ThreadDataList) {
----------------
shiltian wrote:
no auto
https://github.com/llvm/llvm-project/pull/164263
    
    
More information about the llvm-commits
mailing list