[Lldb-commits] [lldb] dfd9a0f - [lldb] Use Guarded in MemoryRegionInfoCache (#219425)
via lldb-commits
lldb-commits at lists.llvm.org
Tue Oct 20 05:59:33 PDT 2026
Author: Raphael Isemann
Date: 2026-10-20T13:59:27+01:00
New Revision: dfd9a0f488bf94dda00d0aa9d2f13b3b328561cb
URL: https://github.com/llvm/llvm-project/commit/dfd9a0f488bf94dda00d0aa9d2f13b3b328561cb
DIFF: https://github.com/llvm/llvm-project/commit/dfd9a0f488bf94dda00d0aa9d2f13b3b328561cb.diff
LOG: [lldb] Use Guarded in MemoryRegionInfoCache (#219425)
This replaces the mutex + variable pair with a `Guarded` variable
that enforces the locking.
Added:
Modified:
lldb/include/lldb/Target/MemoryRegionInfoCache.h
lldb/source/Target/MemoryRegionInfoCache.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Target/MemoryRegionInfoCache.h b/lldb/include/lldb/Target/MemoryRegionInfoCache.h
index 5117f1f598e55..329f694235d86 100644
--- a/lldb/include/lldb/Target/MemoryRegionInfoCache.h
+++ b/lldb/include/lldb/Target/MemoryRegionInfoCache.h
@@ -10,6 +10,7 @@
#define LLDB_TARGET_MEMORYREGIONINFOCACHE_H
#include "lldb/Target/MemoryRegionInfo.h"
+#include "lldb/Utility/Locked.h"
#include <map>
#include <mutex>
@@ -34,8 +35,7 @@ class MemoryRegionInfoCache {
size_t GetSize();
private:
- std::map<lldb::addr_t, MemoryRegionInfo> m_region_infos;
- std::mutex m_mutex;
+ Guarded<std::map<lldb::addr_t, MemoryRegionInfo>, std::mutex> m_region_infos;
};
} // namespace lldb_private
diff --git a/lldb/source/Target/MemoryRegionInfoCache.cpp b/lldb/source/Target/MemoryRegionInfoCache.cpp
index 47694b3ad58fc..e84e56fbcc71e 100644
--- a/lldb/source/Target/MemoryRegionInfoCache.cpp
+++ b/lldb/source/Target/MemoryRegionInfoCache.cpp
@@ -12,21 +12,17 @@
using namespace lldb;
using namespace lldb_private;
-void MemoryRegionInfoCache::Clear() {
- std::lock_guard<std::mutex> guard(m_mutex);
- m_region_infos.clear();
-}
+void MemoryRegionInfoCache::Clear() { m_region_infos.Lock()->clear(); }
size_t MemoryRegionInfoCache::GetSize() {
- std::lock_guard<std::mutex> guard(m_mutex);
- return m_region_infos.size();
+ return m_region_infos.Lock()->size();
}
std::optional<MemoryRegionInfo>
MemoryRegionInfoCache::GetMemoryRegion(addr_t load_addr) {
- std::lock_guard<std::mutex> guard(m_mutex);
- auto it = m_region_infos.upper_bound(load_addr);
- if (it == m_region_infos.begin())
+ auto region_infos = m_region_infos.Lock();
+ auto it = region_infos->upper_bound(load_addr);
+ if (it == region_infos->begin())
return std::nullopt;
--it;
if (load_addr < it->second.GetRange().GetRangeEnd())
@@ -36,6 +32,5 @@ MemoryRegionInfoCache::GetMemoryRegion(addr_t load_addr) {
}
void MemoryRegionInfoCache::AddRegion(const MemoryRegionInfo &ri) {
- std::lock_guard<std::mutex> guard(m_mutex);
- m_region_infos.insert_or_assign(ri.GetRange().GetRangeBase(), ri);
+ m_region_infos.Lock()->insert_or_assign(ri.GetRange().GetRangeBase(), ri);
}
More information about the lldb-commits
mailing list