Lock NullFriendsData.m_Data for consistency and against concurrent read/write

0.7.3-extended
Justin Clark-Casey (justincc) 2012-03-30 01:23:34 +01:00
parent fbd61106cb
commit e2dade05d9
1 changed files with 39 additions and 30 deletions

View File

@ -29,6 +29,7 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using System.Threading;
using log4net; using log4net;
using OpenMetaverse; using OpenMetaverse;
using OpenSim.Framework; using OpenSim.Framework;
@ -54,7 +55,8 @@ namespace OpenSim.Data.Null
/// </remarks> /// </remarks>
public static void Clear() public static void Clear()
{ {
m_Data.Clear(); lock (m_Data)
m_Data.Clear();
} }
public FriendsData[] GetFriends(UUID principalID) public FriendsData[] GetFriends(UUID principalID)
@ -71,27 +73,30 @@ namespace OpenSim.Data.Null
/// <returns></returns> /// <returns></returns>
public FriendsData[] GetFriends(string userID) public FriendsData[] GetFriends(string userID)
{ {
List<FriendsData> lst = m_Data.FindAll(fdata => lock (m_Data)
{ {
return fdata.PrincipalID == userID.ToString(); List<FriendsData> lst = m_Data.FindAll(fdata =>
});
if (lst != null)
{
lst.ForEach(f =>
{ {
FriendsData f2 = m_Data.Find(candidateF2 => f.Friend == candidateF2.PrincipalID); return fdata.PrincipalID == userID.ToString();
if (f2 != null)
f.Data["TheirFlags"] = f2.Data["Flags"];
// m_log.DebugFormat(
// "[NULL FRIENDS DATA]: Got {0} {1} {2} for {3}",
// f.Friend, f.Data["Flags"], f2 != null ? f.Data["TheirFlags"] : "not found!", f.PrincipalID);
}); });
// m_log.DebugFormat("[NULL FRIENDS DATA]: Got {0} friends for {1}", lst.Count, userID); if (lst != null)
{
return lst.ToArray(); lst.ForEach(f =>
{
FriendsData f2 = m_Data.Find(candidateF2 => f.Friend == candidateF2.PrincipalID);
if (f2 != null)
f.Data["TheirFlags"] = f2.Data["Flags"];
// m_log.DebugFormat(
// "[NULL FRIENDS DATA]: Got {0} {1} {2} for {3}",
// f.Friend, f.Data["Flags"], f2 != null ? f.Data["TheirFlags"] : "not found!", f.PrincipalID);
});
// m_log.DebugFormat("[NULL FRIENDS DATA]: Got {0} friends for {1}", lst.Count, userID);
return lst.ToArray();
}
} }
return new FriendsData[0]; return new FriendsData[0];
@ -105,7 +110,8 @@ namespace OpenSim.Data.Null
// m_log.DebugFormat( // m_log.DebugFormat(
// "[NULL FRIENDS DATA]: Storing {0} {1} {2}", data.PrincipalID, data.Friend, data.Data["Flags"]); // "[NULL FRIENDS DATA]: Storing {0} {1} {2}", data.PrincipalID, data.Friend, data.Data["Flags"]);
m_Data.Add(data); lock (m_Data)
m_Data.Add(data);
return true; return true;
} }
@ -117,18 +123,21 @@ namespace OpenSim.Data.Null
public bool Delete(string userID, string friendID) public bool Delete(string userID, string friendID)
{ {
List<FriendsData> lst = m_Data.FindAll(delegate(FriendsData fdata) { return fdata.PrincipalID == userID.ToString(); }); lock (m_Data)
if (lst != null)
{ {
FriendsData friend = lst.Find(delegate(FriendsData fdata) { return fdata.Friend == friendID; }); List<FriendsData> lst = m_Data.FindAll(delegate(FriendsData fdata) { return fdata.PrincipalID == userID.ToString(); });
if (friendID != null) if (lst != null)
{ {
// m_log.DebugFormat( FriendsData friend = lst.Find(delegate(FriendsData fdata) { return fdata.Friend == friendID; });
// "[NULL FRIENDS DATA]: Deleting friend {0} {1} for {2}", if (friendID != null)
// friend.Friend, friend.Data["Flags"], friend.PrincipalID); {
// m_log.DebugFormat(
m_Data.Remove(friend); // "[NULL FRIENDS DATA]: Deleting friend {0} {1} for {2}",
return true; // friend.Friend, friend.Data["Flags"], friend.PrincipalID);
m_Data.Remove(friend);
return true;
}
} }
} }