[Lldb-commits] [lldb] [lldb][plugin] Clear in same thread as set (PR #139252)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Mon May 12 07:55:39 PDT 2025
================
@@ -189,17 +189,23 @@ DWARFUnit::ScopedExtractDIEs DWARFUnit::ExtractDIEsScoped() {
}
DWARFUnit::ScopedExtractDIEs::ScopedExtractDIEs(DWARFUnit &cu) : m_cu(&cu) {
- m_cu->m_die_array_scoped_mutex.lock_shared();
+ llvm::sys::ScopedLock lock(m_cu->m_die_array_scoped_mutex);
+ ++m_cu->m_die_array_scoped_count;
}
DWARFUnit::ScopedExtractDIEs::~ScopedExtractDIEs() {
if (!m_cu)
return;
- m_cu->m_die_array_scoped_mutex.unlock_shared();
+ {
+ llvm::sys::ScopedLock lock(m_cu->m_die_array_scoped_mutex);
+ --m_cu->m_die_array_scoped_count;
+ if (m_cu->m_die_array_scoped_count == 0)
+ return;
+ }
if (!m_clear_dies || m_cu->m_cancel_scopes)
return;
// Be sure no other ScopedExtractDIEs is running anymore.
----------------
labath wrote:
I think all of this can/should be one critical section. The reason the code was originally doing the unlock is because it was switching the lock type (shared->exclusive). So, I think something like this ought to do it:
```
llvm::sys::ScopedLock lock(m_cu->m_die_array_scoped_mutex);
--m_cu->m_die_array_scoped_count;
if (m_cu->m_die_array_scoped_count == 0 && m_clear_dies && !m_cu->m_cancel_scopes)
m_cu->ClearDIEsRWLocked();
```
https://github.com/llvm/llvm-project/pull/139252
More information about the lldb-commits
mailing list