diff options
Diffstat (limited to 'OpenSim/Framework/Util.cs')
-rw-r--r-- | OpenSim/Framework/Util.cs | 64 |
1 files changed, 55 insertions, 9 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index e76a37b..e0d4d74 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs | |||
@@ -299,6 +299,25 @@ namespace OpenSim.Framework | |||
299 | x; | 299 | x; |
300 | } | 300 | } |
301 | 301 | ||
302 | // Clamp the maximum magnitude of a vector | ||
303 | public static Vector3 ClampV(Vector3 x, float max) | ||
304 | { | ||
305 | Vector3 ret = x; | ||
306 | float lenSq = x.LengthSquared(); | ||
307 | if (lenSq > (max * max)) | ||
308 | { | ||
309 | x = x / x.Length() * max; | ||
310 | } | ||
311 | return x; | ||
312 | } | ||
313 | |||
314 | // Inclusive, within range test (true if equal to the endpoints) | ||
315 | public static bool InRange<T>(T x, T min, T max) | ||
316 | where T : IComparable<T> | ||
317 | { | ||
318 | return x.CompareTo(max) <= 0 && x.CompareTo(min) >= 0; | ||
319 | } | ||
320 | |||
302 | public static uint GetNextXferID() | 321 | public static uint GetNextXferID() |
303 | { | 322 | { |
304 | uint id = 0; | 323 | uint id = 0; |
@@ -1651,7 +1670,13 @@ namespace OpenSim.Framework | |||
1651 | if (m_ThreadPool != null) | 1670 | if (m_ThreadPool != null) |
1652 | throw new InvalidOperationException("SmartThreadPool is already initialized"); | 1671 | throw new InvalidOperationException("SmartThreadPool is already initialized"); |
1653 | 1672 | ||
1654 | m_ThreadPool = new SmartThreadPool(2000, maxThreads, 2); | 1673 | STPStartInfo startInfo = new STPStartInfo(); |
1674 | startInfo.ThreadPoolName = "Util"; | ||
1675 | startInfo.IdleTimeout = 2000; | ||
1676 | startInfo.MaxWorkerThreads = maxThreads; | ||
1677 | startInfo.MinWorkerThreads = 2; | ||
1678 | |||
1679 | m_ThreadPool = new SmartThreadPool(startInfo); | ||
1655 | } | 1680 | } |
1656 | 1681 | ||
1657 | public static int FireAndForgetCount() | 1682 | public static int FireAndForgetCount() |
@@ -1724,7 +1749,7 @@ namespace OpenSim.Framework | |||
1724 | break; | 1749 | break; |
1725 | case FireAndForgetMethod.SmartThreadPool: | 1750 | case FireAndForgetMethod.SmartThreadPool: |
1726 | if (m_ThreadPool == null) | 1751 | if (m_ThreadPool == null) |
1727 | m_ThreadPool = new SmartThreadPool(2000, 15, 2); | 1752 | InitThreadPool(15); |
1728 | m_ThreadPool.QueueWorkItem(SmartThreadPoolCallback, new object[] { realCallback, obj }); | 1753 | m_ThreadPool.QueueWorkItem(SmartThreadPoolCallback, new object[] { realCallback, obj }); |
1729 | break; | 1754 | break; |
1730 | case FireAndForgetMethod.Thread: | 1755 | case FireAndForgetMethod.Thread: |
@@ -1753,12 +1778,16 @@ namespace OpenSim.Framework | |||
1753 | StringBuilder sb = new StringBuilder(); | 1778 | StringBuilder sb = new StringBuilder(); |
1754 | if (FireAndForgetMethod == FireAndForgetMethod.SmartThreadPool) | 1779 | if (FireAndForgetMethod == FireAndForgetMethod.SmartThreadPool) |
1755 | { | 1780 | { |
1756 | threadPoolUsed = "SmartThreadPool"; | 1781 | // ROBUST currently leaves this the FireAndForgetMethod but never actually initializes the threadpool. |
1757 | maxThreads = m_ThreadPool.MaxThreads; | 1782 | if (m_ThreadPool != null) |
1758 | minThreads = m_ThreadPool.MinThreads; | 1783 | { |
1759 | inUseThreads = m_ThreadPool.InUseThreads; | 1784 | threadPoolUsed = "SmartThreadPool"; |
1760 | allocatedThreads = m_ThreadPool.ActiveThreads; | 1785 | maxThreads = m_ThreadPool.MaxThreads; |
1761 | waitingCallbacks = m_ThreadPool.WaitingCallbacks; | 1786 | minThreads = m_ThreadPool.MinThreads; |
1787 | inUseThreads = m_ThreadPool.InUseThreads; | ||
1788 | allocatedThreads = m_ThreadPool.ActiveThreads; | ||
1789 | waitingCallbacks = m_ThreadPool.WaitingCallbacks; | ||
1790 | } | ||
1762 | } | 1791 | } |
1763 | else if ( | 1792 | else if ( |
1764 | FireAndForgetMethod == FireAndForgetMethod.UnsafeQueueUserWorkItem | 1793 | FireAndForgetMethod == FireAndForgetMethod.UnsafeQueueUserWorkItem |
@@ -1863,6 +1892,12 @@ namespace OpenSim.Framework | |||
1863 | /// </summary> | 1892 | /// </summary> |
1864 | public static void PrintCallStack() | 1893 | public static void PrintCallStack() |
1865 | { | 1894 | { |
1895 | PrintCallStack(m_log.DebugFormat); | ||
1896 | } | ||
1897 | |||
1898 | public delegate void DebugPrinter(string msg, params Object[] parm); | ||
1899 | public static void PrintCallStack(DebugPrinter printer) | ||
1900 | { | ||
1866 | StackTrace stackTrace = new StackTrace(true); // get call stack | 1901 | StackTrace stackTrace = new StackTrace(true); // get call stack |
1867 | StackFrame[] stackFrames = stackTrace.GetFrames(); // get method calls (frames) | 1902 | StackFrame[] stackFrames = stackTrace.GetFrames(); // get method calls (frames) |
1868 | 1903 | ||
@@ -1870,7 +1905,7 @@ namespace OpenSim.Framework | |||
1870 | foreach (StackFrame stackFrame in stackFrames) | 1905 | foreach (StackFrame stackFrame in stackFrames) |
1871 | { | 1906 | { |
1872 | MethodBase mb = stackFrame.GetMethod(); | 1907 | MethodBase mb = stackFrame.GetMethod(); |
1873 | m_log.DebugFormat("{0}.{1}:{2}", mb.DeclaringType, mb.Name, stackFrame.GetFileLineNumber()); // write method name | 1908 | printer("{0}.{1}:{2}", mb.DeclaringType, mb.Name, stackFrame.GetFileLineNumber()); // write method name |
1874 | } | 1909 | } |
1875 | } | 1910 | } |
1876 | 1911 | ||
@@ -2096,5 +2131,16 @@ namespace OpenSim.Framework | |||
2096 | return firstName + "." + lastName + " " + "@" + uri.Authority; | 2131 | return firstName + "." + lastName + " " + "@" + uri.Authority; |
2097 | } | 2132 | } |
2098 | #endregion | 2133 | #endregion |
2134 | |||
2135 | /// <summary> | ||
2136 | /// Escapes the special characters used in "LIKE". | ||
2137 | /// </summary> | ||
2138 | /// <remarks> | ||
2139 | /// For example: EscapeForLike("foo_bar%baz") = "foo\_bar\%baz" | ||
2140 | /// </remarks> | ||
2141 | public static string EscapeForLike(string str) | ||
2142 | { | ||
2143 | return str.Replace("_", "\\_").Replace("%", "\\%"); | ||
2144 | } | ||
2099 | } | 2145 | } |
2100 | } | 2146 | } |