From eeaac68d73d66724f79bc34ea9d55613c0d99c83 Mon Sep 17 00:00:00 2001 From: Tedd Hansen Date: Sun, 19 Aug 2007 11:38:58 +0000 Subject: Code comments on recent changes in EventQueueManager --- .../ScriptEngine/DotNetEngine/EventQueueManager.cs | 54 ++++++++++++++++++---- .../ScriptEngine/DotNetEngine/ScriptManager.cs | 6 +-- 2 files changed, 48 insertions(+), 12 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs index ec34bb0..c2a4b88 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs @@ -42,11 +42,26 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine [Serializable] class EventQueueManager { + /// + /// List of threads processing event queue + /// private List EventQueueThreads = new List(); - private object QueueLock = new object(); + private object QueueLock = new object(); // Mutex lock object + /// + /// How many ms to sleep if queue is empty + /// private int NothingToDoSleepms = 50; + /// + /// How many threads to process queue with + /// private int NumberOfThreads = 2; + /// + /// Queue containing events waiting to be executed + /// private Queue EventQueue = new Queue(); + /// + /// Queue item structure + /// private struct QueueItemStruct { public IScriptHost ObjectID; @@ -55,13 +70,20 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine public object[] param; } + /// + /// List of ObjectID locks for mutex processing of script events + /// + private List ObjectLocks = new List(); + private object TryLockLock = new object(); // Mutex lock object + private ScriptEngine myScriptEngine; public EventQueueManager(ScriptEngine _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++) { Thread EventQueueThread = new Thread(EventQueueThreadLoop); @@ -92,9 +114,13 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine } EventQueueThreads.Clear(); // Todo: Clean up our queues + EventQueue.Clear(); } + /// + /// Queue processing thread loop + /// private void EventQueueThreadLoop() { //myScriptEngine.m_logger.Verbose("ScriptEngine", "EventQueueManager Worker thread spawned"); @@ -156,8 +182,11 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine } } - private List ObjectLocks = new List(); - private object TryLockLock = new object(); + /// + /// Try to get a mutex lock on ObjectID + /// + /// + /// private bool TryLock(IScriptHost ObjectID) { lock (TryLockLock) @@ -174,6 +203,10 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine } } + /// + /// Release mutex lock on ObjectID + /// + /// private void ReleaseLock(IScriptHost ObjectID) { lock (TryLockLock) @@ -185,6 +218,12 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine } } + /// + /// Add event to event execution queue + /// + /// + /// Name of the function, will be state + "_event_" + FunctionName + /// Array of parameters to match event mask public void AddToObjectQueue(IScriptHost ObjectID, string FunctionName, object[] param) { // 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 - //} + } } diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs index 4879fb2..07d5d54 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs @@ -184,9 +184,9 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine before = GC.GetTotalMemory(true); Script = m_scriptEngine.myAppDomainManager.LoadScript(FileName); Console.WriteLine("Script occupies {0} bytes", GC.GetTotalMemory(true) - before); - before = GC.GetTotalMemory(true); - Script = m_scriptEngine.myAppDomainManager.LoadScript(FileName); - Console.WriteLine("Script occupies {0} bytes", GC.GetTotalMemory(true) - before); + //before = GC.GetTotalMemory(true); + //Script = m_scriptEngine.myAppDomainManager.LoadScript(FileName); + //Console.WriteLine("Script occupies {0} bytes", GC.GetTotalMemory(true) - before); // Add it to our temporary active script keeper -- cgit v1.1