diff options
author | Tedd Hansen | 2008-02-02 03:11:06 +0000 |
---|---|---|
committer | Tedd Hansen | 2008-02-02 03:11:06 +0000 |
commit | e06ee9fd4bb60c95009af516d92786de2a88f859 (patch) | |
tree | 502e98629fded5adcc64ec705e566e57d930d324 /OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptManager.cs | |
parent | Added OpenSim.32BitLaunch.exe that can be used on 64-bit systems to run OpenS... (diff) | |
download | opensim-SC-e06ee9fd4bb60c95009af516d92786de2a88f859.zip opensim-SC-e06ee9fd4bb60c95009af516d92786de2a88f859.tar.gz opensim-SC-e06ee9fd4bb60c95009af516d92786de2a88f859.tar.bz2 opensim-SC-e06ee9fd4bb60c95009af516d92786de2a88f859.tar.xz |
Added load/unload queue size limit
Added option to share script load/unload thread between regions
Added event execution queue size limit
+ some bugfixes from all the changes
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptManager.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptManager.cs | 71 |
1 files changed, 61 insertions, 10 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptManager.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptManager.cs index 22cffff..53ef217 100644 --- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptManager.cs +++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptManager.cs | |||
@@ -62,9 +62,11 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
62 | #region Declares | 62 | #region Declares |
63 | 63 | ||
64 | private Thread scriptLoadUnloadThread; | 64 | private Thread scriptLoadUnloadThread; |
65 | private static Thread staticScriptLoadUnloadThread; | ||
65 | private int scriptLoadUnloadThread_IdleSleepms; | 66 | private int scriptLoadUnloadThread_IdleSleepms; |
66 | private Queue<LUStruct> LUQueue = new Queue<LUStruct>(); | 67 | private Queue<LUStruct> LUQueue = new Queue<LUStruct>(); |
67 | 68 | private static bool PrivateThread; | |
69 | private int LoadUnloadMaxQueueSize; | ||
68 | 70 | ||
69 | // Load/Unload structure | 71 | // Load/Unload structure |
70 | private struct LUStruct | 72 | private struct LUStruct |
@@ -98,6 +100,8 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
98 | public void ReadConfig() | 100 | public void ReadConfig() |
99 | { | 101 | { |
100 | scriptLoadUnloadThread_IdleSleepms = m_scriptEngine.ScriptConfigSource.GetInt("ScriptLoadUnloadLoopms", 30); | 102 | scriptLoadUnloadThread_IdleSleepms = m_scriptEngine.ScriptConfigSource.GetInt("ScriptLoadUnloadLoopms", 30); |
103 | PrivateThread = m_scriptEngine.ScriptConfigSource.GetBoolean("PrivateScriptLoadUnloadThread", false); | ||
104 | LoadUnloadMaxQueueSize = m_scriptEngine.ScriptConfigSource.GetInt("LoadUnloadMaxQueueSize", 100); | ||
101 | } | 105 | } |
102 | 106 | ||
103 | #region Object init/shutdown | 107 | #region Object init/shutdown |
@@ -107,14 +111,52 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
107 | public ScriptManager(ScriptEngineBase.ScriptEngine scriptEngine) | 111 | public ScriptManager(ScriptEngineBase.ScriptEngine scriptEngine) |
108 | { | 112 | { |
109 | m_scriptEngine = scriptEngine; | 113 | m_scriptEngine = scriptEngine; |
110 | // We should not read config during startup as ScriptEngine may not have config object yet | 114 | } |
115 | public void Start() | ||
116 | { | ||
117 | ReadConfig(); | ||
111 | 118 | ||
112 | AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); | 119 | AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); |
113 | scriptLoadUnloadThread = new Thread(ScriptLoadUnloadThreadLoop); | 120 | |
114 | scriptLoadUnloadThread.Name = "ScriptLoadUnloadThread"; | 121 | // |
115 | scriptLoadUnloadThread.IsBackground = true; | 122 | // CREATE THREAD |
116 | scriptLoadUnloadThread.Priority = ThreadPriority.BelowNormal; | 123 | // Private or shared |
117 | scriptLoadUnloadThread.Start(); | 124 | // |
125 | if (PrivateThread) | ||
126 | { | ||
127 | // Assign one thread per region | ||
128 | scriptLoadUnloadThread = StartScriptLoadUnloadThread(); | ||
129 | } | ||
130 | else | ||
131 | { | ||
132 | // Shared thread - make sure one exist, then assign it to the private | ||
133 | if (staticScriptLoadUnloadThread == null) | ||
134 | { | ||
135 | staticScriptLoadUnloadThread = StartScriptLoadUnloadThread(); | ||
136 | } | ||
137 | scriptLoadUnloadThread = staticScriptLoadUnloadThread; | ||
138 | } | ||
139 | } | ||
140 | |||
141 | private static int privateThreadCount = 0; | ||
142 | private Thread StartScriptLoadUnloadThread() | ||
143 | { | ||
144 | Thread t = new Thread(ScriptLoadUnloadThreadLoop); | ||
145 | string name = "ScriptLoadUnloadThread:"; | ||
146 | if (PrivateThread) | ||
147 | { | ||
148 | name += "Private:" + privateThreadCount; | ||
149 | privateThreadCount++; | ||
150 | } | ||
151 | else | ||
152 | { | ||
153 | name += "Shared"; | ||
154 | } | ||
155 | t.Name = name; | ||
156 | t.IsBackground = true; | ||
157 | t.Priority = ThreadPriority.Normal; | ||
158 | t.Start(); | ||
159 | return t; | ||
118 | } | 160 | } |
119 | 161 | ||
120 | ~ScriptManager() | 162 | ~ScriptManager() |
@@ -122,6 +164,8 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
122 | // Abort load/unload thread | 164 | // Abort load/unload thread |
123 | try | 165 | try |
124 | { | 166 | { |
167 | PleaseShutdown = true; | ||
168 | Thread.Sleep(100); | ||
125 | if (scriptLoadUnloadThread != null) | 169 | if (scriptLoadUnloadThread != null) |
126 | { | 170 | { |
127 | if (scriptLoadUnloadThread.IsAlive == true) | 171 | if (scriptLoadUnloadThread.IsAlive == true) |
@@ -148,6 +192,8 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
148 | { | 192 | { |
149 | if (LUQueue.Count == 0) | 193 | if (LUQueue.Count == 0) |
150 | Thread.Sleep(scriptLoadUnloadThread_IdleSleepms); | 194 | Thread.Sleep(scriptLoadUnloadThread_IdleSleepms); |
195 | if (PleaseShutdown) | ||
196 | return; | ||
151 | if (LUQueue.Count > 0) | 197 | if (LUQueue.Count > 0) |
152 | { | 198 | { |
153 | LUStruct item = LUQueue.Dequeue(); | 199 | LUStruct item = LUQueue.Dequeue(); |
@@ -185,7 +231,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
185 | 231 | ||
186 | #endregion | 232 | #endregion |
187 | 233 | ||
188 | 234 | ||
189 | 235 | ||
190 | #region Start/Stop/Reset script | 236 | #region Start/Stop/Reset script |
191 | 237 | ||
@@ -198,6 +244,12 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
198 | /// <param name="localID"></param> | 244 | /// <param name="localID"></param> |
199 | public void StartScript(uint localID, LLUUID itemID, string Script) | 245 | public void StartScript(uint localID, LLUUID itemID, string Script) |
200 | { | 246 | { |
247 | if (LUQueue.Count >= LoadUnloadMaxQueueSize) | ||
248 | { | ||
249 | m_scriptEngine.Log.Error(m_scriptEngine.ScriptEngineName, "ERROR: Load/unload queue item count is at " + LUQueue.Count + ". Config variable \"LoadUnloadMaxQueueSize\" is set to " + LoadUnloadMaxQueueSize + ", so ignoring new script."); | ||
250 | return; | ||
251 | } | ||
252 | |||
201 | LUStruct ls = new LUStruct(); | 253 | LUStruct ls = new LUStruct(); |
202 | ls.localID = localID; | 254 | ls.localID = localID; |
203 | ls.itemID = itemID; | 255 | ls.itemID = itemID; |
@@ -224,9 +276,8 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase | |||
224 | //private Compiler.LSL.Compiler LSLCompiler = new Compiler.LSL.Compiler(); | 276 | //private Compiler.LSL.Compiler LSLCompiler = new Compiler.LSL.Compiler(); |
225 | 277 | ||
226 | public abstract void _StartScript(uint localID, LLUUID itemID, string Script); | 278 | public abstract void _StartScript(uint localID, LLUUID itemID, string Script); |
227 | |||
228 | public abstract void _StopScript(uint localID, LLUUID itemID); | 279 | public abstract void _StopScript(uint localID, LLUUID itemID); |
229 | 280 | ||
230 | 281 | ||
231 | #endregion | 282 | #endregion |
232 | 283 | ||