diff options
Diffstat (limited to 'lldb/source')
-rw-r--r-- | lldb/source/Breakpoint/BreakpointLocationCollection.cpp | 12 | ||||
-rw-r--r-- | lldb/source/Core/ModuleList.cpp | 25 | ||||
-rw-r--r-- | lldb/source/Target/SectionLoadList.cpp | 5 | ||||
-rw-r--r-- | lldb/source/Target/ThreadList.cpp | 6 |
4 files changed, 16 insertions, 32 deletions
diff --git a/lldb/source/Breakpoint/BreakpointLocationCollection.cpp b/lldb/source/Breakpoint/BreakpointLocationCollection.cpp index 413c12a06a6..0651ca09e8f 100644 --- a/lldb/source/Breakpoint/BreakpointLocationCollection.cpp +++ b/lldb/source/Breakpoint/BreakpointLocationCollection.cpp @@ -181,17 +181,11 @@ void BreakpointLocationCollection::GetDescription( BreakpointLocationCollection &BreakpointLocationCollection::operator=( const BreakpointLocationCollection &rhs) { - // Same trick as in ModuleList to avoid lock inversion. if (this != &rhs) { - if (uintptr_t(this) > uintptr_t(&rhs)) { - std::lock_guard<std::mutex> lhs_guard(m_collection_mutex); - std::lock_guard<std::mutex> rhs_guard(rhs.m_collection_mutex); + std::lock(m_collection_mutex, rhs.m_collection_mutex); + std::lock_guard<std::mutex> lhs_guard(m_collection_mutex, std::adopt_lock); + std::lock_guard<std::mutex> rhs_guard(rhs.m_collection_mutex, std::adopt_lock); m_break_loc_collection = rhs.m_break_loc_collection; - } else { - std::lock_guard<std::mutex> lhs_guard(m_collection_mutex); - std::lock_guard<std::mutex> rhs_guard(rhs.m_collection_mutex); - m_break_loc_collection = rhs.m_break_loc_collection; - } } return *this; } diff --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp index 8740bd0f40a..d59e429ad9f 100644 --- a/lldb/source/Core/ModuleList.cpp +++ b/lldb/source/Core/ModuleList.cpp @@ -130,25 +130,12 @@ ModuleList::ModuleList(ModuleList::Notifier *notifier) const ModuleList &ModuleList::operator=(const ModuleList &rhs) { if (this != &rhs) { - // That's probably me nit-picking, but in theoretical situation: - // - // * that two threads A B and - // * two ModuleList's x y do opposite assignments ie.: - // - // in thread A: | in thread B: - // x = y; | y = x; - // - // This establishes correct(same) lock taking order and thus avoids - // priority inversion. - if (uintptr_t(this) > uintptr_t(&rhs)) { - std::lock_guard<std::recursive_mutex> lhs_guard(m_modules_mutex); - std::lock_guard<std::recursive_mutex> rhs_guard(rhs.m_modules_mutex); - m_modules = rhs.m_modules; - } else { - std::lock_guard<std::recursive_mutex> lhs_guard(m_modules_mutex); - std::lock_guard<std::recursive_mutex> rhs_guard(rhs.m_modules_mutex); - m_modules = rhs.m_modules; - } + std::lock(m_modules_mutex, rhs.m_modules_mutex); + std::lock_guard<std::recursive_mutex> lhs_guard(m_modules_mutex, + std::adopt_lock); + std::lock_guard<std::recursive_mutex> rhs_guard(rhs.m_modules_mutex, + std::adopt_lock); + m_modules = rhs.m_modules; } return *this; } diff --git a/lldb/source/Target/SectionLoadList.cpp b/lldb/source/Target/SectionLoadList.cpp index 45b6b52e184..598f49ca13d 100644 --- a/lldb/source/Target/SectionLoadList.cpp +++ b/lldb/source/Target/SectionLoadList.cpp @@ -27,8 +27,9 @@ SectionLoadList::SectionLoadList(const SectionLoadList &rhs) } void SectionLoadList::operator=(const SectionLoadList &rhs) { - std::lock_guard<std::recursive_mutex> lhs_guard(m_mutex); - std::lock_guard<std::recursive_mutex> rhs_guard(rhs.m_mutex); + std::lock(m_mutex, rhs.m_mutex); + std::lock_guard<std::recursive_mutex> lhs_guard(m_mutex, std::adopt_lock); + std::lock_guard<std::recursive_mutex> rhs_guard(rhs.m_mutex, std::adopt_lock); m_addr_to_sect = rhs.m_addr_to_sect; m_sect_to_addr = rhs.m_sect_to_addr; } diff --git a/lldb/source/Target/ThreadList.cpp b/lldb/source/Target/ThreadList.cpp index 86248da4993..afdfda3b0ae 100644 --- a/lldb/source/Target/ThreadList.cpp +++ b/lldb/source/Target/ThreadList.cpp @@ -37,8 +37,10 @@ const ThreadList &ThreadList::operator=(const ThreadList &rhs) { if (this != &rhs) { // Lock both mutexes to make sure neither side changes anyone on us while // the assignment occurs - std::lock_guard<std::recursive_mutex> guard(GetMutex()); - std::lock_guard<std::recursive_mutex> rhs_guard(rhs.GetMutex()); + std::lock(GetMutex(), rhs.GetMutex()); + std::lock_guard<std::recursive_mutex> guard(GetMutex(), std::adopt_lock); + std::lock_guard<std::recursive_mutex> rhs_guard(rhs.GetMutex(), + std::adopt_lock); m_process = rhs.m_process; m_stop_id = rhs.m_stop_id; |