diff options
author | Tedd Hansen | 2007-08-19 11:38:58 +0000 |
---|---|---|
committer | Tedd Hansen | 2007-08-19 11:38:58 +0000 |
commit | eeaac68d73d66724f79bc34ea9d55613c0d99c83 (patch) | |
tree | 103edbb53149d2b11c9ca342e0409bbad27dce0a /OpenSim/Region/ScriptEngine | |
parent | Sped up EventQueueManager response time (scripts now respond quickly). Added ... (diff) | |
download | opensim-SC-eeaac68d73d66724f79bc34ea9d55613c0d99c83.zip opensim-SC-eeaac68d73d66724f79bc34ea9d55613c0d99c83.tar.gz opensim-SC-eeaac68d73d66724f79bc34ea9d55613c0d99c83.tar.bz2 opensim-SC-eeaac68d73d66724f79bc34ea9d55613c0d99c83.tar.xz |
Code comments on recent changes in EventQueueManager
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
-rw-r--r-- | OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs | 54 | ||||
-rw-r--r-- | OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs | 6 |
2 files changed, 48 insertions, 12 deletions
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 | |||
42 | [Serializable] | 42 | [Serializable] |
43 | class EventQueueManager | 43 | class EventQueueManager |
44 | { | 44 | { |
45 | /// <summary> | ||
46 | /// List of threads processing event queue | ||
47 | /// </summary> | ||
45 | private List<Thread> EventQueueThreads = new List<Thread>(); | 48 | private List<Thread> EventQueueThreads = new List<Thread>(); |
46 | private object QueueLock = new object(); | 49 | private object QueueLock = new object(); // Mutex lock object |
50 | /// <summary> | ||
51 | /// How many ms to sleep if queue is empty | ||
52 | /// </summary> | ||
47 | private int NothingToDoSleepms = 50; | 53 | private int NothingToDoSleepms = 50; |
54 | /// <summary> | ||
55 | /// How many threads to process queue with | ||
56 | /// </summary> | ||
48 | private int NumberOfThreads = 2; | 57 | private int NumberOfThreads = 2; |
58 | /// <summary> | ||
59 | /// Queue containing events waiting to be executed | ||
60 | /// </summary> | ||
49 | private Queue<QueueItemStruct> EventQueue = new Queue<QueueItemStruct>(); | 61 | private Queue<QueueItemStruct> EventQueue = new Queue<QueueItemStruct>(); |
62 | /// <summary> | ||
63 | /// Queue item structure | ||
64 | /// </summary> | ||
50 | private struct QueueItemStruct | 65 | private struct QueueItemStruct |
51 | { | 66 | { |
52 | public IScriptHost ObjectID; | 67 | public IScriptHost ObjectID; |
@@ -55,13 +70,20 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
55 | public object[] param; | 70 | public object[] param; |
56 | } | 71 | } |
57 | 72 | ||
73 | /// <summary> | ||
74 | /// List of ObjectID locks for mutex processing of script events | ||
75 | /// </summary> | ||
76 | private List<IScriptHost> ObjectLocks = new List<IScriptHost>(); | ||
77 | private object TryLockLock = new object(); // Mutex lock object | ||
78 | |||
58 | private ScriptEngine myScriptEngine; | 79 | private ScriptEngine myScriptEngine; |
59 | public EventQueueManager(ScriptEngine _ScriptEngine) | 80 | public EventQueueManager(ScriptEngine _ScriptEngine) |
60 | { | 81 | { |
61 | myScriptEngine = _ScriptEngine; | 82 | myScriptEngine = _ScriptEngine; |
62 | //myScriptEngine.m_logger.Verbose("ScriptEngine", "EventQueueManager Start"); | ||
63 | // Start worker thread | ||
64 | 83 | ||
84 | // | ||
85 | // Start event queue processing threads (worker threads) | ||
86 | // | ||
65 | for (int ThreadCount = 0; ThreadCount <= NumberOfThreads; ThreadCount++) | 87 | for (int ThreadCount = 0; ThreadCount <= NumberOfThreads; ThreadCount++) |
66 | { | 88 | { |
67 | Thread EventQueueThread = new Thread(EventQueueThreadLoop); | 89 | Thread EventQueueThread = new Thread(EventQueueThreadLoop); |
@@ -92,9 +114,13 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
92 | } | 114 | } |
93 | EventQueueThreads.Clear(); | 115 | EventQueueThreads.Clear(); |
94 | // Todo: Clean up our queues | 116 | // Todo: Clean up our queues |
117 | EventQueue.Clear(); | ||
95 | 118 | ||
96 | } | 119 | } |
97 | 120 | ||
121 | /// <summary> | ||
122 | /// Queue processing thread loop | ||
123 | /// </summary> | ||
98 | private void EventQueueThreadLoop() | 124 | private void EventQueueThreadLoop() |
99 | { | 125 | { |
100 | //myScriptEngine.m_logger.Verbose("ScriptEngine", "EventQueueManager Worker thread spawned"); | 126 | //myScriptEngine.m_logger.Verbose("ScriptEngine", "EventQueueManager Worker thread spawned"); |
@@ -156,8 +182,11 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
156 | } | 182 | } |
157 | } | 183 | } |
158 | 184 | ||
159 | private List<IScriptHost> ObjectLocks = new List<IScriptHost>(); | 185 | /// <summary> |
160 | private object TryLockLock = new object(); | 186 | /// Try to get a mutex lock on ObjectID |
187 | /// </summary> | ||
188 | /// <param name="ObjectID"></param> | ||
189 | /// <returns></returns> | ||
161 | private bool TryLock(IScriptHost ObjectID) | 190 | private bool TryLock(IScriptHost ObjectID) |
162 | { | 191 | { |
163 | lock (TryLockLock) | 192 | lock (TryLockLock) |
@@ -174,6 +203,10 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
174 | } | 203 | } |
175 | } | 204 | } |
176 | 205 | ||
206 | /// <summary> | ||
207 | /// Release mutex lock on ObjectID | ||
208 | /// </summary> | ||
209 | /// <param name="ObjectID"></param> | ||
177 | private void ReleaseLock(IScriptHost ObjectID) | 210 | private void ReleaseLock(IScriptHost ObjectID) |
178 | { | 211 | { |
179 | lock (TryLockLock) | 212 | lock (TryLockLock) |
@@ -185,6 +218,12 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
185 | } | 218 | } |
186 | } | 219 | } |
187 | 220 | ||
221 | /// <summary> | ||
222 | /// Add event to event execution queue | ||
223 | /// </summary> | ||
224 | /// <param name="ObjectID"></param> | ||
225 | /// <param name="FunctionName">Name of the function, will be state + "_event_" + FunctionName</param> | ||
226 | /// <param name="param">Array of parameters to match event mask</param> | ||
188 | public void AddToObjectQueue(IScriptHost ObjectID, string FunctionName, object[] param) | 227 | public void AddToObjectQueue(IScriptHost ObjectID, string FunctionName, object[] param) |
189 | { | 228 | { |
190 | // Determine all scripts in Object and add to their queue | 229 | // Determine all scripts in Object and add to their queue |
@@ -210,10 +249,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
210 | 249 | ||
211 | } | 250 | } |
212 | } | 251 | } |
213 | //public void AddToScriptQueue(string ObjectID, string FunctionName, object[] param) | 252 | |
214 | //{ | ||
215 | // // Add to script queue | ||
216 | //} | ||
217 | } | 253 | } |
218 | 254 | ||
219 | } | 255 | } |
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 | |||
184 | before = GC.GetTotalMemory(true); | 184 | before = GC.GetTotalMemory(true); |
185 | Script = m_scriptEngine.myAppDomainManager.LoadScript(FileName); | 185 | Script = m_scriptEngine.myAppDomainManager.LoadScript(FileName); |
186 | Console.WriteLine("Script occupies {0} bytes", GC.GetTotalMemory(true) - before); | 186 | Console.WriteLine("Script occupies {0} bytes", GC.GetTotalMemory(true) - before); |
187 | before = GC.GetTotalMemory(true); | 187 | //before = GC.GetTotalMemory(true); |
188 | Script = m_scriptEngine.myAppDomainManager.LoadScript(FileName); | 188 | //Script = m_scriptEngine.myAppDomainManager.LoadScript(FileName); |
189 | Console.WriteLine("Script occupies {0} bytes", GC.GetTotalMemory(true) - before); | 189 | //Console.WriteLine("Script occupies {0} bytes", GC.GetTotalMemory(true) - before); |
190 | 190 | ||
191 | 191 | ||
192 | // Add it to our temporary active script keeper | 192 | // Add it to our temporary active script keeper |