aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs
diff options
context:
space:
mode:
authorTedd Hansen2007-09-13 11:11:08 +0000
committerTedd Hansen2007-09-13 11:11:08 +0000
commitcef8c5e9d7ce49cc47e7ef1816465064d889d6d5 (patch)
treeeb50e06403d1270b5eb6ce1456e2c9d44b3c6488 /OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs
parentBackup is now optional on classes (diff)
downloadopensim-SC-cef8c5e9d7ce49cc47e7ef1816465064d889d6d5.zip
opensim-SC-cef8c5e9d7ce49cc47e7ef1816465064d889d6d5.tar.gz
opensim-SC-cef8c5e9d7ce49cc47e7ef1816465064d889d6d5.tar.bz2
opensim-SC-cef8c5e9d7ce49cc47e7ef1816465064d889d6d5.tar.xz
Hiding evidence that I once was a VB coder (thanks to refactoring). Renamed member names to smallcapsy.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs72
1 files changed, 36 insertions, 36 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs
index dde0a77..3dc5d77 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs
@@ -47,20 +47,20 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
47 /// <summary> 47 /// <summary>
48 /// List of threads processing event queue 48 /// List of threads processing event queue
49 /// </summary> 49 /// </summary>
50 private List<Thread> EventQueueThreads = new List<Thread>(); 50 private List<Thread> eventQueueThreads = new List<Thread>();
51 private object QueueLock = new object(); // Mutex lock object 51 private object queueLock = new object(); // Mutex lock object
52 /// <summary> 52 /// <summary>
53 /// How many ms to sleep if queue is empty 53 /// How many ms to sleep if queue is empty
54 /// </summary> 54 /// </summary>
55 private int NothingToDoSleepms = 50; 55 private int nothingToDoSleepms = 50;
56 /// <summary> 56 /// <summary>
57 /// How many threads to process queue with 57 /// How many threads to process queue with
58 /// </summary> 58 /// </summary>
59 private int NumberOfThreads = 2; 59 private int numberOfThreads = 2;
60 /// <summary> 60 /// <summary>
61 /// Queue containing events waiting to be executed 61 /// Queue containing events waiting to be executed
62 /// </summary> 62 /// </summary>
63 private Queue<QueueItemStruct> EventQueue = new Queue<QueueItemStruct>(); 63 private Queue<QueueItemStruct> eventQueue = new Queue<QueueItemStruct>();
64 /// <summary> 64 /// <summary>
65 /// Queue item structure 65 /// Queue item structure
66 /// </summary> 66 /// </summary>
@@ -68,28 +68,28 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
68 { 68 {
69 public uint localID; 69 public uint localID;
70 public LLUUID itemID; 70 public LLUUID itemID;
71 public string FunctionName; 71 public string functionName;
72 public object[] param; 72 public object[] param;
73 } 73 }
74 74
75 /// <summary> 75 /// <summary>
76 /// List of localID locks for mutex processing of script events 76 /// List of localID locks for mutex processing of script events
77 /// </summary> 77 /// </summary>
78 private List<uint> ObjectLocks = new List<uint>(); 78 private List<uint> objectLocks = new List<uint>();
79 private object TryLockLock = new object(); // Mutex lock object 79 private object tryLockLock = new object(); // Mutex lock object
80 80
81 private ScriptEngine myScriptEngine; 81 private ScriptEngine m_ScriptEngine;
82 public EventQueueManager(ScriptEngine _ScriptEngine) 82 public EventQueueManager(ScriptEngine _ScriptEngine)
83 { 83 {
84 myScriptEngine = _ScriptEngine; 84 m_ScriptEngine = _ScriptEngine;
85 85
86 // 86 //
87 // Start event queue processing threads (worker threads) 87 // Start event queue processing threads (worker threads)
88 // 88 //
89 for (int ThreadCount = 0; ThreadCount <= NumberOfThreads; ThreadCount++) 89 for (int ThreadCount = 0; ThreadCount <= numberOfThreads; ThreadCount++)
90 { 90 {
91 Thread EventQueueThread = new Thread(EventQueueThreadLoop); 91 Thread EventQueueThread = new Thread(EventQueueThreadLoop);
92 EventQueueThreads.Add(EventQueueThread); 92 eventQueueThreads.Add(EventQueueThread);
93 EventQueueThread.IsBackground = true; 93 EventQueueThread.IsBackground = true;
94 EventQueueThread.Priority = ThreadPriority.BelowNormal; 94 EventQueueThread.Priority = ThreadPriority.BelowNormal;
95 EventQueueThread.Name = "EventQueueManagerThread_" + ThreadCount; 95 EventQueueThread.Name = "EventQueueManagerThread_" + ThreadCount;
@@ -100,7 +100,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
100 { 100 {
101 101
102 // Kill worker threads 102 // Kill worker threads
103 foreach (Thread EventQueueThread in new System.Collections.ArrayList(EventQueueThreads)) 103 foreach (Thread EventQueueThread in new System.Collections.ArrayList(eventQueueThreads))
104 { 104 {
105 if (EventQueueThread != null && EventQueueThread.IsAlive == true) 105 if (EventQueueThread != null && EventQueueThread.IsAlive == true)
106 { 106 {
@@ -115,9 +115,9 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
115 } 115 }
116 } 116 }
117 } 117 }
118 EventQueueThreads.Clear(); 118 eventQueueThreads.Clear();
119 // Todo: Clean up our queues 119 // Todo: Clean up our queues
120 EventQueue.Clear(); 120 eventQueue.Clear();
121 121
122 } 122 }
123 123
@@ -137,10 +137,10 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
137 QueueItemStruct QIS = BlankQIS; 137 QueueItemStruct QIS = BlankQIS;
138 bool GotItem = false; 138 bool GotItem = false;
139 139
140 if (EventQueue.Count == 0) 140 if (eventQueue.Count == 0)
141 { 141 {
142 // Nothing to do? Sleep a bit waiting for something to do 142 // Nothing to do? Sleep a bit waiting for something to do
143 Thread.Sleep(NothingToDoSleepms); 143 Thread.Sleep(nothingToDoSleepms);
144 } 144 }
145 else 145 else
146 { 146 {
@@ -148,19 +148,19 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
148 //myScriptEngine.m_logger.Verbose("ScriptEngine", "Processing event for localID: " + QIS.localID + ", itemID: " + QIS.itemID + ", FunctionName: " + QIS.FunctionName); 148 //myScriptEngine.m_logger.Verbose("ScriptEngine", "Processing event for localID: " + QIS.localID + ", itemID: " + QIS.itemID + ", FunctionName: " + QIS.FunctionName);
149 149
150 // OBJECT BASED LOCK - TWO THREADS WORKING ON SAME OBJECT IS NOT GOOD 150 // OBJECT BASED LOCK - TWO THREADS WORKING ON SAME OBJECT IS NOT GOOD
151 lock (QueueLock) 151 lock (queueLock)
152 { 152 {
153 GotItem = false; 153 GotItem = false;
154 for (int qc = 0; qc < EventQueue.Count; qc++) 154 for (int qc = 0; qc < eventQueue.Count; qc++)
155 { 155 {
156 // Get queue item 156 // Get queue item
157 QIS = EventQueue.Dequeue(); 157 QIS = eventQueue.Dequeue();
158 158
159 // Check if object is being processed by someone else 159 // Check if object is being processed by someone else
160 if (TryLock(QIS.localID) == false) 160 if (TryLock(QIS.localID) == false)
161 { 161 {
162 // Object is already being processed, requeue it 162 // Object is already being processed, requeue it
163 EventQueue.Enqueue(QIS); 163 eventQueue.Enqueue(QIS);
164 } 164 }
165 else 165 else
166 { 166 {
@@ -176,12 +176,12 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
176 // Execute function 176 // Execute function
177 try 177 try
178 { 178 {
179 myScriptEngine.myScriptManager.ExecuteEvent(QIS.localID, QIS.itemID, QIS.FunctionName, QIS.param); 179 m_ScriptEngine.m_ScriptManager.ExecuteEvent(QIS.localID, QIS.itemID, QIS.functionName, QIS.param);
180 } 180 }
181 catch (Exception e) 181 catch (Exception e)
182 { 182 {
183 // DISPLAY ERROR INWORLD 183 // DISPLAY ERROR INWORLD
184 string text = "Error executing script function \"" + QIS.FunctionName + "\":\r\n"; 184 string text = "Error executing script function \"" + QIS.functionName + "\":\r\n";
185 if (e.InnerException != null) 185 if (e.InnerException != null)
186 { // Send inner exception 186 { // Send inner exception
187 text += e.InnerException.Message.ToString(); 187 text += e.InnerException.Message.ToString();
@@ -194,10 +194,10 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
194 { 194 {
195 if (text.Length > 1500) 195 if (text.Length > 1500)
196 text = text.Substring(0, 1500); 196 text = text.Substring(0, 1500);
197 IScriptHost m_host = myScriptEngine.World.GetSceneObjectPart(QIS.localID); 197 IScriptHost m_host = m_ScriptEngine.World.GetSceneObjectPart(QIS.localID);
198 //if (m_host != null) 198 //if (m_host != null)
199 //{ 199 //{
200 myScriptEngine.World.SimChat(Helpers.StringToField(text), 1, m_host.AbsolutePosition, m_host.Name, m_host.UUID); 200 m_ScriptEngine.World.SimChat(Helpers.StringToField(text), 1, m_host.AbsolutePosition, m_host.Name, m_host.UUID);
201 } catch { 201 } catch {
202 //} 202 //}
203 //else 203 //else
@@ -234,15 +234,15 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
234 /// <returns></returns> 234 /// <returns></returns>
235 private bool TryLock(uint localID) 235 private bool TryLock(uint localID)
236 { 236 {
237 lock (TryLockLock) 237 lock (tryLockLock)
238 { 238 {
239 if (ObjectLocks.Contains(localID) == true) 239 if (objectLocks.Contains(localID) == true)
240 { 240 {
241 return false; 241 return false;
242 } 242 }
243 else 243 else
244 { 244 {
245 ObjectLocks.Add(localID); 245 objectLocks.Add(localID);
246 return true; 246 return true;
247 } 247 }
248 } 248 }
@@ -254,11 +254,11 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
254 /// <param name="localID"></param> 254 /// <param name="localID"></param>
255 private void ReleaseLock(uint localID) 255 private void ReleaseLock(uint localID)
256 { 256 {
257 lock (TryLockLock) 257 lock (tryLockLock)
258 { 258 {
259 if (ObjectLocks.Contains(localID) == true) 259 if (objectLocks.Contains(localID) == true)
260 { 260 {
261 ObjectLocks.Remove(localID); 261 objectLocks.Remove(localID);
262 } 262 }
263 } 263 }
264 } 264 }
@@ -277,13 +277,13 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
277 277
278 278
279 // Do we have any scripts in this object at all? If not, return 279 // Do we have any scripts in this object at all? If not, return
280 if (myScriptEngine.myScriptManager.Scripts.ContainsKey(localID) == false) 280 if (m_ScriptEngine.m_ScriptManager.Scripts.ContainsKey(localID) == false)
281 { 281 {
282 //Console.WriteLine("Event \"" + FunctionName + "\" for localID: " + localID + ". No scripts found on this localID."); 282 //Console.WriteLine("Event \"" + FunctionName + "\" for localID: " + localID + ". No scripts found on this localID.");
283 return; 283 return;
284 } 284 }
285 285
286 Dictionary<LLUUID, LSL_BaseClass>.KeyCollection scriptKeys = myScriptEngine.myScriptManager.GetScriptKeys(localID); 286 Dictionary<LLUUID, LSL_BaseClass>.KeyCollection scriptKeys = m_ScriptEngine.m_ScriptManager.GetScriptKeys(localID);
287 287
288 foreach ( LLUUID itemID in scriptKeys ) 288 foreach ( LLUUID itemID in scriptKeys )
289 { 289 {
@@ -303,17 +303,17 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
303 /// <param name="param">Array of parameters to match event mask</param> 303 /// <param name="param">Array of parameters to match event mask</param>
304 public void AddToScriptQueue(uint localID, LLUUID itemID, string FunctionName, object[] param) 304 public void AddToScriptQueue(uint localID, LLUUID itemID, string FunctionName, object[] param)
305 { 305 {
306 lock (QueueLock) 306 lock (queueLock)
307 { 307 {
308 // Create a structure and add data 308 // Create a structure and add data
309 QueueItemStruct QIS = new QueueItemStruct(); 309 QueueItemStruct QIS = new QueueItemStruct();
310 QIS.localID = localID; 310 QIS.localID = localID;
311 QIS.itemID = itemID; 311 QIS.itemID = itemID;
312 QIS.FunctionName = FunctionName; 312 QIS.functionName = FunctionName;
313 QIS.param = param; 313 QIS.param = param;
314 314
315 // Add it to queue 315 // Add it to queue
316 EventQueue.Enqueue(QIS); 316 eventQueue.Enqueue(QIS);
317 } 317 }
318 } 318 }
319 319