Lock m_classifiedCache and m_classifiedInterest dictionary reads in UserProfileModule since in the presence of writes these are not thread-safe operations.

Simplified locking to m_classifiedCache only since r/w of both dictionaries always occurs together
cpu-performance
Justin Clark-Casey (justincc) 2013-06-15 00:52:57 +01:00
parent 42b0c68eab
commit e6cb7b4764
1 changed files with 13 additions and 14 deletions

View File

@ -331,17 +331,16 @@ namespace OpenSim.Region.OptionalModules.Avatar.UserProfiles
classifieds[cid] = name; classifieds[cid] = name;
if (!m_classifiedCache.ContainsKey(cid)) lock (m_classifiedCache)
{ {
lock(m_classifiedCache) if (!m_classifiedCache.ContainsKey(cid))
{
m_classifiedCache.Add(cid,creatorId); m_classifiedCache.Add(cid,creatorId);
lock(m_classifiedInterest)
m_classifiedInterest.Add(cid, 0); m_classifiedInterest.Add(cid, 0);
} }
lock(m_classifiedInterest)
m_classifiedInterest[cid]++; m_classifiedInterest[cid]++;
}
} }
remoteClient.SendAvatarClassifiedReply(new UUID(args[0]), classifieds); remoteClient.SendAvatarClassifiedReply(new UUID(args[0]), classifieds);
@ -353,19 +352,19 @@ namespace OpenSim.Region.OptionalModules.Avatar.UserProfiles
UserClassifiedAdd ad = new UserClassifiedAdd(); UserClassifiedAdd ad = new UserClassifiedAdd();
ad.ClassifiedId = queryClassifiedID; ad.ClassifiedId = queryClassifiedID;
if (m_classifiedCache.ContainsKey(queryClassifiedID)) lock (m_classifiedCache)
{ {
target = m_classifiedCache[queryClassifiedID]; if (m_classifiedCache.ContainsKey(queryClassifiedID))
{
target = m_classifiedCache[queryClassifiedID];
lock(m_classifiedInterest)
m_classifiedInterest[queryClassifiedID] --; m_classifiedInterest[queryClassifiedID] --;
if(m_classifiedInterest[queryClassifiedID] == 0) if (m_classifiedInterest[queryClassifiedID] == 0)
{ {
lock(m_classifiedInterest)
m_classifiedInterest.Remove(queryClassifiedID); m_classifiedInterest.Remove(queryClassifiedID);
lock(m_classifiedCache)
m_classifiedCache.Remove(queryClassifiedID); m_classifiedCache.Remove(queryClassifiedID);
}
} }
} }