From a6726b0c9de4ef875348f9dcbf21a9c93bde8a09 Mon Sep 17 00:00:00 2001
From: Tedd Hansen
Date: Fri, 1 Feb 2008 22:18:55 +0000
Subject: SCRIPT SUPPORT IS STILL BROKEN. Bugfix: Scripts exceeding max and set
to be killed were not killed, only removed. Added ability to re-read
configuration while OpenSim is running All regions now sharing one
MaintenanceThread New MaintenanceThread: - checks for script execution
timeout - re-reads config - starts/stops threads if thread active count
becomes too high/low compared to config Speed increase on event execution: -
Reuse of try{}catch{} blocks - Time calculation on event execution
---
.../Common/ScriptEngineBase/EventQueueManager.cs | 242 +++++++++++++--------
.../ScriptEngineBase/EventQueueThreadClass.cs | 220 +++++++++++--------
.../Common/ScriptEngineBase/MaintenanceThread.cs | 127 +++++++++++
.../Common/ScriptEngineBase/ScriptEngine.cs | 12 +
4 files changed, 412 insertions(+), 189 deletions(-)
create mode 100644 OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs
(limited to 'OpenSim/Region/ScriptEngine/Common')
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs
index d5826b7..04c084a 100644
--- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs
+++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs
@@ -65,12 +65,26 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
// increase number of threads to allow more concurrent script executions in OpenSim.
//
+ public ScriptEngine m_ScriptEngine;
+
+ ///
+ /// List of threads (classes) processing event queue
+ ///
+ internal List eventQueueThreads;
+ ///
+ /// Global static list of threads (classes) processing event queue -- used by max enforcment thread
+ ///
+ private List staticGlobalEventQueueThreads;
+ ///
+ /// Locking access to eventQueueThreads AND staticGlobalEventQueueThreads. Note that this may or may not be static depending on PrivateRegionThreads config setting.
+ ///
+ private object eventQueueThreadsLock;
///
- /// List of threads processing event queue
+ /// Used internally to specify how many threads should exit gracefully
///
- private List eventQueueThreads;// = new List();
- private object eventQueueThreadsLock;// = new object();
+ public int ThreadsToExit;
+ public object ThreadsToExitLock = new object();
private static List staticEventQueueThreads;// = new List();
private static object staticEventQueueThreadsLock;// = new object();
@@ -80,22 +94,43 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
///
/// How many threads to process queue with
///
- private int numberOfThreads;
+ internal int numberOfThreads;
+ ///
+ /// Maximum time one function can use for execution before we perform a thread kill.
+ ///
+ private int maxFunctionExecutionTimems
+ {
+ get { return (int)(maxFunctionExecutionTimens / 10000); }
+ set { maxFunctionExecutionTimens = value * 10000; }
+ }
///
- /// Maximum time one function can use for execution before we perform a thread kill
+ /// Contains nanoseconds version of maxFunctionExecutionTimems so that it matches time calculations better (performance reasons).
+ /// WARNING! ONLY UPDATE maxFunctionExecutionTimems, NEVER THIS DIRECTLY.
+ ///
+ public long maxFunctionExecutionTimens;
+ ///
+ /// Enforce max execution time
+ ///
+ public bool EnforceMaxExecutionTime;
+ ///
+ /// Kill script (unload) when it exceeds execution time
///
- private int maxFunctionExecutionTimems;
- private bool EnforceMaxExecutionTime;
private bool KillScriptOnMaxFunctionExecutionTime;
+ ///
+ /// List of localID locks for mutex processing of script events
+ ///
+ private List objectLocks = new List();
+ private object tryLockLock = new object(); // Mutex lock object
///
/// Queue containing events waiting to be executed
///
public Queue eventQueue = new Queue();
+ #region " Queue structures "
///
/// Queue item structure
///
@@ -128,18 +163,9 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
public int[] _int;
public string[] _string;
}
+ #endregion
- ///
- /// List of localID locks for mutex processing of script events
- ///
- private List objectLocks = new List();
-
- private object tryLockLock = new object(); // Mutex lock object
-
- public ScriptEngine m_ScriptEngine;
-
- public Thread ExecutionTimeoutEnforcingThread;
-
+ #region " Initialization / Startup "
public EventQueueManager(ScriptEngine _ScriptEngine)
{
m_ScriptEngine = _ScriptEngine;
@@ -167,66 +193,79 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
eventQueueThreadsLock = staticEventQueueThreadsLock;
}
- numberOfThreads = m_ScriptEngine.ScriptConfigSource.GetInt("NumberOfScriptThreads", 2);
+ ReadConfig();
+ }
+
+ private void ReadConfig()
+ {
+ numberOfThreads = m_ScriptEngine.ScriptConfigSource.GetInt("NumberOfScriptThreads", 2);
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
- if (EnforceMaxExecutionTime)
- {
- ExecutionTimeoutEnforcingThread = new Thread(ExecutionTimeoutEnforcingLoop);
- ExecutionTimeoutEnforcingThread.Name = "ExecutionTimeoutEnforcingThread";
- ExecutionTimeoutEnforcingThread.IsBackground = true;
- ExecutionTimeoutEnforcingThread.Start();
- }
+ #endregion
+
+ #region " Shutdown all threads "
+ ~EventQueueManager()
+ {
+ Stop();
+ }
- //
- // Start event queue processing threads (worker threads)
- //
+ private void Stop()
+ {
+ // Kill worker threads
lock (eventQueueThreadsLock)
{
- for (int ThreadCount = eventQueueThreads.Count; ThreadCount < numberOfThreads; ThreadCount++)
+ foreach (EventQueueThreadClass EventQueueThread in eventQueueThreads)
{
- StartNewThreadClass();
+ EventQueueThread.Shutdown();
}
+ eventQueueThreads.Clear();
+ staticGlobalEventQueueThreads.Clear();
+ }
+ // Remove all entries from our event queue
+ lock (queueLock)
+ {
+ eventQueue.Clear();
}
}
- ~EventQueueManager()
+ #endregion
+
+
+ #region " Start / stop script execution threads (ThreadClasses) "
+ private void StartNewThreadClass()
{
+ EventQueueThreadClass eqtc = new EventQueueThreadClass(this);
+ eventQueueThreads.Add(eqtc);
+ staticGlobalEventQueueThreads.Add(eqtc);
+ m_ScriptEngine.Log.Debug("DotNetEngine", "Started new script execution thread. Current thread count: " + eventQueueThreads.Count);
+
+ }
+ private void AbortThreadClass(EventQueueThreadClass threadClass)
+ {
+ if (eventQueueThreads.Contains(threadClass))
+ eventQueueThreads.Remove(threadClass);
+ if (staticGlobalEventQueueThreads.Contains(threadClass))
+ staticGlobalEventQueueThreads.Remove(threadClass);
try
{
- if (ExecutionTimeoutEnforcingThread != null)
- {
- if (ExecutionTimeoutEnforcingThread.IsAlive)
- {
- ExecutionTimeoutEnforcingThread.Abort();
- }
- }
+ threadClass.Shutdown();
}
catch (Exception ex)
{
+ m_ScriptEngine.Log.Error("EventQueueManager", "If you see this, could you please report it to Tedd:");
+ m_ScriptEngine.Log.Error("EventQueueManager", "Script thread execution timeout kill ended in exception: " + ex.ToString());
}
-
-
- // Kill worker threads
- lock (eventQueueThreadsLock)
- {
- foreach (EventQueueThreadClass EventQueueThread in new ArrayList(eventQueueThreads))
- {
- EventQueueThread.Shutdown();
- }
- eventQueueThreads.Clear();
- }
- // Todo: Clean up our queues
- eventQueue.Clear();
+ m_ScriptEngine.Log.Debug("DotNetEngine", "Killed script execution thread. Remaining thread count: " + eventQueueThreads.Count);
}
+ #endregion
-
+ #region " Mutex locks for queue access "
///
/// Try to get a mutex lock on localID
///
@@ -262,8 +301,9 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
}
}
}
+ #endregion
-
+ #region " Add events to execution queue "
///
/// Add event to event execution queue
///
@@ -317,62 +357,72 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
eventQueue.Enqueue(QIS);
}
}
+ #endregion
+
+ #region " Maintenance thread "
///
- /// A thread should run in this loop and check all running scripts
+ /// Adjust number of script thread classes. It can start new, but if it needs to stop it will just set number of threads in "ThreadsToExit" and threads will have to exit themselves.
+ /// Called from MaintenanceThread
///
- public void ExecutionTimeoutEnforcingLoop()
+ public void AdjustNumberOfScriptThreads()
{
- try
+ lock (eventQueueThreadsLock)
{
- while (true)
+ int diff = numberOfThreads - eventQueueThreads.Count;
+ // Positive number: Start
+ // Negative number: too many are running
+ if (diff > 0)
{
- System.Threading.Thread.Sleep(maxFunctionExecutionTimems);
- lock (eventQueueThreadsLock)
+ // We need to add more threads
+ for (int ThreadCount = eventQueueThreads.Count; ThreadCount < numberOfThreads; ThreadCount++)
{
- foreach (EventQueueThreadClass EventQueueThread in new ArrayList(eventQueueThreads))
- {
- if (EventQueueThread.InExecution)
- {
- if (DateTime.Now.Subtract(EventQueueThread.LastExecutionStarted).Milliseconds >
- maxFunctionExecutionTimems)
- {
- // We need to kill this thread!
- EventQueueThread.KillCurrentScript = KillScriptOnMaxFunctionExecutionTime;
- AbortThreadClass(EventQueueThread);
- // Then start another
- StartNewThreadClass();
- }
- }
- }
+ StartNewThreadClass();
+ }
+ }
+ if (diff < 0)
+ {
+ // We need to kill some threads
+ lock (ThreadsToExitLock)
+ {
+ ThreadsToExit = Math.Abs(diff);
}
}
- }
- catch (ThreadAbortException tae)
- {
}
}
- private void AbortThreadClass(EventQueueThreadClass threadClass)
+ ///
+ /// Check if any thread class has been executing an event too long
+ ///
+ public void CheckScriptMaxExecTime()
{
- try
- {
- threadClass.Shutdown();
- }
- catch (Exception ex)
+ // Iterate through all ScriptThreadClasses and check how long their current function has been executing
+ lock (eventQueueThreadsLock)
{
- Console.WriteLine("Could you please report this to Tedd:");
- Console.WriteLine("Script thread execution timeout kill ended in exception: " + ex.ToString());
+ foreach (EventQueueThreadClass EventQueueThread in staticGlobalEventQueueThreads)
+ {
+ // Is thread currently executing anything?
+ if (EventQueueThread.InExecution)
+ {
+ // Has execution time expired?
+ if (DateTime.Now.Ticks - EventQueueThread.LastExecutionStarted >
+ maxFunctionExecutionTimens)
+ {
+ // Yes! We need to kill this thread!
+
+ // Set flag if script should be removed or not
+ EventQueueThread.KillCurrentScript = KillScriptOnMaxFunctionExecutionTime;
+
+ // Abort this thread
+ AbortThreadClass(EventQueueThread);
+
+ // We do not need to start another, MaintenenceThread will do that for us
+ //StartNewThreadClass();
+ }
+ }
+ }
}
- m_ScriptEngine.Log.Debug("DotNetEngine", "Killed script execution thread, count: " + eventQueueThreads.Count);
- }
-
- private void StartNewThreadClass()
- {
- EventQueueThreadClass eqtc = new EventQueueThreadClass(this);
- eventQueueThreads.Add(eqtc);
- m_ScriptEngine.Log.Debug("DotNetEngine", "Started new script execution thread, count: " + eventQueueThreads.Count);
-
}
+ #endregion
}
}
\ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueThreadClass.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueThreadClass.cs
index 57caad5..e610c36 100644
--- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueThreadClass.cs
+++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueThreadClass.cs
@@ -19,7 +19,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
///
private int nothingToDoSleepms;// = 50;
- public DateTime LastExecutionStarted;
+ public long LastExecutionStarted;
public bool InExecution = false;
public bool KillCurrentScript = false;
@@ -109,120 +109,154 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
//myScriptEngine.m_logger.Verbose("ScriptEngine", "EventQueueManager Worker thread spawned");
try
{
- EventQueueManager.QueueItemStruct BlankQIS = new EventQueueManager.QueueItemStruct();
- while (true)
+ while (true)
{
try
{
- EventQueueManager.QueueItemStruct QIS = BlankQIS;
- bool GotItem = false;
-
- if (eventQueueManager.eventQueue.Count == 0)
- {
- // Nothing to do? Sleep a bit waiting for something to do
- Thread.Sleep(nothingToDoSleepms);
- }
- else
+ EventQueueManager.QueueItemStruct BlankQIS = new EventQueueManager.QueueItemStruct();
+ while (true)
{
- // Something in queue, process
- //myScriptEngine.m_logger.Verbose("ScriptEngine", "Processing event for localID: " + QIS.localID + ", itemID: " + QIS.itemID + ", FunctionName: " + QIS.FunctionName);
-
- // OBJECT BASED LOCK - TWO THREADS WORKING ON SAME OBJECT IS NOT GOOD
- lock (eventQueueManager.queueLock)
+ // Every now and then check if we should shut down
+ if (eventQueueManager.ThreadsToExit > 0)
{
- GotItem = false;
- for (int qc = 0; qc < eventQueueManager.eventQueue.Count; qc++)
+ // Someone should shut down, lets get exclusive lock
+ lock (eventQueueManager.ThreadsToExitLock)
{
- // Get queue item
- QIS = eventQueueManager.eventQueue.Dequeue();
-
- // Check if object is being processed by someone else
- if (eventQueueManager.TryLock(QIS.localID) == false)
- {
- // Object is already being processed, requeue it
- eventQueueManager.eventQueue.Enqueue(QIS);
- }
- else
+ // Lets re-check in case someone grabbed it
+ if (eventQueueManager.ThreadsToExit > 0)
{
- // We have lock on an object and can process it
- GotItem = true;
- break;
+ // We are go for shutdown
+ eventQueueManager.ThreadsToExit--;
+ Shutdown();
+ return;
}
- } // go through queue
- } // lock
+ }
+ }
- if (GotItem == true)
+
+ //try
+ // {
+ EventQueueManager.QueueItemStruct QIS = BlankQIS;
+ bool GotItem = false;
+
+ if (eventQueueManager.eventQueue.Count == 0)
{
- // Execute function
- try
- {
-#if DEBUG
- eventQueueManager.m_ScriptEngine.Log.Debug("ScriptEngine", "Executing event:\r\n"
- + "QIS.localID: " + QIS.localID
- + ", QIS.itemID: " + QIS.itemID
- + ", 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);
- InExecution = false;
- }
- catch (Exception e)
+ // Nothing to do? Sleep a bit waiting for something to do
+ Thread.Sleep(nothingToDoSleepms);
+ }
+ else
+ {
+ // Something in queue, process
+ //myScriptEngine.m_logger.Verbose("ScriptEngine", "Processing event for localID: " + QIS.localID + ", itemID: " + QIS.itemID + ", FunctionName: " + QIS.FunctionName);
+
+ // OBJECT BASED LOCK - TWO THREADS WORKING ON SAME OBJECT IS NOT GOOD
+ lock (eventQueueManager.queueLock)
{
- InExecution = false;
- // DISPLAY ERROR INWORLD
- string text = "Error executing script function \"" + QIS.functionName + "\":\r\n";
- if (e.InnerException != null)
+ GotItem = false;
+ for (int qc = 0; qc < eventQueueManager.eventQueue.Count; qc++)
{
- // Send inner exception
- text += e.InnerException.Message.ToString();
- }
- else
- {
- text += "\r\n";
- // Send normal
- text += e.Message.ToString();
- }
- if (KillCurrentScript)
- text += "\r\nScript will be deactivated!";
+ // Get queue item
+ QIS = eventQueueManager.eventQueue.Dequeue();
+
+ // Check if object is being processed by someone else
+ if (eventQueueManager.TryLock(QIS.localID) == false)
+ {
+ // Object is already being processed, requeue it
+ eventQueueManager.eventQueue.Enqueue(QIS);
+ }
+ else
+ {
+ // We have lock on an object and can process it
+ GotItem = true;
+ break;
+ }
+ } // go through queue
+ } // lock
+ if (GotItem == true)
+ {
+ // Execute function
try
{
- if (text.Length > 1500)
- text = text.Substring(0, 1500);
- IScriptHost m_host = eventQueueManager.m_ScriptEngine.World.GetSceneObjectPart(QIS.localID);
- //if (m_host != null)
- //{
- eventQueueManager.m_ScriptEngine.World.SimChat(Helpers.StringToField(text), ChatTypeEnum.Say, 0,
- m_host.AbsolutePosition, m_host.Name, m_host.UUID);
- }
- catch
- {
- //}
- //else
- //{
- // T oconsole
- eventQueueManager.m_ScriptEngine.Log.Error("ScriptEngine",
- "Unable to send text in-world:\r\n" + text);
+#if DEBUG
+ eventQueueManager.m_ScriptEngine.Log.Debug("ScriptEngine",
+ "Executing event:\r\n"
+ + "QIS.localID: " + QIS.localID
+ + ", QIS.itemID: " + QIS.itemID
+ + ", QIS.functionName: " +
+ QIS.functionName);
+#endif
+ LastExecutionStarted = DateTime.Now.Ticks;
+ KillCurrentScript = false;
+ InExecution = true;
+ eventQueueManager.m_ScriptEngine.m_ScriptManager.ExecuteEvent(QIS.localID,
+ QIS.itemID,
+ QIS.functionName,
+ QIS.llDetectParams,
+ QIS.param);
+ InExecution = false;
}
- finally
+ catch (Exception e)
{
- // So we are done sending message in-world
+ InExecution = false;
+ // DISPLAY ERROR INWORLD
+ string text = "Error executing script function \"" + QIS.functionName +
+ "\":\r\n";
+ if (e.InnerException != null)
+ {
+ // Send inner exception
+ text += e.InnerException.Message.ToString();
+ }
+ else
+ {
+ text += "\r\n";
+ // Send normal
+ text += e.Message.ToString();
+ }
if (KillCurrentScript)
+ text += "\r\nScript will be deactivated!";
+
+ try
+ {
+ if (text.Length > 1500)
+ text = text.Substring(0, 1500);
+ IScriptHost m_host =
+ eventQueueManager.m_ScriptEngine.World.GetSceneObjectPart(QIS.localID);
+ //if (m_host != null)
+ //{
+ eventQueueManager.m_ScriptEngine.World.SimChat(Helpers.StringToField(text),
+ ChatTypeEnum.Say, 0,
+ m_host.AbsolutePosition,
+ m_host.Name, m_host.UUID);
+ }
+ catch
{
- eventQueueManager.m_ScriptEngine.m_ScriptManager.RemoveScript(QIS.localID, QIS.itemID);
+ //}
+ //else
+ //{
+ // T oconsole
+ 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.StopScript(
+ QIS.localID, QIS.itemID);
+ }
}
}
+ finally
+ {
+ InExecution = false;
+ eventQueueManager.ReleaseLock(QIS.localID);
+ }
}
- finally
- {
- InExecution = false;
- eventQueueManager.ReleaseLock(QIS.localID);
- }
- }
- } // Something in queue
+ } // Something in queue
+ }
}
catch (ThreadAbortException tae)
{
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs
new file mode 100644
index 0000000..9536291
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/MaintenanceThread.cs
@@ -0,0 +1,127 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading;
+
+namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
+{
+ ///
+ /// This class does maintenance on script engine.
+ ///
+ public class MaintenanceThread
+ {
+ public ScriptEngine m_ScriptEngine;
+ private int MaintenanceLoopms;
+
+ public MaintenanceThread(ScriptEngine _ScriptEngine)
+ {
+ m_ScriptEngine = _ScriptEngine;
+
+ ReadConfig();
+
+ // Start maintenance thread
+ StartMaintenanceThread();
+ }
+
+ ~MaintenanceThread()
+ {
+ StopMaintenanceThread();
+ }
+
+ private void ReadConfig()
+ {
+ MaintenanceLoopms = m_ScriptEngine.ScriptConfigSource.GetInt("MaintenanceLoopms", 50);
+ }
+
+
+ #region " Maintenance thread "
+ ///
+ /// Maintenance thread. Enforcing max execution time for example.
+ ///
+ public static Thread MaintenanceThreadThread;
+
+ ///
+ /// Starts maintenance thread
+ ///
+ private void StartMaintenanceThread()
+ {
+ StopMaintenanceThread();
+
+ MaintenanceThreadThread = new Thread(MaintenanceLoop);
+ MaintenanceThreadThread.Name = "ScriptMaintenanceThread";
+ MaintenanceThreadThread.IsBackground = true;
+ MaintenanceThreadThread.Start();
+ }
+
+ ///
+ /// Stops maintenance thread
+ ///
+ private void StopMaintenanceThread()
+ {
+ try
+ {
+ if (MaintenanceThreadThread != null)
+ {
+ if (MaintenanceThreadThread.IsAlive)
+ {
+ MaintenanceThreadThread.Abort();
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ m_ScriptEngine.Log.Error("EventQueueManager", "Exception stopping maintenence thread: " + ex.ToString());
+ }
+
+ }
+
+ ///
+ /// A thread should run in this loop and check all running scripts
+ ///
+ public void MaintenanceLoop()
+ {
+ try
+ {
+ long Last_maxFunctionExecutionTimens = 0;// DateTime.Now.Ticks;
+ long Last_ReReadConfigFilens = DateTime.Now.Ticks;
+ while (true)
+ {
+ System.Threading.Thread.Sleep(MaintenanceLoopms); // Sleep
+
+ // Re-reading config every x seconds?
+ if (m_ScriptEngine.ReReadConfigFileSeconds > 0)
+ {
+ // Check if its time to re-read config
+ if (DateTime.Now.Ticks - Last_ReReadConfigFilens > m_ScriptEngine.ReReadConfigFilens)
+ {
+ // Its time to re-read config file
+ m_ScriptEngine.ConfigSource.Reload(); // Re-read config
+ Last_ReReadConfigFilens = DateTime.Now.Ticks; // Reset time
+ }
+ }
+
+ // Adjust number of running script threads if not correct
+ if (m_ScriptEngine.m_EventQueueManager.eventQueueThreads.Count != m_ScriptEngine.m_EventQueueManager.numberOfThreads)
+ {
+ m_ScriptEngine.m_EventQueueManager.AdjustNumberOfScriptThreads();
+ }
+
+
+ // Check if any script has exceeded its max execution time
+ if (m_ScriptEngine.m_EventQueueManager.EnforceMaxExecutionTime)
+ {
+ if (DateTime.Now.Ticks - Last_maxFunctionExecutionTimens > m_ScriptEngine.m_EventQueueManager.maxFunctionExecutionTimens)
+ {
+ m_ScriptEngine.m_EventQueueManager.CheckScriptMaxExecTime(); // Do check
+ Last_maxFunctionExecutionTimens = DateTime.Now.Ticks; // Reset time
+ }
+ }
+ }
+ }
+ catch (ThreadAbortException tae)
+ {
+ }
+ }
+ #endregion
+ }
+}
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptEngine.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptEngine.cs
index fa40947..cfcc36e 100644
--- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptEngine.cs
+++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptEngine.cs
@@ -55,6 +55,15 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
public IConfig ScriptConfigSource;
public abstract string ScriptConfigSourceName { get; }
+ ///
+ /// How many seconds between re-reading config-file. 0 = never. ScriptEngine will try to adjust to new config changes.
+ ///
+ public int ReReadConfigFileSeconds {
+ get { return (int)(ReReadConfigFilens / 10000); }
+ set { ReReadConfigFilens = value * 10000; }
+ }
+ public long ReReadConfigFilens = 0;
+
public ScriptManager GetScriptManager()
{
return _GetScriptManager();
@@ -93,6 +102,9 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
m_AppDomainManager = new AppDomainManager(ScriptConfigSource.GetInt("ScriptsPerAppDomain", 1));
m_LSLLongCmdHandler = new LSLLongCmdHandler(this);
+ ReReadConfigFileSeconds = ScriptConfigSource.GetInt("ReReadConfig", 0);
+
+
// Should we iterate the region for scripts that needs starting?
// Or can we assume we are loaded before anything else so we can use proper events?
}
--
cgit v1.1