@@ -188,18 +188,18 @@ Status DynamicLoaderPOSIXDYLD::CanLoadImage() { return Status(); }
188188
189189void 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
195195void 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
200200std::optional<lldb::addr_t >
201201DynamicLoaderPOSIXDYLD::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 };
0 commit comments