add option for Fireandforget not timeout (our access to main smartThreadPool)

0.9.0-post-fixes
UbitUmarov 2017-06-13 18:39:42 +01:00
parent f33a871d61
commit 5ce15566ac
2 changed files with 9 additions and 9 deletions

View File

@ -182,9 +182,9 @@ namespace OpenSim.Framework.Monitoring
/// <param name="callback"></param>
/// <param name="obj"></param>
/// <param name="name">The name of the job. This is used in monitoring and debugging.</param>
public static void RunInThreadPool(System.Threading.WaitCallback callback, object obj, string name)
public static void RunInThreadPool(System.Threading.WaitCallback callback, object obj, string name, bool timeout = true)
{
Util.FireAndForget(callback, obj, name);
Util.FireAndForget(callback, obj, name, timeout);
}
/// <summary>
@ -231,10 +231,8 @@ namespace OpenSim.Framework.Monitoring
JobEngine.QueueJob(name, () => callback(obj));
else if (canRunInThisThread)
callback(obj);
else if (mustNotTimeout)
RunInThread(callback, obj, name, log);
else
Util.FireAndForget(callback, obj, name);
Util.FireAndForget(callback, obj, name, !mustNotTimeout);
}
private static void HandleControlCommand(string module, string[] args)

View File

@ -2492,8 +2492,9 @@ namespace OpenSim.Framework
public bool Running { get; set; }
public bool Aborted { get; set; }
private int started;
public bool DoTimeout;
public ThreadInfo(long threadFuncNum, string context)
public ThreadInfo(long threadFuncNum, string context, bool dotimeout = true)
{
ThreadFuncNum = threadFuncNum;
this.context = context;
@ -2501,6 +2502,7 @@ namespace OpenSim.Framework
Thread = null;
Running = false;
Aborted = false;
DoTimeout = dotimeout;
}
public void Started()
@ -2571,7 +2573,7 @@ namespace OpenSim.Framework
foreach (KeyValuePair<long, ThreadInfo> entry in activeThreads)
{
ThreadInfo t = entry.Value;
if (t.Running && !t.Aborted && (t.Elapsed() >= THREAD_TIMEOUT))
if (t.DoTimeout && t.Running && !t.Aborted && (t.Elapsed() >= THREAD_TIMEOUT))
{
m_log.WarnFormat("Timeout in threadfunc {0} ({1}) {2}", t.ThreadFuncNum, t.Thread.Name, t.GetStackTrace());
t.Abort();
@ -2612,7 +2614,7 @@ namespace OpenSim.Framework
FireAndForget(callback, obj, null);
}
public static void FireAndForget(System.Threading.WaitCallback callback, object obj, string context)
public static void FireAndForget(System.Threading.WaitCallback callback, object obj, string context, bool dotimeout = true)
{
Interlocked.Increment(ref numTotalThreadFuncsCalled);
@ -2634,7 +2636,7 @@ namespace OpenSim.Framework
bool loggingEnabled = LogThreadPool > 0;
long threadFuncNum = Interlocked.Increment(ref nextThreadFuncNum);
ThreadInfo threadInfo = new ThreadInfo(threadFuncNum, context);
ThreadInfo threadInfo = new ThreadInfo(threadFuncNum, context, dotimeout);
if (FireAndForgetMethod == FireAndForgetMethod.RegressionTest)
{