Skip to content

Commit 74d4870

Browse files
zhytyTom Yang
andauthored
update ManualDWARFIndex::Index to use std::once (llvm#165896)
Small change to use (what I think is) a better practice -- we were using the `m_indexed` bool member to make sure we called `Index()` once, but we should just use `std::once`! This change shouldn't affect functionality. This change may also make concurrent access to `Index()` thread-safe, though the ManualDWARFIndex API isn't completely thread-safe due to `Decode()`. I'm not sure if ManualDWARFIndex was ever intended to be thread-safe. Test Plan: `ninja check-lldb` Tested basic debugging workflow of a couple of large projects I had built. Basically: ``` (lldb) target create <project> (lldb) b main (lldb) r (lldb) step ... ``` I A/B tested the performance of launching several modules with parallel module loading and didn't observe any performance regressions. --------- Co-authored-by: Tom Yang <[email protected]>
1 parent 4ac74fc commit 74d4870

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "lldb/Utility/Stream.h"
2323
#include "lldb/Utility/Timer.h"
2424
#include "lldb/lldb-private-enumerations.h"
25-
#include "llvm/Support/FormatVariadic.h"
2625
#include "llvm/Support/ThreadPool.h"
2726
#include <atomic>
2827
#include <optional>
@@ -33,10 +32,10 @@ using namespace lldb_private::plugin::dwarf;
3332
using namespace llvm::dwarf;
3433

3534
void ManualDWARFIndex::Index() {
36-
if (m_indexed)
37-
return;
38-
m_indexed = true;
35+
std::call_once(m_indexed_flag, [this]() { IndexImpl(); });
36+
}
3937

38+
void ManualDWARFIndex::IndexImpl() {
4039
ElapsedTime elapsed(m_index_time);
4140
LLDB_SCOPED_TIMERF("%p", static_cast<void *>(m_dwarf));
4241
if (LoadFromCache()) {

lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,14 @@ class ManualDWARFIndex : public DWARFIndex {
6666
void Dump(Stream &s) override;
6767

6868
private:
69+
/// Reads the DWARF debug info to build the index once.
70+
///
71+
/// Should be called before attempting to retrieve symbols.
6972
void Index();
7073

74+
/// Call `ManualDWARFIndex::Index()` instead.
75+
void IndexImpl();
76+
7177
/// Decode a serialized version of this object from data.
7278
///
7379
/// \param data
@@ -170,7 +176,7 @@ class ManualDWARFIndex : public DWARFIndex {
170176
llvm::DenseSet<uint64_t> m_type_sigs_to_avoid;
171177

172178
IndexSet<NameToDIE> m_set;
173-
bool m_indexed = false;
179+
std::once_flag m_indexed_flag;
174180
};
175181
} // namespace dwarf
176182
} // namespace lldb_private::plugin

0 commit comments

Comments
 (0)