aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorUbitUmarov2019-04-01 13:58:41 +0100
committerUbitUmarov2019-04-01 13:58:41 +0100
commit7f55db72d2c2be3d0e3396dc8a4ba8ca1f504fd3 (patch)
tree0039d5e99e05308b48f965c080a03f4f30850520
parentstill issues on fast hg tps (diff)
downloadopensim-SC-7f55db72d2c2be3d0e3396dc8a4ba8ca1f504fd3.zip
opensim-SC-7f55db72d2c2be3d0e3396dc8a4ba8ca1f504fd3.tar.gz
opensim-SC-7f55db72d2c2be3d0e3396dc8a4ba8ca1f504fd3.tar.bz2
opensim-SC-7f55db72d2c2be3d0e3396dc8a4ba8ca1f504fd3.tar.xz
Yengine: try fix changing scripts running state if the have long events
-rw-r--r--OpenSim/Region/ScriptEngine/YEngine/XMREngine.cs27
-rw-r--r--OpenSim/Region/ScriptEngine/YEngine/XMRInstMisc.cs27
-rw-r--r--OpenSim/Region/ScriptEngine/YEngine/XMRInstRun.cs57
-rw-r--r--OpenSim/Region/ScriptEngine/YEngine/XMRScriptThread.cs8
4 files changed, 96 insertions, 23 deletions
diff --git a/OpenSim/Region/ScriptEngine/YEngine/XMREngine.cs b/OpenSim/Region/ScriptEngine/YEngine/XMREngine.cs
index 6acc293..e1f8c4c 100644
--- a/OpenSim/Region/ScriptEngine/YEngine/XMREngine.cs
+++ b/OpenSim/Region/ScriptEngine/YEngine/XMREngine.cs
@@ -1535,15 +1535,38 @@ namespace OpenSim.Region.ScriptEngine.Yengine
1535 */ 1535 */
1536 public void QueueToStart(XMRInstance inst) 1536 public void QueueToStart(XMRInstance inst)
1537 { 1537 {
1538 if(inst.m_IState != XMRInstState.ONSTARTQ) 1538 if (inst.m_IState != XMRInstState.ONSTARTQ)
1539 throw new Exception("bad state"); 1539 throw new Exception("bad state");
1540 1540
1541 lock(m_StartQueue) 1541 lock (m_StartQueue)
1542 m_StartQueue.InsertTail(inst); 1542 m_StartQueue.InsertTail(inst);
1543 1543
1544 WakeUpOne(); 1544 WakeUpOne();
1545 } 1545 }
1546 1546
1547 public void QueueToYield(XMRInstance inst)
1548 {
1549 if (inst.m_IState != XMRInstState.ONYIELDQ)
1550 throw new Exception("bad state");
1551
1552 lock (m_YieldQueue)
1553 m_YieldQueue.InsertTail(inst);
1554
1555 WakeUpOne();
1556 }
1557
1558 public void RemoveFromSleep(XMRInstance inst)
1559 {
1560 lock (m_SleepQueue)
1561 {
1562 if (inst.m_IState != XMRInstState.ONSLEEPQ)
1563 return;
1564
1565 m_SleepQueue.Remove(inst);
1566 inst.m_IState = XMRInstState.REMDFROMSLPQ;
1567 }
1568 }
1569
1547 /** 1570 /**
1548 * @brief A script may be sleeping, in which case we wake it. 1571 * @brief A script may be sleeping, in which case we wake it.
1549 */ 1572 */
diff --git a/OpenSim/Region/ScriptEngine/YEngine/XMRInstMisc.cs b/OpenSim/Region/ScriptEngine/YEngine/XMRInstMisc.cs
index 12feb7b..ff8dae5 100644
--- a/OpenSim/Region/ScriptEngine/YEngine/XMRInstMisc.cs
+++ b/OpenSim/Region/ScriptEngine/YEngine/XMRInstMisc.cs
@@ -363,8 +363,33 @@ namespace OpenSim.Region.ScriptEngine.Yengine
363 lock(m_QueueLock) 363 lock(m_QueueLock)
364 { 364 {
365 m_Running = value; 365 m_Running = value;
366 if(!value) 366 if(value)
367 { 367 {
368 if (m_IState == XMRInstState.SUSPENDED && m_SuspendCount == 0)
369 {
370 if(eventCode != ScriptEventCode.None)
371 {
372 m_IState = XMRInstState.ONYIELDQ;
373 m_Engine.QueueToYield(this);
374 }
375 else if ((m_EventQueue != null) && (m_EventQueue.First != null))
376 {
377 m_IState = XMRInstState.ONSTARTQ;
378 m_Engine.QueueToStart(this);
379 }
380 else
381 m_IState = XMRInstState.IDLE;
382 }
383 else if(m_SuspendCount != 0)
384 m_IState = XMRInstState.IDLE;
385 }
386 else
387 {
388 if(m_IState == XMRInstState.ONSLEEPQ)
389 {
390 m_Engine.RemoveFromSleep(this);
391 m_IState = XMRInstState.SUSPENDED;
392 }
368 EmptyEventQueues(); 393 EmptyEventQueues();
369 } 394 }
370 } 395 }
diff --git a/OpenSim/Region/ScriptEngine/YEngine/XMRInstRun.cs b/OpenSim/Region/ScriptEngine/YEngine/XMRInstRun.cs
index d237d2c..4f94c23 100644
--- a/OpenSim/Region/ScriptEngine/YEngine/XMRInstRun.cs
+++ b/OpenSim/Region/ScriptEngine/YEngine/XMRInstRun.cs
@@ -80,10 +80,21 @@ namespace OpenSim.Region.ScriptEngine.Yengine
80 !m_HaveEventHandlers[(int)evc]) // don't bother if we don't have such a handler in any state 80 !m_HaveEventHandlers[(int)evc]) // don't bother if we don't have such a handler in any state
81 return; 81 return;
82 82
83 // Not running means we ignore any incoming events. 83 // Not running means we ignore any incoming events.
84 // But queue if still constructing because m_Running is not yet valid. 84 // But queue if still constructing because m_Running is not yet valid.
85
85 if(!m_Running && !construct) 86 if(!m_Running && !construct)
87 {
88 if(m_IState == XMRInstState.SUSPENDED)
89 {
90 if(evc == ScriptEventCode.state_entry && m_EventQueue.Count == 0)
91 {
92 LinkedListNode<EventParams> llns = new LinkedListNode<EventParams>(evt);
93 m_EventQueue.AddFirst(llns);
94 }
95 }
86 return; 96 return;
97 }
87 98
88 if(m_minEventDelay != 0) 99 if(m_minEventDelay != 0)
89 { 100 {
@@ -250,13 +261,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine
250 return XMRInstState.SUSPENDED; 261 return XMRInstState.SUSPENDED;
251 } 262 }
252 263
253 // Make sure we aren't being migrated in or out and prevent that 264 // Make sure we aren't being migrated in or out and prevent that
254 // whilst we are in here. If migration has it locked, don't call 265 // whilst we are in here. If migration has it locked, don't call
255 // back right away, delay a bit so we don't get in infinite loop. 266 // back right away, delay a bit so we don't get in infinite loop.
256 m_RunOnePhase = "lock m_RunLock"; 267 m_RunOnePhase = "lock m_RunLock";
257 if(!Monitor.TryEnter(m_RunLock)) 268 if(!Monitor.TryEnter(m_RunLock))
258 { 269 {
259 m_SleepUntil = now.AddMilliseconds(3); 270 m_SleepUntil = now.AddMilliseconds(15);
260 m_RunOnePhase = "return was locked"; 271 m_RunOnePhase = "return was locked";
261 return XMRInstState.ONSLEEPQ; 272 return XMRInstState.ONSLEEPQ;
262 } 273 }
@@ -273,6 +284,12 @@ namespace OpenSim.Region.ScriptEngine.Yengine
273 return XMRInstState.DISPOSED; 284 return XMRInstState.DISPOSED;
274 } 285 }
275 286
287 if(!m_Running)
288 {
289 m_RunOnePhase = "return is not running";
290 return XMRInstState.SUSPENDED;
291 }
292
276 // Do some more of the last event if it didn't finish. 293 // Do some more of the last event if it didn't finish.
277 if(this.eventCode != ScriptEventCode.None) 294 if(this.eventCode != ScriptEventCode.None)
278 { 295 {
@@ -325,10 +342,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine
325 if(m_EventQueue.First != null) 342 if(m_EventQueue.First != null)
326 { 343 {
327 evt = m_EventQueue.First.Value; 344 evt = m_EventQueue.First.Value;
328 if(m_DetachQuantum > 0) 345 evc = (ScriptEventCode)Enum.Parse(typeof(ScriptEventCode), evt.EventName);
346 if (m_DetachQuantum > 0)
329 { 347 {
330 evc = (ScriptEventCode)Enum.Parse(typeof(ScriptEventCode),
331 evt.EventName);
332 if(evc != ScriptEventCode.attach) 348 if(evc != ScriptEventCode.attach)
333 { 349 {
334 // This is the case where the attach event 350 // This is the case where the attach event
@@ -343,8 +359,6 @@ namespace OpenSim.Region.ScriptEngine.Yengine
343 } 359 }
344 } 360 }
345 m_EventQueue.RemoveFirst(); 361 m_EventQueue.RemoveFirst();
346 evc = (ScriptEventCode)Enum.Parse(typeof(ScriptEventCode),
347 evt.EventName);
348 if((int)evc >= 0) 362 if((int)evc >= 0)
349 m_EventCounts[(int)evc]--; 363 m_EventCounts[(int)evc]--;
350 } 364 }
@@ -730,11 +744,14 @@ namespace OpenSim.Region.ScriptEngine.Yengine
730 case XMRInstState.DISPOSED: 744 case XMRInstState.DISPOSED:
731 return; 745 return;
732 746
733 // Some other thread is already resetting it, let it finish. 747 // Some other thread is already resetting it, let it finish.
734 748
735 case XMRInstState.RESETTING: 749 case XMRInstState.RESETTING:
736 return; 750 return;
737 751
752 case XMRInstState.SUSPENDED:
753 break;
754
738 default: 755 default:
739 throw new Exception("bad state"); 756 throw new Exception("bad state");
740 } 757 }
@@ -744,17 +761,21 @@ namespace OpenSim.Region.ScriptEngine.Yengine
744 { 761 {
745 CheckRunLockInvariants(true); 762 CheckRunLockInvariants(true);
746 763
747 // No other thread should have transitioned it from RESETTING. 764 // No other thread should have transitioned it from RESETTING.
748 if(m_IState != XMRInstState.RESETTING) 765 if (m_IState != XMRInstState.SUSPENDED)
749 throw new Exception("bad state"); 766 {
767 if (m_IState != XMRInstState.RESETTING)
768 throw new Exception("bad state");
750 769
751 // Mark it idle now so it can get queued to process new stuff. 770 m_IState = XMRInstState.IDLE;
752 m_IState = XMRInstState.IDLE; 771 }
753 772
754 // Reset everything and queue up default's start_entry() event. 773 // Reset everything and queue up default's start_entry() event.
755 ClearQueue(); 774 ClearQueue();
756 ResetLocked("external Reset"); 775 ResetLocked("external Reset");
757 776
777 // Mark it idle now so it can get queued to process new stuff.
778
758 CheckRunLockInvariants(true); 779 CheckRunLockInvariants(true);
759 } 780 }
760 } 781 }
diff --git a/OpenSim/Region/ScriptEngine/YEngine/XMRScriptThread.cs b/OpenSim/Region/ScriptEngine/YEngine/XMRScriptThread.cs
index 08c7e80..f68fd51 100644
--- a/OpenSim/Region/ScriptEngine/YEngine/XMRScriptThread.cs
+++ b/OpenSim/Region/ScriptEngine/YEngine/XMRScriptThread.cs
@@ -166,7 +166,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine
166 166
167 if(inst == null) 167 if(inst == null)
168 break; 168 break;
169 if(inst.m_IState != XMRInstState.ONSTARTQ) 169 if (inst.m_IState == XMRInstState.SUSPENDED)
170 continue;
171 if (inst.m_IState != XMRInstState.ONSTARTQ)
170 throw new Exception("bad state"); 172 throw new Exception("bad state");
171 RunInstance(inst, tid); 173 RunInstance(inst, tid);
172 if(m_SuspendScriptThreadFlag || m_Exiting) 174 if(m_SuspendScriptThreadFlag || m_Exiting)
@@ -187,7 +189,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine
187 189
188 if(inst != null) 190 if(inst != null)
189 { 191 {
190 if(inst.m_IState != XMRInstState.ONYIELDQ) 192 if (inst.m_IState == XMRInstState.SUSPENDED)
193 continue;
194 if (inst.m_IState != XMRInstState.ONYIELDQ)
191 throw new Exception("bad state"); 195 throw new Exception("bad state");
192 RunInstance(inst, tid); 196 RunInstance(inst, tid);
193 continue; 197 continue;