aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Util.cs
diff options
context:
space:
mode:
authorMelanie2009-10-22 07:02:21 +0100
committerMelanie2009-10-22 07:02:21 +0100
commitb35fbe1f98532196befa8bc38deb0aba83d08f6f (patch)
tree2aa3d6c6e8683dcce52709931c998b7e2bf1d42d /OpenSim/Framework/Util.cs
parent* Changed the misc. methods calling ThreadPool.UnsafeQueueUserWorkItem() to U... (diff)
parentMake the LSL scripting delays take full effect. To tune, tweat the (diff)
downloadopensim-SC_OLD-b35fbe1f98532196befa8bc38deb0aba83d08f6f.zip
opensim-SC_OLD-b35fbe1f98532196befa8bc38deb0aba83d08f6f.tar.gz
opensim-SC_OLD-b35fbe1f98532196befa8bc38deb0aba83d08f6f.tar.bz2
opensim-SC_OLD-b35fbe1f98532196befa8bc38deb0aba83d08f6f.tar.xz
Merge branch 'melanie_test' into prioritization
This makes SmartThreadPool configurable and also makes it the default, since the regular thread pool simply stinks.
Diffstat (limited to 'OpenSim/Framework/Util.cs')
-rw-r--r--OpenSim/Framework/Util.cs26
1 files changed, 23 insertions, 3 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 02f6d12..d09bd6d 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -41,12 +41,14 @@ using System.Security.Cryptography;
41using System.Text; 41using System.Text;
42using System.Text.RegularExpressions; 42using System.Text.RegularExpressions;
43using System.Xml; 43using System.Xml;
44using System.Threading;
44using log4net; 45using log4net;
45using Nini.Config; 46using Nini.Config;
46using Nwc.XmlRpc; 47using Nwc.XmlRpc;
47using BclExtras; 48using BclExtras;
48using OpenMetaverse; 49using OpenMetaverse;
49using OpenMetaverse.StructuredData; 50using OpenMetaverse.StructuredData;
51using Amib.Threading;
50 52
51namespace OpenSim.Framework 53namespace OpenSim.Framework
52{ 54{
@@ -67,6 +69,8 @@ namespace OpenSim.Framework
67 /// </summary> 69 /// </summary>
68 public class Util 70 public class Util
69 { 71 {
72 private static SmartThreadPool m_ThreadPool = null;
73
70 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 74 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
71 75
72 private static uint nextXferID = 5000; 76 private static uint nextXferID = 5000;
@@ -83,7 +87,7 @@ namespace OpenSim.Framework
83 public static readonly Regex UUIDPattern 87 public static readonly Regex UUIDPattern
84 = new Regex("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); 88 = new Regex("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$");
85 89
86 public static FireAndForgetMethod FireAndForgetMethod = FireAndForgetMethod.UnsafeQueueUserWorkItem; 90 public static FireAndForgetMethod FireAndForgetMethod = FireAndForgetMethod.SmartThreadPool;
87 91
88 /// <summary> 92 /// <summary>
89 /// Linear interpolates B<->C using percent A 93 /// Linear interpolates B<->C using percent A
@@ -1315,6 +1319,23 @@ namespace OpenSim.Framework
1315 FireAndForget(callback, null); 1319 FireAndForget(callback, null);
1316 } 1320 }
1317 1321
1322 public static void SetMaxThreads(int maxThreads)
1323 {
1324 if (m_ThreadPool != null)
1325 return;
1326
1327 STPStartInfo startInfo = new STPStartInfo();
1328 startInfo.IdleTimeout = 2000; // 2 seconds
1329 startInfo.MaxWorkerThreads = maxThreads;
1330 startInfo.MinWorkerThreads = 2;
1331 startInfo.StackSize = 524288;
1332 startInfo.ThreadPriority = ThreadPriority.Normal;
1333
1334 startInfo.StartSuspended = false;
1335
1336 m_ThreadPool = new SmartThreadPool(startInfo);
1337 }
1338
1318 public static void FireAndForget(System.Threading.WaitCallback callback, object obj) 1339 public static void FireAndForget(System.Threading.WaitCallback callback, object obj)
1319 { 1340 {
1320 switch (FireAndForgetMethod) 1341 switch (FireAndForgetMethod)
@@ -1330,8 +1351,7 @@ namespace OpenSim.Framework
1330 wrapper.FireAndForget(callback, obj); 1351 wrapper.FireAndForget(callback, obj);
1331 break; 1352 break;
1332 case FireAndForgetMethod.SmartThreadPool: 1353 case FireAndForgetMethod.SmartThreadPool:
1333 Amib.Threading.SmartThreadPool stp = Singleton.GetInstance<Amib.Threading.SmartThreadPool>(); 1354 m_ThreadPool.QueueWorkItem(delegate(object o) { callback(o); return null; }, obj);
1334 stp.QueueWorkItem(delegate(object o) { callback(o); return null; }, obj);
1335 break; 1355 break;
1336 case FireAndForgetMethod.Thread: 1356 case FireAndForgetMethod.Thread:
1337 System.Threading.Thread thread = new System.Threading.Thread(delegate(object o) { callback(o); }); 1357 System.Threading.Thread thread = new System.Threading.Thread(delegate(object o) { callback(o); });