diff options
Diffstat (limited to 'OpenSim/Framework/Util.cs')
-rw-r--r-- | OpenSim/Framework/Util.cs | 63 |
1 files changed, 53 insertions, 10 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index fefa050..97c958a 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs | |||
@@ -1928,11 +1928,6 @@ namespace OpenSim.Framework | |||
1928 | } | 1928 | } |
1929 | } | 1929 | } |
1930 | 1930 | ||
1931 | public static void FireAndForget(System.Threading.WaitCallback callback) | ||
1932 | { | ||
1933 | FireAndForget(callback, null, null); | ||
1934 | } | ||
1935 | |||
1936 | public static void InitThreadPool(int minThreads, int maxThreads) | 1931 | public static void InitThreadPool(int minThreads, int maxThreads) |
1937 | { | 1932 | { |
1938 | if (maxThreads < 2) | 1933 | if (maxThreads < 2) |
@@ -1977,8 +1972,7 @@ namespace OpenSim.Framework | |||
1977 | throw new NotImplementedException(); | 1972 | throw new NotImplementedException(); |
1978 | } | 1973 | } |
1979 | } | 1974 | } |
1980 | 1975 | ||
1981 | |||
1982 | /// <summary> | 1976 | /// <summary> |
1983 | /// Additional information about threads in the main thread pool. Used to time how long the | 1977 | /// Additional information about threads in the main thread pool. Used to time how long the |
1984 | /// thread has been running, and abort it if it has timed-out. | 1978 | /// thread has been running, and abort it if it has timed-out. |
@@ -2052,12 +2046,15 @@ namespace OpenSim.Framework | |||
2052 | } | 2046 | } |
2053 | } | 2047 | } |
2054 | 2048 | ||
2055 | |||
2056 | private static long nextThreadFuncNum = 0; | 2049 | private static long nextThreadFuncNum = 0; |
2057 | private static long numQueuedThreadFuncs = 0; | 2050 | private static long numQueuedThreadFuncs = 0; |
2058 | private static long numRunningThreadFuncs = 0; | 2051 | private static long numRunningThreadFuncs = 0; |
2052 | private static long numTotalThreadFuncsCalled = 0; | ||
2059 | private static Int32 threadFuncOverloadMode = 0; | 2053 | private static Int32 threadFuncOverloadMode = 0; |
2060 | 2054 | ||
2055 | public static long TotalQueuedFireAndForgetCalls { get { return numQueuedThreadFuncs; } } | ||
2056 | public static long TotalRunningFireAndForgetCalls { get { return numRunningThreadFuncs; } } | ||
2057 | |||
2061 | // Maps (ThreadFunc number -> Thread) | 2058 | // Maps (ThreadFunc number -> Thread) |
2062 | private static ConcurrentDictionary<long, ThreadInfo> activeThreads = new ConcurrentDictionary<long, ThreadInfo>(); | 2059 | private static ConcurrentDictionary<long, ThreadInfo> activeThreads = new ConcurrentDictionary<long, ThreadInfo>(); |
2063 | 2060 | ||
@@ -2086,14 +2083,49 @@ namespace OpenSim.Framework | |||
2086 | } | 2083 | } |
2087 | } | 2084 | } |
2088 | 2085 | ||
2086 | public static long TotalFireAndForgetCallsMade { get { return numTotalThreadFuncsCalled; } } | ||
2087 | |||
2088 | public static Dictionary<string, int> GetFireAndForgetCallsMade() | ||
2089 | { | ||
2090 | return new Dictionary<string, int>(m_fireAndForgetCallsMade); | ||
2091 | } | ||
2092 | |||
2093 | private static Dictionary<string, int> m_fireAndForgetCallsMade = new Dictionary<string, int>(); | ||
2094 | |||
2095 | public static Dictionary<string, int> GetFireAndForgetCallsInProgress() | ||
2096 | { | ||
2097 | return new Dictionary<string, int>(m_fireAndForgetCallsInProgress); | ||
2098 | } | ||
2099 | |||
2100 | private static Dictionary<string, int> m_fireAndForgetCallsInProgress = new Dictionary<string, int>(); | ||
2101 | |||
2102 | public static void FireAndForget(System.Threading.WaitCallback callback) | ||
2103 | { | ||
2104 | FireAndForget(callback, null, null); | ||
2105 | } | ||
2089 | 2106 | ||
2090 | public static void FireAndForget(System.Threading.WaitCallback callback, object obj) | 2107 | public static void FireAndForget(System.Threading.WaitCallback callback, object obj) |
2091 | { | 2108 | { |
2092 | FireAndForget(callback, obj, null); | 2109 | FireAndForget(callback, obj, null); |
2093 | } | 2110 | } |
2094 | 2111 | ||
2095 | public static void FireAndForget(System.Threading.WaitCallback callback, object obj, string context) | 2112 | public static void FireAndForget(System.Threading.WaitCallback callback, object obj, string context) |
2096 | { | 2113 | { |
2114 | Interlocked.Increment(ref numTotalThreadFuncsCalled); | ||
2115 | |||
2116 | if (context != null) | ||
2117 | { | ||
2118 | if (!m_fireAndForgetCallsMade.ContainsKey(context)) | ||
2119 | m_fireAndForgetCallsMade[context] = 1; | ||
2120 | else | ||
2121 | m_fireAndForgetCallsMade[context]++; | ||
2122 | |||
2123 | if (!m_fireAndForgetCallsInProgress.ContainsKey(context)) | ||
2124 | m_fireAndForgetCallsInProgress[context] = 1; | ||
2125 | else | ||
2126 | m_fireAndForgetCallsInProgress[context]++; | ||
2127 | } | ||
2128 | |||
2097 | WaitCallback realCallback; | 2129 | WaitCallback realCallback; |
2098 | 2130 | ||
2099 | bool loggingEnabled = LogThreadPool > 0; | 2131 | bool loggingEnabled = LogThreadPool > 0; |
@@ -2104,7 +2136,15 @@ namespace OpenSim.Framework | |||
2104 | if (FireAndForgetMethod == FireAndForgetMethod.RegressionTest) | 2136 | if (FireAndForgetMethod == FireAndForgetMethod.RegressionTest) |
2105 | { | 2137 | { |
2106 | // If we're running regression tests, then we want any exceptions to rise up to the test code. | 2138 | // If we're running regression tests, then we want any exceptions to rise up to the test code. |
2107 | realCallback = o => { Culture.SetCurrentCulture(); callback(o); }; | 2139 | realCallback = |
2140 | o => | ||
2141 | { | ||
2142 | Culture.SetCurrentCulture(); | ||
2143 | callback(o); | ||
2144 | |||
2145 | if (context != null) | ||
2146 | m_fireAndForgetCallsInProgress[context]--; | ||
2147 | }; | ||
2108 | } | 2148 | } |
2109 | else | 2149 | else |
2110 | { | 2150 | { |
@@ -2143,6 +2183,9 @@ namespace OpenSim.Framework | |||
2143 | activeThreads.TryRemove(threadFuncNum, out dummy); | 2183 | activeThreads.TryRemove(threadFuncNum, out dummy); |
2144 | if ((loggingEnabled || (threadFuncOverloadMode == 1)) && threadInfo.LogThread) | 2184 | if ((loggingEnabled || (threadFuncOverloadMode == 1)) && threadInfo.LogThread) |
2145 | m_log.DebugFormat("Exit threadfunc {0} ({1})", threadFuncNum, FormatDuration(threadInfo.Elapsed())); | 2185 | m_log.DebugFormat("Exit threadfunc {0} ({1})", threadFuncNum, FormatDuration(threadInfo.Elapsed())); |
2186 | |||
2187 | if (context != null) | ||
2188 | m_fireAndForgetCallsInProgress[context]--; | ||
2146 | } | 2189 | } |
2147 | }; | 2190 | }; |
2148 | } | 2191 | } |