================
@@ -548,45 +580,52 @@ template <typename Instance> class PluginInstances {
   // to the returned instances will not be reflected back to instances
   // stored by the PluginInstances object.
   std::vector<Instance> GetSnapshot() {
+    std::lock_guard<std::mutex> lock(m_mutex);
     std::vector<Instance> enabled_instances;
-    for (const auto &instance : m_instances) {
+    for (const Instance &instance : m_instances) {
       if (instance.enabled)
         enabled_instances.push_back(instance);
     }
     return enabled_instances;
   }
 
-  const Instance *GetInstanceAtIndex(uint32_t idx) {
+  // Return a field from the idx-th enabled instance, or default_val if none.
+  template <typename Ret, typename Callback>
+  Ret GetFieldAtIndex(uint32_t idx, Ret default_val, Callback callback) {
+    std::lock_guard<std::mutex> lock(m_mutex);
     uint32_t count = 0;
-
-    return FindEnabledInstance(
-        [&](const Instance &instance) { return count++ == idx; });
+    for (const Instance &instance : m_instances) {
+      if (!instance.enabled)
+        continue;
+      if (count++ == idx)
+        return callback(instance);
+    }
+    return default_val;
   }
 
-  const Instance *GetInstanceForName(llvm::StringRef name) {
+  // Return a field from the enabled instance with the given name, or
+  // default_val if none.
+  template <typename Ret, typename Callback>
+  Ret GetFieldForName(llvm::StringRef name, Ret default_val,
----------------
ashgti wrote:

Same as `GetFieldAtIndex`

https://github.com/llvm/llvm-project/pull/184452
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to