aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs55
1 files changed, 31 insertions, 24 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs
index c2a4b88..3ef21db 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs
@@ -32,6 +32,7 @@ using System.Text;
32using System.Threading; 32using System.Threading;
33using System.Reflection; 33using System.Reflection;
34using OpenSim.Region.Environment.Scenes.Scripting; 34using OpenSim.Region.Environment.Scenes.Scripting;
35using libsecondlife;
35 36
36namespace OpenSim.Region.ScriptEngine.DotNetEngine 37namespace OpenSim.Region.ScriptEngine.DotNetEngine
37{ 38{
@@ -64,16 +65,16 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
64 /// </summary> 65 /// </summary>
65 private struct QueueItemStruct 66 private struct QueueItemStruct
66 { 67 {
67 public IScriptHost ObjectID; 68 public uint localID;
68 public string ScriptID; 69 public LLUUID itemID;
69 public string FunctionName; 70 public string FunctionName;
70 public object[] param; 71 public object[] param;
71 } 72 }
72 73
73 /// <summary> 74 /// <summary>
74 /// List of ObjectID locks for mutex processing of script events 75 /// List of localID locks for mutex processing of script events
75 /// </summary> 76 /// </summary>
76 private List<IScriptHost> ObjectLocks = new List<IScriptHost>(); 77 private List<uint> ObjectLocks = new List<uint>();
77 private object TryLockLock = new object(); // Mutex lock object 78 private object TryLockLock = new object(); // Mutex lock object
78 79
79 private ScriptEngine myScriptEngine; 80 private ScriptEngine myScriptEngine;
@@ -140,7 +141,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
140 else 141 else
141 { 142 {
142 // Something in queue, process 143 // Something in queue, process
143 //myScriptEngine.m_logger.Verbose("ScriptEngine", "Processing event for ObjectID: " + QIS.ObjectID + ", ScriptID: " + QIS.ScriptID + ", FunctionName: " + QIS.FunctionName); 144 //myScriptEngine.m_logger.Verbose("ScriptEngine", "Processing event for localID: " + QIS.localID + ", itemID: " + QIS.itemID + ", FunctionName: " + QIS.FunctionName);
144 145
145 // OBJECT BASED LOCK - TWO THREADS WORKING ON SAME OBJECT IS NOT GOOD 146 // OBJECT BASED LOCK - TWO THREADS WORKING ON SAME OBJECT IS NOT GOOD
146 lock (QueueLock) 147 lock (QueueLock)
@@ -152,7 +153,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
152 QIS = EventQueue.Dequeue(); 153 QIS = EventQueue.Dequeue();
153 154
154 // Check if object is being processed by someone else 155 // Check if object is being processed by someone else
155 if (TryLock(QIS.ObjectID) == false) 156 if (TryLock(QIS.localID) == false)
156 { 157 {
157 // Object is already being processed, requeue it 158 // Object is already being processed, requeue it
158 EventQueue.Enqueue(QIS); 159 EventQueue.Enqueue(QIS);
@@ -169,8 +170,14 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
169 if (GotItem == true) 170 if (GotItem == true)
170 { 171 {
171 // Execute function 172 // Execute function
172 myScriptEngine.myScriptManager.ExecuteEvent(QIS.ObjectID, QIS.ScriptID, QIS.FunctionName, QIS.param); 173 try
173 ReleaseLock(QIS.ObjectID); 174 {
175 myScriptEngine.myScriptManager.ExecuteEvent(QIS.localID, QIS.itemID, QIS.FunctionName, QIS.param);
176 }
177 finally
178 {
179 ReleaseLock(QIS.localID);
180 }
174 } 181 }
175 182
176 } // Something in queue 183 } // Something in queue
@@ -183,37 +190,37 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
183 } 190 }
184 191
185 /// <summary> 192 /// <summary>
186 /// Try to get a mutex lock on ObjectID 193 /// Try to get a mutex lock on localID
187 /// </summary> 194 /// </summary>
188 /// <param name="ObjectID"></param> 195 /// <param name="localID"></param>
189 /// <returns></returns> 196 /// <returns></returns>
190 private bool TryLock(IScriptHost ObjectID) 197 private bool TryLock(uint localID)
191 { 198 {
192 lock (TryLockLock) 199 lock (TryLockLock)
193 { 200 {
194 if (ObjectLocks.Contains(ObjectID) == true) 201 if (ObjectLocks.Contains(localID) == true)
195 { 202 {
196 return false; 203 return false;
197 } 204 }
198 else 205 else
199 { 206 {
200 ObjectLocks.Add(ObjectID); 207 ObjectLocks.Add(localID);
201 return true; 208 return true;
202 } 209 }
203 } 210 }
204 } 211 }
205 212
206 /// <summary> 213 /// <summary>
207 /// Release mutex lock on ObjectID 214 /// Release mutex lock on localID
208 /// </summary> 215 /// </summary>
209 /// <param name="ObjectID"></param> 216 /// <param name="localID"></param>
210 private void ReleaseLock(IScriptHost ObjectID) 217 private void ReleaseLock(uint localID)
211 { 218 {
212 lock (TryLockLock) 219 lock (TryLockLock)
213 { 220 {
214 if (ObjectLocks.Contains(ObjectID) == true) 221 if (ObjectLocks.Contains(localID) == true)
215 { 222 {
216 ObjectLocks.Remove(ObjectID); 223 ObjectLocks.Remove(localID);
217 } 224 }
218 } 225 }
219 } 226 }
@@ -221,26 +228,26 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
221 /// <summary> 228 /// <summary>
222 /// Add event to event execution queue 229 /// Add event to event execution queue
223 /// </summary> 230 /// </summary>
224 /// <param name="ObjectID"></param> 231 /// <param name="localID"></param>
225 /// <param name="FunctionName">Name of the function, will be state + "_event_" + FunctionName</param> 232 /// <param name="FunctionName">Name of the function, will be state + "_event_" + FunctionName</param>
226 /// <param name="param">Array of parameters to match event mask</param> 233 /// <param name="param">Array of parameters to match event mask</param>
227 public void AddToObjectQueue(IScriptHost ObjectID, string FunctionName, object[] param) 234 public void AddToObjectQueue(uint localID, string FunctionName, object[] param)
228 { 235 {
229 // Determine all scripts in Object and add to their queue 236 // Determine all scripts in Object and add to their queue
230 //myScriptEngine.m_logger.Verbose("ScriptEngine", "EventQueueManager Adding ObjectID: " + ObjectID + ", FunctionName: " + FunctionName); 237 //myScriptEngine.m_logger.Verbose("ScriptEngine", "EventQueueManager Adding localID: " + localID + ", FunctionName: " + FunctionName);
231 238
232 lock (QueueLock) 239 lock (QueueLock)
233 { 240 {
234 241
235 foreach (string ScriptID in myScriptEngine.myScriptManager.GetScriptKeys(ObjectID)) 242 foreach (LLUUID itemID in myScriptEngine.myScriptManager.GetScriptKeys(localID))
236 { 243 {
237 // Add to each script in that object 244 // Add to each script in that object
238 // TODO: Some scripts may not subscribe to this event. Should we NOT add it? Does it matter? 245 // TODO: Some scripts may not subscribe to this event. Should we NOT add it? Does it matter?
239 246
240 // Create a structure and add data 247 // Create a structure and add data
241 QueueItemStruct QIS = new QueueItemStruct(); 248 QueueItemStruct QIS = new QueueItemStruct();
242 QIS.ObjectID = ObjectID; 249 QIS.localID = localID;
243 QIS.ScriptID = ScriptID; 250 QIS.itemID = itemID;
244 QIS.FunctionName = FunctionName; 251 QIS.FunctionName = FunctionName;
245 QIS.param = param; 252 QIS.param = param;
246 253