From 7597b353b3cdf56af79b8abb86b5a5d1330af4e2 Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Mon, 2 Feb 2015 20:45:17 +0000 Subject: [PATCH] Make one mutex for the lldb_private::Platform class that can be used to protect with modifying member variables. This mutex is designed to be used for simple modifications, so the lock should be taken, modify the member variable and released. We need to make sure this isn't used with any code that cause code to rely or reenter on another thread. Partial fix for: llvm-svn: 227855 --- lldb/include/lldb/Target/Platform.h | 20 +++++++++----------- .../Plugins/Platform/MacOSX/PlatformDarwin.cpp | 7 ++++++- lldb/source/Target/Platform.cpp | 10 +++++----- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h index 9a91c79..2f2281d 100644 --- a/lldb/include/lldb/Target/Platform.h +++ b/lldb/include/lldb/Target/Platform.h @@ -952,8 +952,7 @@ namespace lldb_private { uint32_t m_update_os_version; ArchSpec m_system_arch; // The architecture of the kernel or the remote platform typedef std::map IDToNameMap; - Mutex m_uid_map_mutex; - Mutex m_gid_map_mutex; + Mutex m_mutex; // Mutex for modifying Platform data structures that should only be used for non-reentrant code IDToNameMap m_uid_map; IDToNameMap m_gid_map; size_t m_max_uid_name_len; @@ -967,7 +966,6 @@ namespace lldb_private { std::string m_local_cache_directory; std::vector m_trap_handlers; bool m_calculated_trap_handlers; - Mutex m_trap_handler_mutex; //------------------------------------------------------------------ /// Ask the Platform subclass to fill in the list of trap handler names @@ -988,7 +986,7 @@ namespace lldb_private { const char * GetCachedUserName (uint32_t uid) { - Mutex::Locker locker (m_uid_map_mutex); + Mutex::Locker locker (m_mutex); IDToNameMap::iterator pos = m_uid_map.find (uid); if (pos != m_uid_map.end()) { @@ -1004,7 +1002,7 @@ namespace lldb_private { const char * SetCachedUserName (uint32_t uid, const char *name, size_t name_len) { - Mutex::Locker locker (m_uid_map_mutex); + Mutex::Locker locker (m_mutex); ConstString const_name (name); m_uid_map[uid] = const_name; if (m_max_uid_name_len < name_len) @@ -1016,7 +1014,7 @@ namespace lldb_private { void SetUserNameNotFound (uint32_t uid) { - Mutex::Locker locker (m_uid_map_mutex); + Mutex::Locker locker (m_mutex); m_uid_map[uid] = ConstString(); } @@ -1024,14 +1022,14 @@ namespace lldb_private { void ClearCachedUserNames () { - Mutex::Locker locker (m_uid_map_mutex); + Mutex::Locker locker (m_mutex); m_uid_map.clear(); } const char * GetCachedGroupName (uint32_t gid) { - Mutex::Locker locker (m_gid_map_mutex); + Mutex::Locker locker (m_mutex); IDToNameMap::iterator pos = m_gid_map.find (gid); if (pos != m_gid_map.end()) { @@ -1047,7 +1045,7 @@ namespace lldb_private { const char * SetCachedGroupName (uint32_t gid, const char *name, size_t name_len) { - Mutex::Locker locker (m_gid_map_mutex); + Mutex::Locker locker (m_mutex); ConstString const_name (name); m_gid_map[gid] = const_name; if (m_max_gid_name_len < name_len) @@ -1059,14 +1057,14 @@ namespace lldb_private { void SetGroupNameNotFound (uint32_t gid) { - Mutex::Locker locker (m_gid_map_mutex); + Mutex::Locker locker (m_mutex); m_gid_map[gid] = ConstString(); } void ClearCachedGroupNames () { - Mutex::Locker locker (m_gid_map_mutex); + Mutex::Locker locker (m_mutex); m_gid_map.clear(); } diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index 5fb43c6d..5966466 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -1496,7 +1496,12 @@ PlatformDarwin::AddClangModuleCompilationOptionsForSDKType (Target *target, std: options.push_back(minimum_version_option.GetString()); } - FileSpec sysroot_spec = GetSDKDirectoryForModules(sdk_type); + FileSpec sysroot_spec; + // Scope for mutex locker below + { + Mutex::Locker locker (m_mutex); + sysroot_spec = GetSDKDirectoryForModules(sdk_type); + } if (sysroot_spec.IsDirectory()) { diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp index 83a8769..086e1a7 100644 --- a/lldb/source/Target/Platform.cpp +++ b/lldb/source/Target/Platform.cpp @@ -286,8 +286,7 @@ Platform::Platform (bool is_host) : m_minor_os_version (UINT32_MAX), m_update_os_version (UINT32_MAX), m_system_arch(), - m_uid_map_mutex (Mutex::eMutexTypeNormal), - m_gid_map_mutex (Mutex::eMutexTypeNormal), + m_mutex (Mutex::eMutexTypeRecursive), m_uid_map(), m_gid_map(), m_max_uid_name_len (0), @@ -299,8 +298,7 @@ Platform::Platform (bool is_host) : m_ssh_opts (), m_ignores_remote_hostname (false), m_trap_handlers(), - m_calculated_trap_handlers (false), - m_trap_handler_mutex() + m_calculated_trap_handlers (false) { Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); if (log) @@ -384,6 +382,8 @@ Platform::GetOSVersion (uint32_t &major, uint32_t &minor, uint32_t &update) { + Mutex::Locker locker (m_mutex); + bool success = m_major_os_version != UINT32_MAX; if (IsHost()) { @@ -1585,7 +1585,7 @@ Platform::GetTrapHandlerSymbolNames () { if (!m_calculated_trap_handlers) { - Mutex::Locker locker (m_trap_handler_mutex); + Mutex::Locker locker (m_mutex); if (!m_calculated_trap_handlers) { CalculateTrapHandlerSymbolNames(); -- 2.7.4