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

0.7.4.1
Justin Clark-Casey (justincc) 2012-03-30 01:23:34 +01:00
parent bce7964ac2
commit 1ef62ca75e
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,6 +55,7 @@ namespace OpenSim.Data.Null
/// </remarks> /// </remarks>
public static void Clear() public static void Clear()
{ {
lock (m_Data)
m_Data.Clear(); m_Data.Clear();
} }
@ -70,6 +72,8 @@ namespace OpenSim.Data.Null
/// <param name="values"></param> /// <param name="values"></param>
/// <returns></returns> /// <returns></returns>
public FriendsData[] GetFriends(string userID) public FriendsData[] GetFriends(string userID)
{
lock (m_Data)
{ {
List<FriendsData> lst = m_Data.FindAll(fdata => List<FriendsData> lst = m_Data.FindAll(fdata =>
{ {
@ -93,6 +97,7 @@ namespace OpenSim.Data.Null
return lst.ToArray(); return lst.ToArray();
} }
}
return new FriendsData[0]; return new FriendsData[0];
} }
@ -105,6 +110,7 @@ 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"]);
lock (m_Data)
m_Data.Add(data); m_Data.Add(data);
return true; return true;
@ -116,6 +122,8 @@ namespace OpenSim.Data.Null
} }
public bool Delete(string userID, string friendID) public bool Delete(string userID, string friendID)
{
lock (m_Data)
{ {
List<FriendsData> lst = m_Data.FindAll(delegate(FriendsData fdata) { return fdata.PrincipalID == userID.ToString(); }); List<FriendsData> lst = m_Data.FindAll(delegate(FriendsData fdata) { return fdata.PrincipalID == userID.ToString(); });
if (lst != null) if (lst != null)
@ -131,6 +139,7 @@ namespace OpenSim.Data.Null
return true; return true;
} }
} }
}
return false; return false;
} }