diff options
author | Tedd Hansen | 2008-02-01 20:45:15 +0000 |
---|---|---|
committer | Tedd Hansen | 2008-02-01 20:45:15 +0000 |
commit | e14c8f59f7205ac010ed13387950647e5023b335 (patch) | |
tree | 2a4be137508c4114c289d960926f95c732c8110e /OpenSim/Region/ScriptEngine/Common | |
parent | Removed "Loading inventory for Primitive" message. (diff) | |
download | opensim-SC-e14c8f59f7205ac010ed13387950647e5023b335.zip opensim-SC-e14c8f59f7205ac010ed13387950647e5023b335.tar.gz opensim-SC-e14c8f59f7205ac010ed13387950647e5023b335.tar.bz2 opensim-SC-e14c8f59f7205ac010ed13387950647e5023b335.tar.xz |
Added config options:
ScriptThreadPriority to set script thread priority
DeactivateScriptOnTimeout to remove script if it is executing too long
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Common')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs | 5 | ||||
-rw-r--r-- | OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueThreadClass.cs | 43 |
2 files changed, 46 insertions, 2 deletions
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 | |||
82 | /// </summary> | 82 | /// </summary> |
83 | private int numberOfThreads; | 83 | private int numberOfThreads; |
84 | 84 | ||
85 | |||
85 | /// <summary> | 86 | /// <summary> |
86 | /// Maximum time one function can use for execution before we perform a thread kill | 87 | /// Maximum time one function can use for execution before we perform a thread kill |
87 | /// </summary> | 88 | /// </summary> |
88 | private int maxFunctionExecutionTimems; | 89 | private int maxFunctionExecutionTimems; |
89 | private bool EnforceMaxExecutionTime; | 90 | private bool EnforceMaxExecutionTime; |
91 | private bool KillScriptOnMaxFunctionExecutionTime; | ||
90 | 92 | ||
91 | 93 | ||
92 | /// <summary> | 94 | /// <summary> |
@@ -169,7 +171,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
169 | 171 | ||
170 | maxFunctionExecutionTimems = m_ScriptEngine.ScriptConfigSource.GetInt("MaxEventExecutionTimeMs", 5000); | 172 | maxFunctionExecutionTimems = m_ScriptEngine.ScriptConfigSource.GetInt("MaxEventExecutionTimeMs", 5000); |
171 | EnforceMaxExecutionTime = m_ScriptEngine.ScriptConfigSource.GetBoolean("EnforceMaxEventExecutionTime", false); | 173 | EnforceMaxExecutionTime = m_ScriptEngine.ScriptConfigSource.GetBoolean("EnforceMaxEventExecutionTime", false); |
172 | 174 | KillScriptOnMaxFunctionExecutionTime = m_ScriptEngine.ScriptConfigSource.GetBoolean("DeactivateScriptOnTimeout", false); | |
173 | 175 | ||
174 | 176 | ||
175 | // Start function max exec time enforcement thread | 177 | // Start function max exec time enforcement thread |
@@ -336,6 +338,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
336 | maxFunctionExecutionTimems) | 338 | maxFunctionExecutionTimems) |
337 | { | 339 | { |
338 | // We need to kill this thread! | 340 | // We need to kill this thread! |
341 | EventQueueThread.KillCurrentScript = KillScriptOnMaxFunctionExecutionTime; | ||
339 | AbortThreadClass(EventQueueThread); | 342 | AbortThreadClass(EventQueueThread); |
340 | // Then start another | 343 | // Then start another |
341 | StartNewThreadClass(); | 344 | 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 | |||
21 | 21 | ||
22 | public DateTime LastExecutionStarted; | 22 | public DateTime LastExecutionStarted; |
23 | public bool InExecution = false; | 23 | public bool InExecution = false; |
24 | public bool KillCurrentScript = false; | ||
24 | 25 | ||
25 | private EventQueueManager eventQueueManager; | 26 | private EventQueueManager eventQueueManager; |
26 | public Thread EventQueueThread; | 27 | public Thread EventQueueThread; |
27 | private static int ThreadCount = 0; | 28 | private static int ThreadCount = 0; |
29 | private ThreadPriority MyThreadPriority; | ||
28 | 30 | ||
29 | public EventQueueThreadClass(EventQueueManager eqm) | 31 | public EventQueueThreadClass(EventQueueManager eqm) |
30 | { | 32 | { |
@@ -43,9 +45,36 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
43 | /// </summary> | 45 | /// </summary> |
44 | private void Start() | 46 | private void Start() |
45 | { | 47 | { |
48 | // Later with ScriptServer we might want to ask OS for stuff too, so doing this a bit manually | ||
49 | string pri = eventQueueManager.m_ScriptEngine.ScriptConfigSource.GetString("ScriptThreadPriority", "BelowNormal"); | ||
50 | switch (pri.ToLower()) | ||
51 | { | ||
52 | case "lowest": | ||
53 | MyThreadPriority = ThreadPriority.Lowest; | ||
54 | break; | ||
55 | case "belownormal": | ||
56 | MyThreadPriority = ThreadPriority.BelowNormal; | ||
57 | break; | ||
58 | case "normal": | ||
59 | MyThreadPriority = ThreadPriority.Normal; | ||
60 | break; | ||
61 | case "abovenormal": | ||
62 | MyThreadPriority = ThreadPriority.AboveNormal; | ||
63 | break; | ||
64 | case "highest": | ||
65 | MyThreadPriority = ThreadPriority.Highest; | ||
66 | break; | ||
67 | default: | ||
68 | MyThreadPriority = ThreadPriority.BelowNormal; // Default | ||
69 | eventQueueManager.m_ScriptEngine.Log.Error("ScriptEngineBase", "Unknown priority type \"" + pri + "\" in config file. Defaulting to \"BelowNormal\"."); | ||
70 | break; | ||
71 | } | ||
72 | |||
73 | |||
46 | EventQueueThread = new Thread(EventQueueThreadLoop); | 74 | EventQueueThread = new Thread(EventQueueThreadLoop); |
47 | EventQueueThread.IsBackground = true; | 75 | EventQueueThread.IsBackground = true; |
48 | EventQueueThread.Priority = ThreadPriority.BelowNormal; | 76 | |
77 | EventQueueThread.Priority = MyThreadPriority; | ||
49 | EventQueueThread.Name = "EventQueueManagerThread_" + ThreadCount; | 78 | EventQueueThread.Name = "EventQueueManagerThread_" + ThreadCount; |
50 | EventQueueThread.Start(); | 79 | EventQueueThread.Start(); |
51 | 80 | ||
@@ -134,6 +163,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
134 | + ", QIS.functionName: " + QIS.functionName); | 163 | + ", QIS.functionName: " + QIS.functionName); |
135 | #endif | 164 | #endif |
136 | LastExecutionStarted = DateTime.Now; | 165 | LastExecutionStarted = DateTime.Now; |
166 | KillCurrentScript = false; | ||
137 | InExecution = true; | 167 | InExecution = true; |
138 | eventQueueManager.m_ScriptEngine.m_ScriptManager.ExecuteEvent(QIS.localID, QIS.itemID, | 168 | eventQueueManager.m_ScriptEngine.m_ScriptManager.ExecuteEvent(QIS.localID, QIS.itemID, |
139 | QIS.functionName, QIS.llDetectParams, QIS.param); | 169 | QIS.functionName, QIS.llDetectParams, QIS.param); |
@@ -155,6 +185,9 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
155 | // Send normal | 185 | // Send normal |
156 | text += e.Message.ToString(); | 186 | text += e.Message.ToString(); |
157 | } | 187 | } |
188 | if (KillCurrentScript) | ||
189 | text += "\r\nScript will be deactivated!"; | ||
190 | |||
158 | try | 191 | try |
159 | { | 192 | { |
160 | if (text.Length > 1500) | 193 | if (text.Length > 1500) |
@@ -174,6 +207,14 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
174 | eventQueueManager.m_ScriptEngine.Log.Error("ScriptEngine", | 207 | eventQueueManager.m_ScriptEngine.Log.Error("ScriptEngine", |
175 | "Unable to send text in-world:\r\n" + text); | 208 | "Unable to send text in-world:\r\n" + text); |
176 | } | 209 | } |
210 | finally | ||
211 | { | ||
212 | // So we are done sending message in-world | ||
213 | if (KillCurrentScript) | ||
214 | { | ||
215 | eventQueueManager.m_ScriptEngine.m_ScriptManager.RemoveScript(QIS.localID, QIS.itemID); | ||
216 | } | ||
217 | } | ||
177 | } | 218 | } |
178 | finally | 219 | finally |
179 | { | 220 | { |