From 5941858efdca72425c29bf043d3ec84e7fec6f62 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Thu, 1 Dec 2022 09:24:32 +0000 Subject: [PATCH] [lldb][Module][NFC] Add ModuleList::AnyOf Differential Revision: https://reviews.llvm.org/D139083 --- lldb/include/lldb/Core/ModuleList.h | 7 +++++++ lldb/source/Core/ModuleList.cpp | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lldb/include/lldb/Core/ModuleList.h b/lldb/include/lldb/Core/ModuleList.h index 3ae56f17db74..631d7889f367 100644 --- a/lldb/include/lldb/Core/ModuleList.h +++ b/lldb/include/lldb/Core/ModuleList.h @@ -473,6 +473,13 @@ public: void ForEach(std::function const &callback) const; + /// Returns true if 'callback' returns true for one of the modules + /// in this ModuleList. + /// + /// This function is thread-safe. + bool AnyOf( + std::function const &callback) const; + protected: // Class typedefs. typedef std::vector diff --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp index 991163c63dc5..5aa58d9bba6b 100644 --- a/lldb/source/Core/ModuleList.cpp +++ b/lldb/source/Core/ModuleList.cpp @@ -1074,3 +1074,16 @@ void ModuleList::ForEach( break; } } + +bool ModuleList::AnyOf( + std::function const &callback) + const { + std::lock_guard guard(m_modules_mutex); + for (const auto &module_sp : m_modules) { + assert(module_sp != nullptr); + if (callback(*module_sp)) + return true; + } + + return false; +}