aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-03-30 01:23:34 +0100
committerJustin Clark-Casey (justincc)2012-03-30 01:23:34 +0100
commit1ef62ca75ef8c551303b4e86e737b5d958d07ce7 (patch)
tree0e3085c8b31634edb963bbbd0b095c32fd808ab3
parentrefactor: Move "friends show cache" console command out into separate Friends... (diff)
downloadopensim-SC_OLD-1ef62ca75ef8c551303b4e86e737b5d958d07ce7.zip
opensim-SC_OLD-1ef62ca75ef8c551303b4e86e737b5d958d07ce7.tar.gz
opensim-SC_OLD-1ef62ca75ef8c551303b4e86e737b5d958d07ce7.tar.bz2
opensim-SC_OLD-1ef62ca75ef8c551303b4e86e737b5d958d07ce7.tar.xz
Lock NullFriendsData.m_Data for consistency and against concurrent read/write
-rw-r--r--OpenSim/Data/Null/NullFriendsData.cs69
1 files changed, 39 insertions, 30 deletions
diff --git a/OpenSim/Data/Null/NullFriendsData.cs b/OpenSim/Data/Null/NullFriendsData.cs
index 0be32a4..473999f 100644
--- a/OpenSim/Data/Null/NullFriendsData.cs
+++ b/OpenSim/Data/Null/NullFriendsData.cs
@@ -29,6 +29,7 @@ using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Reflection; 31using System.Reflection;
32using System.Threading;
32using log4net; 33using log4net;
33using OpenMetaverse; 34using OpenMetaverse;
34using OpenSim.Framework; 35using OpenSim.Framework;
@@ -54,7 +55,8 @@ namespace OpenSim.Data.Null
54 /// </remarks> 55 /// </remarks>
55 public static void Clear() 56 public static void Clear()
56 { 57 {
57 m_Data.Clear(); 58 lock (m_Data)
59 m_Data.Clear();
58 } 60 }
59 61
60 public FriendsData[] GetFriends(UUID principalID) 62 public FriendsData[] GetFriends(UUID principalID)
@@ -71,27 +73,30 @@ namespace OpenSim.Data.Null
71 /// <returns></returns> 73 /// <returns></returns>
72 public FriendsData[] GetFriends(string userID) 74 public FriendsData[] GetFriends(string userID)
73 { 75 {
74 List<FriendsData> lst = m_Data.FindAll(fdata => 76 lock (m_Data)
75 { 77 {
76 return fdata.PrincipalID == userID.ToString(); 78 List<FriendsData> lst = m_Data.FindAll(fdata =>
77 });
78
79 if (lst != null)
80 {
81 lst.ForEach(f =>
82 { 79 {
83 FriendsData f2 = m_Data.Find(candidateF2 => f.Friend == candidateF2.PrincipalID); 80 return fdata.PrincipalID == userID.ToString();
84 if (f2 != null)
85 f.Data["TheirFlags"] = f2.Data["Flags"];
86
87// m_log.DebugFormat(
88// "[NULL FRIENDS DATA]: Got {0} {1} {2} for {3}",
89// f.Friend, f.Data["Flags"], f2 != null ? f.Data["TheirFlags"] : "not found!", f.PrincipalID);
90 }); 81 });
91 82
92// m_log.DebugFormat("[NULL FRIENDS DATA]: Got {0} friends for {1}", lst.Count, userID); 83 if (lst != null)
93 84 {
94 return lst.ToArray(); 85 lst.ForEach(f =>
86 {
87 FriendsData f2 = m_Data.Find(candidateF2 => f.Friend == candidateF2.PrincipalID);
88 if (f2 != null)
89 f.Data["TheirFlags"] = f2.Data["Flags"];
90
91 // m_log.DebugFormat(
92 // "[NULL FRIENDS DATA]: Got {0} {1} {2} for {3}",
93 // f.Friend, f.Data["Flags"], f2 != null ? f.Data["TheirFlags"] : "not found!", f.PrincipalID);
94 });
95
96 // m_log.DebugFormat("[NULL FRIENDS DATA]: Got {0} friends for {1}", lst.Count, userID);
97
98 return lst.ToArray();
99 }
95 } 100 }
96 101
97 return new FriendsData[0]; 102 return new FriendsData[0];
@@ -105,7 +110,8 @@ namespace OpenSim.Data.Null
105// m_log.DebugFormat( 110// m_log.DebugFormat(
106// "[NULL FRIENDS DATA]: Storing {0} {1} {2}", data.PrincipalID, data.Friend, data.Data["Flags"]); 111// "[NULL FRIENDS DATA]: Storing {0} {1} {2}", data.PrincipalID, data.Friend, data.Data["Flags"]);
107 112
108 m_Data.Add(data); 113 lock (m_Data)
114 m_Data.Add(data);
109 115
110 return true; 116 return true;
111 } 117 }
@@ -117,18 +123,21 @@ namespace OpenSim.Data.Null
117 123
118 public bool Delete(string userID, string friendID) 124 public bool Delete(string userID, string friendID)
119 { 125 {
120 List<FriendsData> lst = m_Data.FindAll(delegate(FriendsData fdata) { return fdata.PrincipalID == userID.ToString(); }); 126 lock (m_Data)
121 if (lst != null)
122 { 127 {
123 FriendsData friend = lst.Find(delegate(FriendsData fdata) { return fdata.Friend == friendID; }); 128 List<FriendsData> lst = m_Data.FindAll(delegate(FriendsData fdata) { return fdata.PrincipalID == userID.ToString(); });
124 if (friendID != null) 129 if (lst != null)
125 { 130 {
126// m_log.DebugFormat( 131 FriendsData friend = lst.Find(delegate(FriendsData fdata) { return fdata.Friend == friendID; });
127// "[NULL FRIENDS DATA]: Deleting friend {0} {1} for {2}", 132 if (friendID != null)
128// friend.Friend, friend.Data["Flags"], friend.PrincipalID); 133 {
129 134 // m_log.DebugFormat(
130 m_Data.Remove(friend); 135 // "[NULL FRIENDS DATA]: Deleting friend {0} {1} for {2}",
131 return true; 136 // friend.Friend, friend.Data["Flags"], friend.PrincipalID);
137
138 m_Data.Remove(friend);
139 return true;
140 }
132 } 141 }
133 } 142 }
134 143