* 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() function0.6.8-post-fixes
parent
4121a02936
commit
6ca4b0f366
|
@ -1324,18 +1324,10 @@ namespace OpenSim.Framework
|
||||||
{
|
{
|
||||||
if (maxThreads < 2)
|
if (maxThreads < 2)
|
||||||
throw new ArgumentOutOfRangeException("maxThreads", "maxThreads must be greater than 2");
|
throw new ArgumentOutOfRangeException("maxThreads", "maxThreads must be greater than 2");
|
||||||
|
|
||||||
if (m_ThreadPool != null)
|
if (m_ThreadPool != null)
|
||||||
return;
|
throw new InvalidOperationException("SmartThreadPool is already initialized");
|
||||||
|
|
||||||
STPStartInfo startInfo = new STPStartInfo();
|
m_ThreadPool = new SmartThreadPool(2000, maxThreads, 2);
|
||||||
startInfo.IdleTimeout = 2000; // 2 seconds
|
|
||||||
startInfo.MaxWorkerThreads = maxThreads;
|
|
||||||
startInfo.MinWorkerThreads = 2;
|
|
||||||
startInfo.ThreadPriority = ThreadPriority.Normal;
|
|
||||||
startInfo.StartSuspended = false;
|
|
||||||
|
|
||||||
m_ThreadPool = new SmartThreadPool(startInfo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void FireAndForget(System.Threading.WaitCallback callback, object obj)
|
public static void FireAndForget(System.Threading.WaitCallback callback, object obj)
|
||||||
|
@ -1343,20 +1335,22 @@ namespace OpenSim.Framework
|
||||||
switch (FireAndForgetMethod)
|
switch (FireAndForgetMethod)
|
||||||
{
|
{
|
||||||
case FireAndForgetMethod.UnsafeQueueUserWorkItem:
|
case FireAndForgetMethod.UnsafeQueueUserWorkItem:
|
||||||
System.Threading.ThreadPool.UnsafeQueueUserWorkItem(callback, obj);
|
ThreadPool.UnsafeQueueUserWorkItem(callback, obj);
|
||||||
break;
|
break;
|
||||||
case FireAndForgetMethod.QueueUserWorkItem:
|
case FireAndForgetMethod.QueueUserWorkItem:
|
||||||
System.Threading.ThreadPool.QueueUserWorkItem(callback, obj);
|
ThreadPool.QueueUserWorkItem(callback, obj);
|
||||||
break;
|
break;
|
||||||
case FireAndForgetMethod.BeginInvoke:
|
case FireAndForgetMethod.BeginInvoke:
|
||||||
FireAndForgetWrapper wrapper = Singleton.GetInstance<FireAndForgetWrapper>();
|
FireAndForgetWrapper wrapper = Singleton.GetInstance<FireAndForgetWrapper>();
|
||||||
wrapper.FireAndForget(callback, obj);
|
wrapper.FireAndForget(callback, obj);
|
||||||
break;
|
break;
|
||||||
case FireAndForgetMethod.SmartThreadPool:
|
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);
|
m_ThreadPool.QueueWorkItem(delegate(object o) { callback(o); return null; }, obj);
|
||||||
break;
|
break;
|
||||||
case FireAndForgetMethod.Thread:
|
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);
|
thread.Start(obj);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue