From e14c8f59f7205ac010ed13387950647e5023b335 Mon Sep 17 00:00:00 2001
From: Tedd Hansen
Date: Fri, 1 Feb 2008 20:45:15 +0000
Subject: Added config options: ScriptThreadPriority to set script thread
priority DeactivateScriptOnTimeout to remove script if it is executing too
long
---
.../Common/ScriptEngineBase/EventQueueManager.cs | 5 ++-
.../ScriptEngineBase/EventQueueThreadClass.cs | 43 +++++++++++++++++++++-
2 files changed, 46 insertions(+), 2 deletions(-)
(limited to 'OpenSim/Region')
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs
index 6b2db35..d5826b7 100644
--- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs
+++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs
@@ -82,11 +82,13 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
///
private int numberOfThreads;
+
///
/// Maximum time one function can use for execution before we perform a thread kill
///
private int maxFunctionExecutionTimems;
private bool EnforceMaxExecutionTime;
+ private bool KillScriptOnMaxFunctionExecutionTime;
///
@@ -169,7 +171,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
maxFunctionExecutionTimems = m_ScriptEngine.ScriptConfigSource.GetInt("MaxEventExecutionTimeMs", 5000);
EnforceMaxExecutionTime = m_ScriptEngine.ScriptConfigSource.GetBoolean("EnforceMaxEventExecutionTime", false);
-
+ KillScriptOnMaxFunctionExecutionTime = m_ScriptEngine.ScriptConfigSource.GetBoolean("DeactivateScriptOnTimeout", false);
// Start function max exec time enforcement thread
@@ -336,6 +338,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
maxFunctionExecutionTimems)
{
// We need to kill this thread!
+ EventQueueThread.KillCurrentScript = KillScriptOnMaxFunctionExecutionTime;
AbortThreadClass(EventQueueThread);
// Then start another
StartNewThreadClass();
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueThreadClass.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueThreadClass.cs
index 67cf0e2..57caad5 100644
--- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueThreadClass.cs
+++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueThreadClass.cs
@@ -21,10 +21,12 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
public DateTime LastExecutionStarted;
public bool InExecution = false;
+ public bool KillCurrentScript = false;
private EventQueueManager eventQueueManager;
public Thread EventQueueThread;
private static int ThreadCount = 0;
+ private ThreadPriority MyThreadPriority;
public EventQueueThreadClass(EventQueueManager eqm)
{
@@ -43,9 +45,36 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
///
private void Start()
{
+ // Later with ScriptServer we might want to ask OS for stuff too, so doing this a bit manually
+ string pri = eventQueueManager.m_ScriptEngine.ScriptConfigSource.GetString("ScriptThreadPriority", "BelowNormal");
+ switch (pri.ToLower())
+ {
+ case "lowest":
+ MyThreadPriority = ThreadPriority.Lowest;
+ break;
+ case "belownormal":
+ MyThreadPriority = ThreadPriority.BelowNormal;
+ break;
+ case "normal":
+ MyThreadPriority = ThreadPriority.Normal;
+ break;
+ case "abovenormal":
+ MyThreadPriority = ThreadPriority.AboveNormal;
+ break;
+ case "highest":
+ MyThreadPriority = ThreadPriority.Highest;
+ break;
+ default:
+ MyThreadPriority = ThreadPriority.BelowNormal; // Default
+ eventQueueManager.m_ScriptEngine.Log.Error("ScriptEngineBase", "Unknown priority type \"" + pri + "\" in config file. Defaulting to \"BelowNormal\".");
+ break;
+ }
+
+
EventQueueThread = new Thread(EventQueueThreadLoop);
EventQueueThread.IsBackground = true;
- EventQueueThread.Priority = ThreadPriority.BelowNormal;
+
+ EventQueueThread.Priority = MyThreadPriority;
EventQueueThread.Name = "EventQueueManagerThread_" + ThreadCount;
EventQueueThread.Start();
@@ -134,6 +163,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
+ ", QIS.functionName: " + QIS.functionName);
#endif
LastExecutionStarted = DateTime.Now;
+ KillCurrentScript = false;
InExecution = true;
eventQueueManager.m_ScriptEngine.m_ScriptManager.ExecuteEvent(QIS.localID, QIS.itemID,
QIS.functionName, QIS.llDetectParams, QIS.param);
@@ -155,6 +185,9 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
// Send normal
text += e.Message.ToString();
}
+ if (KillCurrentScript)
+ text += "\r\nScript will be deactivated!";
+
try
{
if (text.Length > 1500)
@@ -174,6 +207,14 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
eventQueueManager.m_ScriptEngine.Log.Error("ScriptEngine",
"Unable to send text in-world:\r\n" + text);
}
+ finally
+ {
+ // So we are done sending message in-world
+ if (KillCurrentScript)
+ {
+ eventQueueManager.m_ScriptEngine.m_ScriptManager.RemoveScript(QIS.localID, QIS.itemID);
+ }
+ }
}
finally
{
--
cgit v1.1