aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs64
1 files changed, 38 insertions, 26 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs
index aa36ea2..d7491d9 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs
@@ -27,12 +27,11 @@
27*/ 27*/
28/* Original code: Tedd Hansen */ 28/* Original code: Tedd Hansen */
29using System; 29using System;
30using System.Collections;
30using System.Collections.Generic; 31using System.Collections.Generic;
31using System.Text;
32using System.Threading; 32using System.Threading;
33using System.Reflection;
34using OpenSim.Region.Environment.Scenes.Scripting;
35using libsecondlife; 33using libsecondlife;
34using OpenSim.Region.Environment.Scenes.Scripting;
36using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL; 35using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL;
37 36
38namespace OpenSim.Region.ScriptEngine.DotNetEngine 37namespace OpenSim.Region.ScriptEngine.DotNetEngine
@@ -42,25 +41,30 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
42 /// Events are queued and executed in separate thread 41 /// Events are queued and executed in separate thread
43 /// </summary> 42 /// </summary>
44 [Serializable] 43 [Serializable]
45 class EventQueueManager 44 internal class EventQueueManager
46 { 45 {
47 /// <summary> 46 /// <summary>
48 /// List of threads processing event queue 47 /// List of threads processing event queue
49 /// </summary> 48 /// </summary>
50 private List<Thread> eventQueueThreads = new List<Thread>(); 49 private List<Thread> eventQueueThreads = new List<Thread>();
50
51 private object queueLock = new object(); // Mutex lock object 51 private object queueLock = new object(); // Mutex lock object
52
52 /// <summary> 53 /// <summary>
53 /// How many ms to sleep if queue is empty 54 /// How many ms to sleep if queue is empty
54 /// </summary> 55 /// </summary>
55 private int nothingToDoSleepms = 50; 56 private int nothingToDoSleepms = 50;
57
56 /// <summary> 58 /// <summary>
57 /// How many threads to process queue with 59 /// How many threads to process queue with
58 /// </summary> 60 /// </summary>
59 private int numberOfThreads = 2; 61 private int numberOfThreads = 2;
62
60 /// <summary> 63 /// <summary>
61 /// Queue containing events waiting to be executed 64 /// Queue containing events waiting to be executed
62 /// </summary> 65 /// </summary>
63 private Queue<QueueItemStruct> eventQueue = new Queue<QueueItemStruct>(); 66 private Queue<QueueItemStruct> eventQueue = new Queue<QueueItemStruct>();
67
64 /// <summary> 68 /// <summary>
65 /// Queue item structure 69 /// Queue item structure
66 /// </summary> 70 /// </summary>
@@ -76,9 +80,11 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
76 /// List of localID locks for mutex processing of script events 80 /// List of localID locks for mutex processing of script events
77 /// </summary> 81 /// </summary>
78 private List<uint> objectLocks = new List<uint>(); 82 private List<uint> objectLocks = new List<uint>();
83
79 private object tryLockLock = new object(); // Mutex lock object 84 private object tryLockLock = new object(); // Mutex lock object
80 85
81 private ScriptEngine m_ScriptEngine; 86 private ScriptEngine m_ScriptEngine;
87
82 public EventQueueManager(ScriptEngine _ScriptEngine) 88 public EventQueueManager(ScriptEngine _ScriptEngine)
83 { 89 {
84 m_ScriptEngine = _ScriptEngine; 90 m_ScriptEngine = _ScriptEngine;
@@ -96,11 +102,11 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
96 EventQueueThread.Start(); 102 EventQueueThread.Start();
97 } 103 }
98 } 104 }
105
99 ~EventQueueManager() 106 ~EventQueueManager()
100 { 107 {
101
102 // Kill worker threads 108 // Kill worker threads
103 foreach (Thread EventQueueThread in new System.Collections.ArrayList(eventQueueThreads)) 109 foreach (Thread EventQueueThread in new ArrayList(eventQueueThreads))
104 { 110 {
105 if (EventQueueThread != null && EventQueueThread.IsAlive == true) 111 if (EventQueueThread != null && EventQueueThread.IsAlive == true)
106 { 112 {
@@ -118,7 +124,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
118 eventQueueThreads.Clear(); 124 eventQueueThreads.Clear();
119 // Todo: Clean up our queues 125 // Todo: Clean up our queues
120 eventQueue.Clear(); 126 eventQueue.Clear();
121
122 } 127 }
123 128
124 /// <summary> 129 /// <summary>
@@ -176,18 +181,21 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
176 // Execute function 181 // Execute function
177 try 182 try
178 { 183 {
179 m_ScriptEngine.m_ScriptManager.ExecuteEvent(QIS.localID, QIS.itemID, QIS.functionName, QIS.param); 184 m_ScriptEngine.m_ScriptManager.ExecuteEvent(QIS.localID, QIS.itemID,
185 QIS.functionName, QIS.param);
180 } 186 }
181 catch (Exception e) 187 catch (Exception e)
182 { 188 {
183 // DISPLAY ERROR INWORLD 189 // DISPLAY ERROR INWORLD
184 string text = "Error executing script function \"" + QIS.functionName + "\":\r\n"; 190 string text = "Error executing script function \"" + QIS.functionName + "\":\r\n";
185 if (e.InnerException != null) 191 if (e.InnerException != null)
186 { // Send inner exception 192 {
193 // Send inner exception
187 text += e.InnerException.Message.ToString(); 194 text += e.InnerException.Message.ToString();
188 } 195 }
189 else 196 else
190 { // Send normal 197 {
198 // Send normal
191 text += e.Message.ToString(); 199 text += e.Message.ToString();
192 } 200 }
193 try 201 try
@@ -195,28 +203,33 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
195 if (text.Length > 1500) 203 if (text.Length > 1500)
196 text = text.Substring(0, 1500); 204 text = text.Substring(0, 1500);
197 IScriptHost m_host = m_ScriptEngine.World.GetSceneObjectPart(QIS.localID); 205 IScriptHost m_host = m_ScriptEngine.World.GetSceneObjectPart(QIS.localID);
198 //if (m_host != null) 206 //if (m_host != null)
199 //{ 207 //{
200 m_ScriptEngine.World.SimChat(Helpers.StringToField(text), 1, 0, m_host.AbsolutePosition, m_host.Name, m_host.UUID); 208 m_ScriptEngine.World.SimChat(Helpers.StringToField(text), 1, 0,
201 } catch { 209 m_host.AbsolutePosition, m_host.Name, m_host.UUID);
202 //} 210 }
203 //else 211 catch
204 //{ 212 {
213 //}
214 //else
215 //{
205 // T oconsole 216 // T oconsole
206 Console.WriteLine("Unable to send text in-world:\r\n" + text); 217 Console.WriteLine("Unable to send text in-world:\r\n" + text);
207 } 218 }
208
209 } 219 }
210 finally 220 finally
211 { 221 {
212 ReleaseLock(QIS.localID); 222 ReleaseLock(QIS.localID);
213 } 223 }
214 } 224 }
215
216 } // Something in queue 225 } // Something in queue
217 } catch (ThreadAbortException tae) { 226 }
227 catch (ThreadAbortException tae)
228 {
218 throw tae; 229 throw tae;
219 } catch (Exception e) { 230 }
231 catch (Exception e)
232 {
220 Console.WriteLine("Exception in EventQueueThreadLoop: " + e.ToString()); 233 Console.WriteLine("Exception in EventQueueThreadLoop: " + e.ToString());
221 } 234 }
222 } // while 235 } // while
@@ -283,15 +296,15 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
283 return; 296 return;
284 } 297 }
285 298
286 Dictionary<LLUUID, LSL_BaseClass>.KeyCollection scriptKeys = m_ScriptEngine.m_ScriptManager.GetScriptKeys(localID); 299 Dictionary<LLUUID, LSL_BaseClass>.KeyCollection scriptKeys =
300 m_ScriptEngine.m_ScriptManager.GetScriptKeys(localID);
287 301
288 foreach ( LLUUID itemID in scriptKeys ) 302 foreach (LLUUID itemID in scriptKeys)
289 { 303 {
290 // Add to each script in that object 304 // Add to each script in that object
291 // TODO: Some scripts may not subscribe to this event. Should we NOT add it? Does it matter? 305 // TODO: Some scripts may not subscribe to this event. Should we NOT add it? Does it matter?
292 AddToScriptQueue(localID, itemID, FunctionName, param); 306 AddToScriptQueue(localID, itemID, FunctionName, param);
293 } 307 }
294
295 } 308 }
296 309
297 /// <summary> 310 /// <summary>
@@ -316,6 +329,5 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
316 eventQueue.Enqueue(QIS); 329 eventQueue.Enqueue(QIS);
317 } 330 }
318 } 331 }
319
320 } 332 }
321} 333} \ No newline at end of file