aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Util.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Util.cs')
-rw-r--r--OpenSim/Framework/Util.cs91
1 files changed, 1 insertions, 90 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index e12d37a..6e0d30d 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -111,9 +111,7 @@ namespace OpenSim.Framework
111 { 111 {
112 None, 112 None,
113 RegressionTest, 113 RegressionTest,
114 UnsafeQueueUserWorkItem,
115 QueueUserWorkItem, 114 QueueUserWorkItem,
116 BeginInvoke,
117 SmartThreadPool, 115 SmartThreadPool,
118 Thread, 116 Thread,
119 } 117 }
@@ -2412,27 +2410,8 @@ namespace OpenSim.Framework
2412 /// </summary> 2410 /// </summary>
2413 private sealed class FireAndForgetWrapper 2411 private sealed class FireAndForgetWrapper
2414 { 2412 {
2415 private static volatile FireAndForgetWrapper instance;
2416 private static object syncRoot = new Object(); 2413 private static object syncRoot = new Object();
2417 2414
2418 public static FireAndForgetWrapper Instance {
2419 get {
2420
2421 if (instance == null)
2422 {
2423 lock (syncRoot)
2424 {
2425 if (instance == null)
2426 {
2427 instance = new FireAndForgetWrapper();
2428 }
2429 }
2430 }
2431
2432 return instance;
2433 }
2434 }
2435
2436 public void FireAndForget(System.Threading.WaitCallback callback) 2415 public void FireAndForget(System.Threading.WaitCallback callback)
2437 { 2416 {
2438 callback.BeginInvoke(null, EndFireAndForget, callback); 2417 callback.BeginInvoke(null, EndFireAndForget, callback);
@@ -2484,9 +2463,7 @@ namespace OpenSim.Framework
2484 2463
2485 switch (FireAndForgetMethod) 2464 switch (FireAndForgetMethod)
2486 { 2465 {
2487 case FireAndForgetMethod.UnsafeQueueUserWorkItem:
2488 case FireAndForgetMethod.QueueUserWorkItem: 2466 case FireAndForgetMethod.QueueUserWorkItem:
2489 case FireAndForgetMethod.BeginInvoke:
2490 int workerThreads, iocpThreads; 2467 int workerThreads, iocpThreads;
2491 ThreadPool.GetAvailableThreads(out workerThreads, out iocpThreads); 2468 ThreadPool.GetAvailableThreads(out workerThreads, out iocpThreads);
2492 return workerThreads; 2469 return workerThreads;
@@ -2640,20 +2617,6 @@ namespace OpenSim.Framework
2640 public static void FireAndForget(System.Threading.WaitCallback callback, object obj, string context, bool dotimeout = true) 2617 public static void FireAndForget(System.Threading.WaitCallback callback, object obj, string context, bool dotimeout = true)
2641 { 2618 {
2642 Interlocked.Increment(ref numTotalThreadFuncsCalled); 2619 Interlocked.Increment(ref numTotalThreadFuncsCalled);
2643/*
2644 if (context != null)
2645 {
2646 if (!m_fireAndForgetCallsMade.ContainsKey(context))
2647 m_fireAndForgetCallsMade[context] = 1;
2648 else
2649 m_fireAndForgetCallsMade[context]++;
2650
2651 if (!m_fireAndForgetCallsInProgress.ContainsKey(context))
2652 m_fireAndForgetCallsInProgress[context] = 1;
2653 else
2654 m_fireAndForgetCallsInProgress[context]++;
2655 }
2656*/
2657 WaitCallback realCallback; 2620 WaitCallback realCallback;
2658 2621
2659 bool loggingEnabled = LogThreadPool > 0; 2622 bool loggingEnabled = LogThreadPool > 0;
@@ -2669,9 +2632,6 @@ namespace OpenSim.Framework
2669 { 2632 {
2670 Culture.SetCurrentCulture(); 2633 Culture.SetCurrentCulture();
2671 callback(o); 2634 callback(o);
2672
2673// if (context != null)
2674// m_fireAndForgetCallsInProgress[context]--;
2675 }; 2635 };
2676 } 2636 }
2677 else 2637 else
@@ -2692,7 +2652,6 @@ namespace OpenSim.Framework
2692 m_log.DebugFormat("Run threadfunc {0} (Queued {1}, Running {2})", threadFuncNum, numQueued1, numRunning1); 2652 m_log.DebugFormat("Run threadfunc {0} (Queued {1}, Running {2})", threadFuncNum, numQueued1, numRunning1);
2693 2653
2694 Culture.SetCurrentCulture(); 2654 Culture.SetCurrentCulture();
2695
2696 callback(o); 2655 callback(o);
2697 } 2656 }
2698 catch (ThreadAbortException) 2657 catch (ThreadAbortException)
@@ -2710,9 +2669,6 @@ namespace OpenSim.Framework
2710 activeThreads.TryRemove(threadFuncNum, out dummy); 2669 activeThreads.TryRemove(threadFuncNum, out dummy);
2711 if ((loggingEnabled || (threadFuncOverloadMode == 1)) && threadInfo.LogThread) 2670 if ((loggingEnabled || (threadFuncOverloadMode == 1)) && threadInfo.LogThread)
2712 m_log.DebugFormat("Exit threadfunc {0} ({1})", threadFuncNum, FormatDuration(threadInfo.Elapsed())); 2671 m_log.DebugFormat("Exit threadfunc {0} ({1})", threadFuncNum, FormatDuration(threadInfo.Elapsed()));
2713
2714// if (context != null)
2715// m_fireAndForgetCallsInProgress[context]--;
2716 } 2672 }
2717 }; 2673 };
2718 } 2674 }
@@ -2720,45 +2676,7 @@ namespace OpenSim.Framework
2720 long numQueued = Interlocked.Increment(ref numQueuedThreadFuncs); 2676 long numQueued = Interlocked.Increment(ref numQueuedThreadFuncs);
2721 try 2677 try
2722 { 2678 {
2723/* 2679 threadInfo.LogThread = false;
2724 long numRunning = numRunningThreadFuncs;
2725
2726 if (m_ThreadPool != null && LogOverloads)
2727 {
2728 if ((threadFuncOverloadMode == 0) && (numRunning >= m_ThreadPool.MaxThreads))
2729 {
2730 if (Interlocked.CompareExchange(ref threadFuncOverloadMode, 1, 0) == 0)
2731 m_log.DebugFormat("Threadfunc: enable overload mode (Queued {0}, Running {1})", numQueued, numRunning);
2732 }
2733 else if ((threadFuncOverloadMode == 1) && (numRunning <= (m_ThreadPool.MaxThreads * 2) / 3))
2734 {
2735 if (Interlocked.CompareExchange(ref threadFuncOverloadMode, 0, 1) == 1)
2736 m_log.DebugFormat("Threadfunc: disable overload mode (Queued {0}, Running {1})", numQueued, numRunning);
2737 }
2738 }
2739
2740 if (loggingEnabled || (threadFuncOverloadMode == 1))
2741 {
2742 string full, partial;
2743 GetFireAndForgetStackTrace(out full, out partial);
2744 threadInfo.StackTrace = full;
2745 threadInfo.LogThread = ShouldLogThread(partial);
2746
2747 if (threadInfo.LogThread)
2748 {
2749 m_log.DebugFormat("Queue threadfunc {0} (Queued {1}, Running {2}) {3}{4}",
2750 threadFuncNum, numQueued, numRunningThreadFuncs,
2751 (context == null) ? "" : ("(" + context + ") "),
2752 (LogThreadPool >= 2) ? full : partial);
2753 }
2754 }
2755 else
2756*/
2757 {
2758 // Since we didn't log "Queue threadfunc", don't log "Run threadfunc" or "End threadfunc" either.
2759 // Those log lines aren't useful when we don't know which function is running in the thread.
2760 threadInfo.LogThread = false;
2761 }
2762 2680
2763 switch (FireAndForgetMethod) 2681 switch (FireAndForgetMethod)
2764 { 2682 {
@@ -2766,16 +2684,9 @@ namespace OpenSim.Framework
2766 case FireAndForgetMethod.None: 2684 case FireAndForgetMethod.None:
2767 realCallback.Invoke(obj); 2685 realCallback.Invoke(obj);
2768 break; 2686 break;
2769 case FireAndForgetMethod.UnsafeQueueUserWorkItem:
2770 ThreadPool.UnsafeQueueUserWorkItem(realCallback, obj);
2771 break;
2772 case FireAndForgetMethod.QueueUserWorkItem: 2687 case FireAndForgetMethod.QueueUserWorkItem:
2773 ThreadPool.QueueUserWorkItem(realCallback, obj); 2688 ThreadPool.QueueUserWorkItem(realCallback, obj);
2774 break; 2689 break;
2775 case FireAndForgetMethod.BeginInvoke:
2776 FireAndForgetWrapper wrapper = FireAndForgetWrapper.Instance;
2777 wrapper.FireAndForget(realCallback, obj);
2778 break;
2779 case FireAndForgetMethod.SmartThreadPool: 2690 case FireAndForgetMethod.SmartThreadPool:
2780 if (m_ThreadPool == null) 2691 if (m_ThreadPool == null)
2781 InitThreadPool(2, 15); 2692 InitThreadPool(2, 15);