Skip to content

Commit 38a017e

Browse files
author
Tom Yang
committed
switch usage of std shared_mutex with rwmutex, which is more portable
1 parent 6585ce1 commit 38a017e

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,18 @@ Status DynamicLoaderPOSIXDYLD::CanLoadImage() { return Status(); }
188188

189189
void DynamicLoaderPOSIXDYLD::SetLoadedModule(const ModuleSP &module_sp,
190190
addr_t link_map_addr) {
191-
std::unique_lock<std::shared_mutex> lock(m_loaded_modules_rw_mutex);
191+
llvm::sys::ScopedWriter lock(m_loaded_modules_rw_mutex);
192192
m_loaded_modules[module_sp] = link_map_addr;
193193
}
194194

195195
void DynamicLoaderPOSIXDYLD::UnloadModule(const ModuleSP &module_sp) {
196-
std::unique_lock<std::shared_mutex> lock(m_loaded_modules_rw_mutex);
196+
llvm::sys::ScopedWriter lock(m_loaded_modules_rw_mutex);
197197
m_loaded_modules.erase(module_sp);
198198
}
199199

200200
std::optional<lldb::addr_t>
201201
DynamicLoaderPOSIXDYLD::GetLoadedModuleLinkAddr(const ModuleSP &module_sp) {
202-
std::shared_lock<std::shared_mutex> lock(m_loaded_modules_rw_mutex);
202+
llvm::sys::ScopedReader lock(m_loaded_modules_rw_mutex);
203203
auto it = m_loaded_modules.find(module_sp);
204204
if (it != m_loaded_modules.end())
205205
return it->second;
@@ -447,6 +447,7 @@ void DynamicLoaderPOSIXDYLD::RefreshModules() {
447447
m_initial_modules_added = true;
448448
}
449449

450+
// Synchronize reading and writing of `m_interpreter_module`.
450451
std::mutex interpreter_module_mutex;
451452
// We should be able to take SOEntry as reference since the data
452453
// exists for the duration of this call in `m_rendezvous`.
@@ -489,6 +490,12 @@ void DynamicLoaderPOSIXDYLD::RefreshModules() {
489490
}
490491
}
491492

493+
// Note: in a multi-threaded environment, these module lists may be
494+
// appended to out-of-order. This is fine, since there's no
495+
// expectation for `loaded_modules` or `new_modules` to be in any
496+
// particular order, and appending to each module list is thread-safe.
497+
// Also, `new_modules` is only used for the `ModulesDidLoad` call at
498+
// the end of this function.
492499
loaded_modules.AppendIfNeeded(module_sp);
493500
new_modules.Append(module_sp);
494501
};

lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class DynamicLoaderPOSIXDYLD : public lldb_private::DynamicLoader {
182182
/// to access `m_loaded_modules` safely.
183183
std::map<lldb::ModuleWP, lldb::addr_t, std::owner_less<lldb::ModuleWP>>
184184
m_loaded_modules;
185-
std::shared_mutex m_loaded_modules_rw_mutex;
185+
llvm::sys::RWMutex m_loaded_modules_rw_mutex;
186186

187187
void SetLoadedModule(const lldb::ModuleSP &module_sp,
188188
lldb::addr_t link_map_addr);

0 commit comments

Comments
 (0)