[Lldb-commits] [lldb] r229008 - Add a ModuleList::ForEach(...) which takes the module list mutex calls the std::function argument with each module. If you return true in the callback, iteration will continue, if you return false, iteration will stop and the lock will be released.

Greg Clayton gclayton at apple.com
Thu Feb 12 17:19:24 PST 2015


Author: gclayton
Date: Thu Feb 12 19:19:24 2015
New Revision: 229008

URL: http://llvm.org/viewvc/llvm-project?rev=229008&view=rev
Log:
Add a ModuleList::ForEach(...) which takes the module list mutex calls the std::function argument with each module. If you return true in the callback, iteration will continue, if you return false, iteration will stop and the lock will be released.

<rdar://problem/19213054>


Modified:
    lldb/trunk/include/lldb/Core/ModuleList.h
    lldb/trunk/source/Core/ModuleList.cpp

Modified: lldb/trunk/include/lldb/Core/ModuleList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ModuleList.h?rev=229008&r1=229007&r2=229008&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ModuleList.h (original)
+++ lldb/trunk/include/lldb/Core/ModuleList.h Thu Feb 12 19:19:24 2015
@@ -12,6 +12,7 @@
 
 #include <vector>
 #include <list>
+#include <functional>
 
 #include "lldb/lldb-private.h"
 #include "lldb/Host/Mutex.h"
@@ -562,6 +563,9 @@ public:
     static bool
     RemoveSharedModuleIfOrphaned (const Module *module_ptr);
 
+    void
+    ForEach (std::function <bool (const lldb::ModuleSP &module_sp)> const &callback) const;
+
 protected:
     //------------------------------------------------------------------
     // Class typedefs.

Modified: lldb/trunk/source/Core/ModuleList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ModuleList.cpp?rev=229008&r1=229007&r2=229008&view=diff
==============================================================================
--- lldb/trunk/source/Core/ModuleList.cpp (original)
+++ lldb/trunk/source/Core/ModuleList.cpp Thu Feb 12 19:19:24 2015
@@ -1162,3 +1162,15 @@ ModuleList::LoadScriptingResourcesInTarg
     }
     return errors.size() == 0;
 }
+
+void
+ModuleList::ForEach (std::function <bool (const ModuleSP &module_sp)> const &callback) const
+{
+    Mutex::Locker locker(m_modules_mutex);
+    for (const auto &module : m_modules)
+    {
+        // If the callback returns false, then stop iterating and break out
+        if (!callback (module))
+            break;
+    }
+}





More information about the lldb-commits mailing list