[Lldb-commits] [PATCH] D51319: Use a RAII guard to lock/unlock DisassemblerLLVMC [NFC]
Raphael Isemann via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Mon Aug 27 13:33:17 PDT 2018
teemperor created this revision.
teemperor added a reviewer: LLDB.
Herald added a subscriber: lldb-commits.
The manual lock/unlock calls make my LazyBool refactoring tricky (because now `return` potentially
cause deadlocks), so this patch just replaces them with a much safer lock guard that is using RAII.
Repository:
rLLDB LLDB
https://reviews.llvm.org/D51319
Files:
source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp
source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h
Index: source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h
===================================================================
--- source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h
+++ source/Plugins/Disassembler/llvm/DisassemblerLLVMC.h
@@ -77,6 +77,17 @@
uint64_t ReferencePC,
const char **ReferenceName);
+ struct Guard {
+ DisassemblerLLVMC *m_instance;
+ Guard(DisassemblerLLVMC *instance, InstructionLLVMC *inst,
+ const lldb_private::ExecutionContext *exe_ctx = nullptr)
+ : m_instance(instance) {
+ m_instance->Lock(inst, exe_ctx);
+ }
+
+ ~Guard() { m_instance->Unlock(); }
+ };
+
void Lock(InstructionLLVMC *inst,
const lldb_private::ExecutionContext *exe_ctx) {
m_mutex.lock();
Index: source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp
===================================================================
--- source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp
+++ source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp
@@ -100,7 +100,7 @@
if (m_does_branch == eLazyBoolCalculate) {
std::shared_ptr<DisassemblerLLVMC> disasm_sp(GetDisassembler());
if (disasm_sp) {
- disasm_sp->Lock(this, NULL);
+ DisassemblerLLVMC::Guard guard(disasm_sp.get(), this);
DataExtractor data;
if (m_opcode.GetData(data)) {
bool is_alternate_isa;
@@ -125,7 +125,6 @@
m_does_branch = eLazyBoolNo;
}
}
- disasm_sp->Unlock();
}
}
return m_does_branch == eLazyBoolYes;
@@ -135,7 +134,7 @@
if (m_has_delay_slot == eLazyBoolCalculate) {
std::shared_ptr<DisassemblerLLVMC> disasm_sp(GetDisassembler());
if (disasm_sp) {
- disasm_sp->Lock(this, NULL);
+ DisassemblerLLVMC::Guard guard(disasm_sp.get(), this);
DataExtractor data;
if (m_opcode.GetData(data)) {
bool is_alternate_isa;
@@ -160,7 +159,6 @@
m_has_delay_slot = eLazyBoolNo;
}
}
- disasm_sp->Unlock();
}
}
return m_has_delay_slot == eLazyBoolYes;
@@ -261,10 +259,13 @@
const addr_t pc = m_address.GetFileAddress();
llvm::MCInst inst;
- disasm_sp->Lock(this, NULL);
- const size_t inst_size =
- mc_disasm_ptr->GetMCInst(opcode_data, opcode_data_len, pc, inst);
- disasm_sp->Unlock();
+ size_t inst_size;
+ {
+ DisassemblerLLVMC::Guard guard(disasm_sp.get(), this);
+ inst_size = mc_disasm_ptr->GetMCInst(opcode_data, opcode_data_len,
+ pc, inst);
+ }
+
if (inst_size == 0)
m_opcode.Clear();
else {
@@ -878,7 +879,7 @@
if (m_is_call == eLazyBoolCalculate) {
std::shared_ptr<DisassemblerLLVMC> disasm_sp(GetDisassembler());
if (disasm_sp) {
- disasm_sp->Lock(this, NULL);
+ DisassemblerLLVMC::Guard guard(disasm_sp.get(), this);
DataExtractor data;
if (m_opcode.GetData(data)) {
bool is_alternate_isa;
@@ -900,7 +901,6 @@
m_is_call = eLazyBoolNo;
}
}
- disasm_sp->Unlock();
}
}
return m_is_call == eLazyBoolYes;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51319.162736.patch
Type: text/x-patch
Size: 3363 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180827/2fe1927e/attachment.bin>
More information about the lldb-commits
mailing list