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.cs87
1 files changed, 47 insertions, 40 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs
index 99971a5..9037c2a 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs
@@ -131,57 +131,64 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
131 QueueItemStruct BlankQIS = new QueueItemStruct(); 131 QueueItemStruct BlankQIS = new QueueItemStruct();
132 while (true) 132 while (true)
133 { 133 {
134 QueueItemStruct QIS = BlankQIS; 134 try
135 bool GotItem = false;
136
137 if (EventQueue.Count == 0)
138 {
139 // Nothing to do? Sleep a bit waiting for something to do
140 Thread.Sleep(NothingToDoSleepms);
141 }
142 else
143 { 135 {
144 // Something in queue, process 136 QueueItemStruct QIS = BlankQIS;
145 //myScriptEngine.m_logger.Verbose("ScriptEngine", "Processing event for localID: " + QIS.localID + ", itemID: " + QIS.itemID + ", FunctionName: " + QIS.FunctionName); 137 bool GotItem = false;
146 138
147 // OBJECT BASED LOCK - TWO THREADS WORKING ON SAME OBJECT IS NOT GOOD 139 if (EventQueue.Count == 0)
148 lock (QueueLock)
149 { 140 {
150 GotItem = false; 141 // Nothing to do? Sleep a bit waiting for something to do
151 for (int qc = 0; qc < EventQueue.Count; qc++) 142 Thread.Sleep(NothingToDoSleepms);
143 }
144 else
145 {
146 // Something in queue, process
147 //myScriptEngine.m_logger.Verbose("ScriptEngine", "Processing event for localID: " + QIS.localID + ", itemID: " + QIS.itemID + ", FunctionName: " + QIS.FunctionName);
148
149 // OBJECT BASED LOCK - TWO THREADS WORKING ON SAME OBJECT IS NOT GOOD
150 lock (QueueLock)
152 { 151 {
153 // Get queue item 152 GotItem = false;
154 QIS = EventQueue.Dequeue(); 153 for (int qc = 0; qc < EventQueue.Count; qc++)
154 {
155 // Get queue item
156 QIS = EventQueue.Dequeue();
157
158 // Check if object is being processed by someone else
159 if (TryLock(QIS.localID) == false)
160 {
161 // Object is already being processed, requeue it
162 EventQueue.Enqueue(QIS);
163 }
164 else
165 {
166 // We have lock on an object and can process it
167 GotItem = true;
168 break;
169 }
170 } // go through queue
171 } // lock
155 172
156 // Check if object is being processed by someone else 173 if (GotItem == true)
157 if (TryLock(QIS.localID) == false) 174 {
175 // Execute function
176 try
158 { 177 {
159 // Object is already being processed, requeue it 178 myScriptEngine.myScriptManager.ExecuteEvent(QIS.localID, QIS.itemID, QIS.FunctionName, QIS.param);
160 EventQueue.Enqueue(QIS);
161 } 179 }
162 else 180 finally
163 { 181 {
164 // We have lock on an object and can process it 182 ReleaseLock(QIS.localID);
165 GotItem = true;
166 break;
167 } 183 }
168 } // go through queue
169 } // lock
170
171 if (GotItem == true)
172 {
173 // Execute function
174 try
175 {
176 myScriptEngine.myScriptManager.ExecuteEvent(QIS.localID, QIS.itemID, QIS.FunctionName, QIS.param);
177 } 184 }
178 finally
179 {
180 ReleaseLock(QIS.localID);
181 }
182 }
183 185
184 } // Something in queue 186 } // Something in queue
187 } catch {ThreadAbortException tae) {
188 throw tae;
189 } catch (Exception e) {
190 Console.WriteLine("Exception in EventQueueThreadLoop: " + e.ToString());
191 }
185 } // while 192 } // while
186 } // try 193 } // try
187 catch (ThreadAbortException tae) 194 catch (ThreadAbortException tae)