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: <rdar://problem/19575304>

llvm-svn: 227855
This commit is contained in:
Greg Clayton 2015-02-02 20:45:17 +00:00
parent 49a766e468
commit 7597b353b3
3 changed files with 20 additions and 17 deletions

View File

@ -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<uint32_t, ConstString> 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<ConstString> 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();
}

View File

@ -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())
{

View File

@ -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();