Code comments on recent changes in EventQueueManager
parent
7770c65a7e
commit
eeaac68d73
|
@ -42,11 +42,26 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||||
[Serializable]
|
[Serializable]
|
||||||
class EventQueueManager
|
class EventQueueManager
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// List of threads processing event queue
|
||||||
|
/// </summary>
|
||||||
private List<Thread> EventQueueThreads = new List<Thread>();
|
private List<Thread> EventQueueThreads = new List<Thread>();
|
||||||
private object QueueLock = new object();
|
private object QueueLock = new object(); // Mutex lock object
|
||||||
|
/// <summary>
|
||||||
|
/// How many ms to sleep if queue is empty
|
||||||
|
/// </summary>
|
||||||
private int NothingToDoSleepms = 50;
|
private int NothingToDoSleepms = 50;
|
||||||
|
/// <summary>
|
||||||
|
/// How many threads to process queue with
|
||||||
|
/// </summary>
|
||||||
private int NumberOfThreads = 2;
|
private int NumberOfThreads = 2;
|
||||||
|
/// <summary>
|
||||||
|
/// Queue containing events waiting to be executed
|
||||||
|
/// </summary>
|
||||||
private Queue<QueueItemStruct> EventQueue = new Queue<QueueItemStruct>();
|
private Queue<QueueItemStruct> EventQueue = new Queue<QueueItemStruct>();
|
||||||
|
/// <summary>
|
||||||
|
/// Queue item structure
|
||||||
|
/// </summary>
|
||||||
private struct QueueItemStruct
|
private struct QueueItemStruct
|
||||||
{
|
{
|
||||||
public IScriptHost ObjectID;
|
public IScriptHost ObjectID;
|
||||||
|
@ -55,13 +70,20 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||||
public object[] param;
|
public object[] param;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// List of ObjectID locks for mutex processing of script events
|
||||||
|
/// </summary>
|
||||||
|
private List<IScriptHost> ObjectLocks = new List<IScriptHost>();
|
||||||
|
private object TryLockLock = new object(); // Mutex lock object
|
||||||
|
|
||||||
private ScriptEngine myScriptEngine;
|
private ScriptEngine myScriptEngine;
|
||||||
public EventQueueManager(ScriptEngine _ScriptEngine)
|
public EventQueueManager(ScriptEngine _ScriptEngine)
|
||||||
{
|
{
|
||||||
myScriptEngine = _ScriptEngine;
|
myScriptEngine = _ScriptEngine;
|
||||||
//myScriptEngine.m_logger.Verbose("ScriptEngine", "EventQueueManager Start");
|
|
||||||
// Start worker thread
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Start event queue processing threads (worker threads)
|
||||||
|
//
|
||||||
for (int ThreadCount = 0; ThreadCount <= NumberOfThreads; ThreadCount++)
|
for (int ThreadCount = 0; ThreadCount <= NumberOfThreads; ThreadCount++)
|
||||||
{
|
{
|
||||||
Thread EventQueueThread = new Thread(EventQueueThreadLoop);
|
Thread EventQueueThread = new Thread(EventQueueThreadLoop);
|
||||||
|
@ -92,9 +114,13 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||||
}
|
}
|
||||||
EventQueueThreads.Clear();
|
EventQueueThreads.Clear();
|
||||||
// Todo: Clean up our queues
|
// Todo: Clean up our queues
|
||||||
|
EventQueue.Clear();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Queue processing thread loop
|
||||||
|
/// </summary>
|
||||||
private void EventQueueThreadLoop()
|
private void EventQueueThreadLoop()
|
||||||
{
|
{
|
||||||
//myScriptEngine.m_logger.Verbose("ScriptEngine", "EventQueueManager Worker thread spawned");
|
//myScriptEngine.m_logger.Verbose("ScriptEngine", "EventQueueManager Worker thread spawned");
|
||||||
|
@ -156,8 +182,11 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<IScriptHost> ObjectLocks = new List<IScriptHost>();
|
/// <summary>
|
||||||
private object TryLockLock = new object();
|
/// Try to get a mutex lock on ObjectID
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ObjectID"></param>
|
||||||
|
/// <returns></returns>
|
||||||
private bool TryLock(IScriptHost ObjectID)
|
private bool TryLock(IScriptHost ObjectID)
|
||||||
{
|
{
|
||||||
lock (TryLockLock)
|
lock (TryLockLock)
|
||||||
|
@ -174,6 +203,10 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Release mutex lock on ObjectID
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ObjectID"></param>
|
||||||
private void ReleaseLock(IScriptHost ObjectID)
|
private void ReleaseLock(IScriptHost ObjectID)
|
||||||
{
|
{
|
||||||
lock (TryLockLock)
|
lock (TryLockLock)
|
||||||
|
@ -185,6 +218,12 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add event to event execution queue
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ObjectID"></param>
|
||||||
|
/// <param name="FunctionName">Name of the function, will be state + "_event_" + FunctionName</param>
|
||||||
|
/// <param name="param">Array of parameters to match event mask</param>
|
||||||
public void AddToObjectQueue(IScriptHost ObjectID, string FunctionName, object[] param)
|
public void AddToObjectQueue(IScriptHost ObjectID, string FunctionName, object[] param)
|
||||||
{
|
{
|
||||||
// Determine all scripts in Object and add to their queue
|
// Determine all scripts in Object and add to their queue
|
||||||
|
@ -210,10 +249,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//public void AddToScriptQueue(string ObjectID, string FunctionName, object[] param)
|
|
||||||
//{
|
|
||||||
// // Add to script queue
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,9 +184,9 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
|
||||||
before = GC.GetTotalMemory(true);
|
before = GC.GetTotalMemory(true);
|
||||||
Script = m_scriptEngine.myAppDomainManager.LoadScript(FileName);
|
Script = m_scriptEngine.myAppDomainManager.LoadScript(FileName);
|
||||||
Console.WriteLine("Script occupies {0} bytes", GC.GetTotalMemory(true) - before);
|
Console.WriteLine("Script occupies {0} bytes", GC.GetTotalMemory(true) - before);
|
||||||
before = GC.GetTotalMemory(true);
|
//before = GC.GetTotalMemory(true);
|
||||||
Script = m_scriptEngine.myAppDomainManager.LoadScript(FileName);
|
//Script = m_scriptEngine.myAppDomainManager.LoadScript(FileName);
|
||||||
Console.WriteLine("Script occupies {0} bytes", GC.GetTotalMemory(true) - before);
|
//Console.WriteLine("Script occupies {0} bytes", GC.GetTotalMemory(true) - before);
|
||||||
|
|
||||||
|
|
||||||
// Add it to our temporary active script keeper
|
// Add it to our temporary active script keeper
|
||||||
|
|
Loading…
Reference in New Issue