[lldb] Make ModuleSpecList iterable (NFC)
authorJonas Devlieghere <jonas@devlieghere.com>
Tue, 29 Mar 2022 00:14:44 +0000 (17:14 -0700)
committerJonas Devlieghere <jonas@devlieghere.com>
Tue, 29 Mar 2022 22:26:54 +0000 (15:26 -0700)
lldb/include/lldb/Core/ModuleSpec.h

index bcf4ec3..5789e6c 100644 (file)
@@ -13,6 +13,7 @@
 #include "lldb/Target/PathMappingList.h"
 #include "lldb/Utility/ArchSpec.h"
 #include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/Iterable.h"
 #include "lldb/Utility/Stream.h"
 #include "lldb/Utility/UUID.h"
 
@@ -287,7 +288,7 @@ public:
     if (this != &rhs) {
       std::lock(m_mutex, rhs.m_mutex);
       std::lock_guard<std::recursive_mutex> lhs_guard(m_mutex, std::adopt_lock);
-      std::lock_guard<std::recursive_mutex> rhs_guard(rhs.m_mutex, 
+      std::lock_guard<std::recursive_mutex> rhs_guard(rhs.m_mutex,
                                                       std::adopt_lock);
       m_specs = rhs.m_specs;
     }
@@ -387,8 +388,16 @@ public:
     }
   }
 
+  typedef std::vector<ModuleSpec> collection;
+  typedef LockingAdaptedIterable<collection, ModuleSpec, vector_adapter,
+                                 std::recursive_mutex>
+      ModuleSpecIterable;
+
+  ModuleSpecIterable ModuleSpecs() {
+    return ModuleSpecIterable(m_specs, m_mutex);
+  }
+
 protected:
-  typedef std::vector<ModuleSpec> collection; ///< The module collection type.
   collection m_specs;                         ///< The collection of modules.
   mutable std::recursive_mutex m_mutex;
 };