Rewrote parts of the code that were double-locking different objects. This is about half of the code base reviewed.

This commit is contained in:
Diva Canto
2009-10-06 15:39:53 -07:00
parent 99c85b5ef5
commit e992ca0255
9 changed files with 211 additions and 176 deletions

View File

@@ -128,24 +128,18 @@ namespace OpenSim.Framework.Communications.Cache
/// <returns>null if no user details are found</returns>
public CachedUserInfo GetUserDetails(string fname, string lname)
{
CachedUserInfo userInfo;
lock (m_userProfilesByName)
{
CachedUserInfo userInfo;
{
if (m_userProfilesByName.TryGetValue(string.Format(NAME_FORMAT, fname, lname), out userInfo))
{
return userInfo;
}
else
{
UserProfileData userProfile = m_commsManager.UserService.GetUserProfile(fname, lname);
if (userProfile != null)
return AddToCaches(userProfile);
else
return null;
}
}
UserProfileData userProfile = m_commsManager.UserService.GetUserProfile(fname, lname);
if (userProfile != null)
return AddToCaches(userProfile);
else
return null;
}
/// <summary>
@@ -160,20 +154,14 @@ namespace OpenSim.Framework.Communications.Cache
return null;
lock (m_userProfilesById)
{
if (m_userProfilesById.ContainsKey(userID))
{
return m_userProfilesById[userID];
}
else
{
UserProfileData userProfile = m_commsManager.UserService.GetUserProfile(userID);
if (userProfile != null)
return AddToCaches(userProfile);
else
return null;
}
}
UserProfileData userProfile = m_commsManager.UserService.GetUserProfile(userID);
if (userProfile != null)
return AddToCaches(userProfile);
else
return null;
}
/// <summary>
@@ -211,14 +199,10 @@ namespace OpenSim.Framework.Communications.Cache
CachedUserInfo createdUserInfo = new CachedUserInfo(m_InventoryService, userProfile);
lock (m_userProfilesById)
{
m_userProfilesById[createdUserInfo.UserProfile.ID] = createdUserInfo;
lock (m_userProfilesByName)
{
m_userProfilesByName[createdUserInfo.UserProfile.Name] = createdUserInfo;
}
}
lock (m_userProfilesByName)
m_userProfilesByName[createdUserInfo.UserProfile.Name] = createdUserInfo;
return createdUserInfo;
}
@@ -230,21 +214,25 @@ namespace OpenSim.Framework.Communications.Cache
/// <returns>true if there was a profile to remove, false otherwise</returns>
protected bool RemoveFromCaches(UUID userId)
{
CachedUserInfo userInfo = null;
lock (m_userProfilesById)
{
if (m_userProfilesById.ContainsKey(userId))
{
CachedUserInfo userInfo = m_userProfilesById[userId];
userInfo = m_userProfilesById[userId];
m_userProfilesById.Remove(userId);
lock (m_userProfilesByName)
{
m_userProfilesByName.Remove(userInfo.UserProfile.Name);
}
return true;
}
}
if (userInfo != null)
lock (m_userProfilesByName)
{
if (m_userProfilesByName.ContainsKey(userInfo.UserProfile.Name))
{
m_userProfilesByName.Remove(userInfo.UserProfile.Name);
return true;
}
}
return false;
}