[Lldb-commits] [lldb] [lldb] Make the PluginManager thread safe (PR #184452)
John Harrison via lldb-commits
lldb-commits at lists.llvm.org
Tue Mar 3 16:47:10 PST 2026
================
@@ -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) {
----------------
ashgti wrote:
Should we use `std::optional<Ret>` to make it more explicit that `std::nullopt`?
At the call site, you can do `GetFieldAtIndex(idx, callback).value_or(default_val)`, which pushes the default value handling to the call site and better supports move only types.
https://github.com/llvm/llvm-project/pull/184452
More information about the lldb-commits
mailing list