diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs | 64 |
1 files changed, 18 insertions, 46 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs index e3d448c..581c7a0 100644 --- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs +++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs | |||
@@ -45,7 +45,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
45 | public class EventQueueManager : iScriptEngineFunctionModule | 45 | public class EventQueueManager : iScriptEngineFunctionModule |
46 | { | 46 | { |
47 | // | 47 | // |
48 | // Class is instanced in "ScriptEngine" and used by "EventManager" also instanced in "ScriptEngine". | 48 | // Class is instanced in "ScriptEngine" and used by "EventManager" which is also instanced in "ScriptEngine". |
49 | // | 49 | // |
50 | // Class purpose is to queue and execute functions that are received by "EventManager": | 50 | // Class purpose is to queue and execute functions that are received by "EventManager": |
51 | // - allowing "EventManager" to release its event thread immediately, thus not interrupting server execution. | 51 | // - allowing "EventManager" to release its event thread immediately, thus not interrupting server execution. |
@@ -68,25 +68,25 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
68 | /// List of threads (classes) processing event queue | 68 | /// List of threads (classes) processing event queue |
69 | /// Note that this may or may not be a reference to a static object depending on PrivateRegionThreads config setting. | 69 | /// Note that this may or may not be a reference to a static object depending on PrivateRegionThreads config setting. |
70 | /// </summary> | 70 | /// </summary> |
71 | internal List<EventQueueThreadClass> eventQueueThreads; // Thread pool that we work on | 71 | internal static List<EventQueueThreadClass> eventQueueThreads; // Thread pool that we work on |
72 | /// <summary> | 72 | /// <summary> |
73 | /// Locking access to eventQueueThreads AND staticGlobalEventQueueThreads. | 73 | /// Locking access to eventQueueThreads AND staticGlobalEventQueueThreads. |
74 | /// </summary> | 74 | /// </summary> |
75 | // private object eventQueueThreadsLock = new object(); | 75 | // private object eventQueueThreadsLock = new object(); |
76 | // Static objects for referencing the objects above if we don't have private threads: | 76 | // Static objects for referencing the objects above if we don't have private threads: |
77 | internal static List<EventQueueThreadClass> staticEventQueueThreads; // A static reference used if we don't use private threads | 77 | //internal static List<EventQueueThreadClass> staticEventQueueThreads; // A static reference used if we don't use private threads |
78 | // internal static object staticEventQueueThreadsLock; // Statick lock object reference for same reason | 78 | // internal static object staticEventQueueThreadsLock; // Statick lock object reference for same reason |
79 | 79 | ||
80 | /// <summary> | 80 | /// <summary> |
81 | /// Global static list of all threads (classes) processing event queue -- used by max enforcment thread | 81 | /// Global static list of all threads (classes) processing event queue -- used by max enforcment thread |
82 | /// </summary> | 82 | /// </summary> |
83 | private List<EventQueueThreadClass> staticGlobalEventQueueThreads = new List<EventQueueThreadClass>(); | 83 | //private List<EventQueueThreadClass> staticGlobalEventQueueThreads = new List<EventQueueThreadClass>(); |
84 | 84 | ||
85 | /// <summary> | 85 | /// <summary> |
86 | /// Used internally to specify how many threads should exit gracefully | 86 | /// Used internally to specify how many threads should exit gracefully |
87 | /// </summary> | 87 | /// </summary> |
88 | public int ThreadsToExit; | 88 | public static int ThreadsToExit; |
89 | public object ThreadsToExitLock = new object(); | 89 | public static object ThreadsToExitLock = new object(); |
90 | 90 | ||
91 | 91 | ||
92 | //public object queueLock = new object(); // Mutex lock object | 92 | //public object queueLock = new object(); // Mutex lock object |
@@ -94,14 +94,14 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
94 | /// <summary> | 94 | /// <summary> |
95 | /// How many threads to process queue with | 95 | /// How many threads to process queue with |
96 | /// </summary> | 96 | /// </summary> |
97 | internal int numberOfThreads; | 97 | internal static int numberOfThreads; |
98 | 98 | ||
99 | internal static int EventExecutionMaxQueueSize; | 99 | internal static int EventExecutionMaxQueueSize; |
100 | 100 | ||
101 | /// <summary> | 101 | /// <summary> |
102 | /// Maximum time one function can use for execution before we perform a thread kill. | 102 | /// Maximum time one function can use for execution before we perform a thread kill. |
103 | /// </summary> | 103 | /// </summary> |
104 | private int maxFunctionExecutionTimems | 104 | private static int maxFunctionExecutionTimems |
105 | { | 105 | { |
106 | get { return (int)(maxFunctionExecutionTimens / 10000); } | 106 | get { return (int)(maxFunctionExecutionTimens / 10000); } |
107 | set { maxFunctionExecutionTimens = value * 10000; } | 107 | set { maxFunctionExecutionTimens = value * 10000; } |
@@ -111,15 +111,15 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
111 | /// Contains nanoseconds version of maxFunctionExecutionTimems so that it matches time calculations better (performance reasons). | 111 | /// Contains nanoseconds version of maxFunctionExecutionTimems so that it matches time calculations better (performance reasons). |
112 | /// WARNING! ONLY UPDATE maxFunctionExecutionTimems, NEVER THIS DIRECTLY. | 112 | /// WARNING! ONLY UPDATE maxFunctionExecutionTimems, NEVER THIS DIRECTLY. |
113 | /// </summary> | 113 | /// </summary> |
114 | public long maxFunctionExecutionTimens; | 114 | public static long maxFunctionExecutionTimens; |
115 | /// <summary> | 115 | /// <summary> |
116 | /// Enforce max execution time | 116 | /// Enforce max execution time |
117 | /// </summary> | 117 | /// </summary> |
118 | public bool EnforceMaxExecutionTime; | 118 | public static bool EnforceMaxExecutionTime; |
119 | /// <summary> | 119 | /// <summary> |
120 | /// Kill script (unload) when it exceeds execution time | 120 | /// Kill script (unload) when it exceeds execution time |
121 | /// </summary> | 121 | /// </summary> |
122 | private bool KillScriptOnMaxFunctionExecutionTime; | 122 | private static bool KillScriptOnMaxFunctionExecutionTime; |
123 | 123 | ||
124 | /// <summary> | 124 | /// <summary> |
125 | /// List of localID locks for mutex processing of script events | 125 | /// List of localID locks for mutex processing of script events |
@@ -172,33 +172,8 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
172 | { | 172 | { |
173 | m_ScriptEngine = _ScriptEngine; | 173 | m_ScriptEngine = _ScriptEngine; |
174 | 174 | ||
175 | // TODO: We need to move from single EventQueueManager to list of it in to share threads | 175 | eventQueueThreads = new List<EventQueueThreadClass>(); |
176 | bool PrivateRegionThreads = true; // m_ScriptEngine.ScriptConfigSource.GetBoolean("PrivateRegionThreads", false); | ||
177 | |||
178 | // Create thread pool list and lock object | ||
179 | // Determine from config if threads should be dedicated to regions or shared | ||
180 | if (PrivateRegionThreads) | ||
181 | { | ||
182 | // PRIVATE THREAD POOL PER REGION | ||
183 | eventQueueThreads = new List<EventQueueThreadClass>(); | ||
184 | // eventQueueThreadsLock = new object(); | ||
185 | } | ||
186 | else | ||
187 | { | ||
188 | // SHARED THREAD POOL | ||
189 | // Crate the static objects | ||
190 | if (staticEventQueueThreads == null) | ||
191 | staticEventQueueThreads = new List<EventQueueThreadClass>(); | ||
192 | // if (staticEventQueueThreadsLock == null) | ||
193 | // staticEventQueueThreadsLock = new object(); | ||
194 | |||
195 | // Now reference our locals to them | ||
196 | eventQueueThreads = staticEventQueueThreads; | ||
197 | //eventQueueThreadsLock = staticEventQueueThreadsLock; | ||
198 | } | ||
199 | |||
200 | ReadConfig(); | 176 | ReadConfig(); |
201 | |||
202 | } | 177 | } |
203 | 178 | ||
204 | public void ReadConfig() | 179 | public void ReadConfig() |
@@ -230,18 +205,18 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
230 | 205 | ||
231 | private void Stop() | 206 | private void Stop() |
232 | { | 207 | { |
233 | if (eventQueueThreads != null && eventQueueThreads != null) | 208 | if (eventQueueThreads != null) |
234 | { | 209 | { |
235 | // Kill worker threads | 210 | // Kill worker threads |
236 | //lock (eventQueueThreads) | 211 | lock (eventQueueThreads) |
237 | //{ | 212 | { |
238 | foreach (EventQueueThreadClass EventQueueThread in new ArrayList(eventQueueThreads)) | 213 | foreach (EventQueueThreadClass EventQueueThread in new ArrayList(eventQueueThreads)) |
239 | { | 214 | { |
240 | AbortThreadClass(EventQueueThread); | 215 | AbortThreadClass(EventQueueThread); |
241 | } | 216 | } |
242 | //eventQueueThreads.Clear(); | 217 | //eventQueueThreads.Clear(); |
243 | //staticGlobalEventQueueThreads.Clear(); | 218 | //staticGlobalEventQueueThreads.Clear(); |
244 | //} | 219 | } |
245 | } | 220 | } |
246 | 221 | ||
247 | // Remove all entries from our event queue | 222 | // Remove all entries from our event queue |
@@ -256,9 +231,8 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
256 | #region " Start / stop script execution threads (ThreadClasses) " | 231 | #region " Start / stop script execution threads (ThreadClasses) " |
257 | private void StartNewThreadClass() | 232 | private void StartNewThreadClass() |
258 | { | 233 | { |
259 | EventQueueThreadClass eqtc = new EventQueueThreadClass(this); | 234 | EventQueueThreadClass eqtc = new EventQueueThreadClass(); |
260 | eventQueueThreads.Add(eqtc); | 235 | eventQueueThreads.Add(eqtc); |
261 | staticGlobalEventQueueThreads.Add(eqtc); | ||
262 | m_ScriptEngine.Log.Debug("[" + m_ScriptEngine.ScriptEngineName + "]: Started new script execution thread. Current thread count: " + eventQueueThreads.Count); | 236 | m_ScriptEngine.Log.Debug("[" + m_ScriptEngine.ScriptEngineName + "]: Started new script execution thread. Current thread count: " + eventQueueThreads.Count); |
263 | } | 237 | } |
264 | 238 | ||
@@ -266,8 +240,6 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
266 | { | 240 | { |
267 | if (eventQueueThreads.Contains(threadClass)) | 241 | if (eventQueueThreads.Contains(threadClass)) |
268 | eventQueueThreads.Remove(threadClass); | 242 | eventQueueThreads.Remove(threadClass); |
269 | if (staticGlobalEventQueueThreads.Contains(threadClass)) | ||
270 | staticGlobalEventQueueThreads.Remove(threadClass); | ||
271 | 243 | ||
272 | try | 244 | try |
273 | { | 245 | { |
@@ -426,7 +398,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
426 | // Iterate through all ScriptThreadClasses and check how long their current function has been executing | 398 | // Iterate through all ScriptThreadClasses and check how long their current function has been executing |
427 | lock (eventQueueThreads) | 399 | lock (eventQueueThreads) |
428 | { | 400 | { |
429 | foreach (EventQueueThreadClass EventQueueThread in staticGlobalEventQueueThreads) | 401 | foreach (EventQueueThreadClass EventQueueThread in eventQueueThreads) |
430 | { | 402 | { |
431 | // Is thread currently executing anything? | 403 | // Is thread currently executing anything? |
432 | if (EventQueueThread.InExecution) | 404 | if (EventQueueThread.InExecution) |