From e992ca025571a891333a57012c2cd4419b6581e5 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Tue, 6 Oct 2009 15:39:53 -0700 Subject: Rewrote parts of the code that were double-locking different objects. This is about half of the code base reviewed. --- .../Cache/UserProfileCacheService.cs | 66 +++++++++------------- 1 file changed, 27 insertions(+), 39 deletions(-) (limited to 'OpenSim/Framework/Communications') diff --git a/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs b/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs index 9e12d948..b02cf5b 100644 --- a/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs +++ b/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs @@ -128,24 +128,18 @@ namespace OpenSim.Framework.Communications.Cache /// null if no user details are found 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; } /// @@ -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; } /// @@ -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 /// true if there was a profile to remove, false otherwise 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) + } + } + + if (userInfo != null) + lock (m_userProfilesByName) + { + if (m_userProfilesByName.ContainsKey(userInfo.UserProfile.Name)) { m_userProfilesByName.Remove(userInfo.UserProfile.Name); + return true; } - - return true; } - } return false; } -- cgit v1.1