From 6ca4b0f36622833688136e9ace7d5545063293ba Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Thu, 22 Oct 2009 10:37:11 -0700 Subject: * Added a check if Util.m_ThreadPool is null before trying to use it, and if so initialize it to sane defaults * Simplified the InitThreadPool() function --- OpenSim/Framework/Util.cs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 167e34d..a18a827 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -1324,18 +1324,10 @@ namespace OpenSim.Framework { if (maxThreads < 2) throw new ArgumentOutOfRangeException("maxThreads", "maxThreads must be greater than 2"); - if (m_ThreadPool != null) - return; - - STPStartInfo startInfo = new STPStartInfo(); - startInfo.IdleTimeout = 2000; // 2 seconds - startInfo.MaxWorkerThreads = maxThreads; - startInfo.MinWorkerThreads = 2; - startInfo.ThreadPriority = ThreadPriority.Normal; - startInfo.StartSuspended = false; + throw new InvalidOperationException("SmartThreadPool is already initialized"); - m_ThreadPool = new SmartThreadPool(startInfo); + m_ThreadPool = new SmartThreadPool(2000, maxThreads, 2); } public static void FireAndForget(System.Threading.WaitCallback callback, object obj) @@ -1343,20 +1335,22 @@ namespace OpenSim.Framework switch (FireAndForgetMethod) { case FireAndForgetMethod.UnsafeQueueUserWorkItem: - System.Threading.ThreadPool.UnsafeQueueUserWorkItem(callback, obj); + ThreadPool.UnsafeQueueUserWorkItem(callback, obj); break; case FireAndForgetMethod.QueueUserWorkItem: - System.Threading.ThreadPool.QueueUserWorkItem(callback, obj); + ThreadPool.QueueUserWorkItem(callback, obj); break; case FireAndForgetMethod.BeginInvoke: FireAndForgetWrapper wrapper = Singleton.GetInstance(); wrapper.FireAndForget(callback, obj); break; case FireAndForgetMethod.SmartThreadPool: + if (m_ThreadPool != null) + m_ThreadPool = new SmartThreadPool(2000, 15, 2); m_ThreadPool.QueueWorkItem(delegate(object o) { callback(o); return null; }, obj); break; case FireAndForgetMethod.Thread: - System.Threading.Thread thread = new System.Threading.Thread(delegate(object o) { callback(o); }); + Thread thread = new Thread(delegate(object o) { callback(o); }); thread.Start(obj); break; default: -- cgit v1.1