summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core/ModuleList.cpp
diff options
context:
space:
mode:
authorJim Ingham <jingham@apple.com>2019-03-29 17:07:30 +0000
committerJim Ingham <jingham@apple.com>2019-03-29 17:07:30 +0000
commitcdd4892f12e860905565f4e4444d7726618f89bd (patch)
treec0dc087dd800b84beea1df1c2cb533bdecd83c06 /lldb/source/Core/ModuleList.cpp
parentdd0c7d88c6c52ffd7e346497cf36dc13f6ce6766 (diff)
downloadbcm5719-llvm-cdd4892f12e860905565f4e4444d7726618f89bd.tar.gz
bcm5719-llvm-cdd4892f12e860905565f4e4444d7726618f89bd.zip
Use the multi-lockable form of std::lock for operator=
For = operators for lists that have mutexes, we were either just taking the locks sequentially or hand-rolling a trick to try to avoid lock inversion. Use the std::lock mechanism for this instead. Differential Revision: https://reviews.llvm.org/D59957 llvm-svn: 357276
Diffstat (limited to 'lldb/source/Core/ModuleList.cpp')
-rw-r--r--lldb/source/Core/ModuleList.cpp25
1 files changed, 6 insertions, 19 deletions
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;
}
OpenPOWER on IntegriCloud