diff options
Diffstat (limited to 'OpenSim/Framework/Util.cs')
-rw-r--r-- | OpenSim/Framework/Util.cs | 80 |
1 files changed, 70 insertions, 10 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 48f3f8b..0545365 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs | |||
@@ -45,6 +45,7 @@ using System.Text.RegularExpressions; | |||
45 | using System.Xml; | 45 | using System.Xml; |
46 | using System.Threading; | 46 | using System.Threading; |
47 | using log4net; | 47 | using log4net; |
48 | using log4net.Appender; | ||
48 | using Nini.Config; | 49 | using Nini.Config; |
49 | using Nwc.XmlRpc; | 50 | using Nwc.XmlRpc; |
50 | using OpenMetaverse; | 51 | using OpenMetaverse; |
@@ -299,6 +300,25 @@ namespace OpenSim.Framework | |||
299 | x; | 300 | x; |
300 | } | 301 | } |
301 | 302 | ||
303 | // Clamp the maximum magnitude of a vector | ||
304 | public static Vector3 ClampV(Vector3 x, float max) | ||
305 | { | ||
306 | Vector3 ret = x; | ||
307 | float lenSq = x.LengthSquared(); | ||
308 | if (lenSq > (max * max)) | ||
309 | { | ||
310 | x = x / x.Length() * max; | ||
311 | } | ||
312 | return x; | ||
313 | } | ||
314 | |||
315 | // Inclusive, within range test (true if equal to the endpoints) | ||
316 | public static bool InRange<T>(T x, T min, T max) | ||
317 | where T : IComparable<T> | ||
318 | { | ||
319 | return x.CompareTo(max) <= 0 && x.CompareTo(min) >= 0; | ||
320 | } | ||
321 | |||
302 | public static uint GetNextXferID() | 322 | public static uint GetNextXferID() |
303 | { | 323 | { |
304 | uint id = 0; | 324 | uint id = 0; |
@@ -809,9 +829,22 @@ namespace OpenSim.Framework | |||
809 | return "."; | 829 | return "."; |
810 | } | 830 | } |
811 | 831 | ||
832 | public static string logFile() | ||
833 | { | ||
834 | foreach (IAppender appender in LogManager.GetRepository().GetAppenders()) | ||
835 | { | ||
836 | if (appender is FileAppender) | ||
837 | { | ||
838 | return ((FileAppender)appender).File; | ||
839 | } | ||
840 | } | ||
841 | |||
842 | return "./OpenSim.log"; | ||
843 | } | ||
844 | |||
812 | public static string logDir() | 845 | public static string logDir() |
813 | { | 846 | { |
814 | return "."; | 847 | return Path.GetDirectoryName(logFile()); |
815 | } | 848 | } |
816 | 849 | ||
817 | // From: http://coercedcode.blogspot.com/2008/03/c-generate-unique-filenames-within.html | 850 | // From: http://coercedcode.blogspot.com/2008/03/c-generate-unique-filenames-within.html |
@@ -1651,7 +1684,13 @@ namespace OpenSim.Framework | |||
1651 | if (m_ThreadPool != null) | 1684 | if (m_ThreadPool != null) |
1652 | throw new InvalidOperationException("SmartThreadPool is already initialized"); | 1685 | throw new InvalidOperationException("SmartThreadPool is already initialized"); |
1653 | 1686 | ||
1654 | m_ThreadPool = new SmartThreadPool(2000, maxThreads, 2); | 1687 | STPStartInfo startInfo = new STPStartInfo(); |
1688 | startInfo.ThreadPoolName = "Util"; | ||
1689 | startInfo.IdleTimeout = 2000; | ||
1690 | startInfo.MaxWorkerThreads = maxThreads; | ||
1691 | startInfo.MinWorkerThreads = 2; | ||
1692 | |||
1693 | m_ThreadPool = new SmartThreadPool(startInfo); | ||
1655 | } | 1694 | } |
1656 | 1695 | ||
1657 | public static int FireAndForgetCount() | 1696 | public static int FireAndForgetCount() |
@@ -1724,7 +1763,7 @@ namespace OpenSim.Framework | |||
1724 | break; | 1763 | break; |
1725 | case FireAndForgetMethod.SmartThreadPool: | 1764 | case FireAndForgetMethod.SmartThreadPool: |
1726 | if (m_ThreadPool == null) | 1765 | if (m_ThreadPool == null) |
1727 | m_ThreadPool = new SmartThreadPool(2000, 15, 2); | 1766 | InitThreadPool(15); |
1728 | m_ThreadPool.QueueWorkItem(SmartThreadPoolCallback, new object[] { realCallback, obj }); | 1767 | m_ThreadPool.QueueWorkItem(SmartThreadPoolCallback, new object[] { realCallback, obj }); |
1729 | break; | 1768 | break; |
1730 | case FireAndForgetMethod.Thread: | 1769 | case FireAndForgetMethod.Thread: |
@@ -1753,12 +1792,16 @@ namespace OpenSim.Framework | |||
1753 | StringBuilder sb = new StringBuilder(); | 1792 | StringBuilder sb = new StringBuilder(); |
1754 | if (FireAndForgetMethod == FireAndForgetMethod.SmartThreadPool) | 1793 | if (FireAndForgetMethod == FireAndForgetMethod.SmartThreadPool) |
1755 | { | 1794 | { |
1756 | threadPoolUsed = "SmartThreadPool"; | 1795 | // ROBUST currently leaves this the FireAndForgetMethod but never actually initializes the threadpool. |
1757 | maxThreads = m_ThreadPool.MaxThreads; | 1796 | if (m_ThreadPool != null) |
1758 | minThreads = m_ThreadPool.MinThreads; | 1797 | { |
1759 | inUseThreads = m_ThreadPool.InUseThreads; | 1798 | threadPoolUsed = "SmartThreadPool"; |
1760 | allocatedThreads = m_ThreadPool.ActiveThreads; | 1799 | maxThreads = m_ThreadPool.MaxThreads; |
1761 | waitingCallbacks = m_ThreadPool.WaitingCallbacks; | 1800 | minThreads = m_ThreadPool.MinThreads; |
1801 | inUseThreads = m_ThreadPool.InUseThreads; | ||
1802 | allocatedThreads = m_ThreadPool.ActiveThreads; | ||
1803 | waitingCallbacks = m_ThreadPool.WaitingCallbacks; | ||
1804 | } | ||
1762 | } | 1805 | } |
1763 | else if ( | 1806 | else if ( |
1764 | FireAndForgetMethod == FireAndForgetMethod.UnsafeQueueUserWorkItem | 1807 | FireAndForgetMethod == FireAndForgetMethod.UnsafeQueueUserWorkItem |
@@ -1863,6 +1906,12 @@ namespace OpenSim.Framework | |||
1863 | /// </summary> | 1906 | /// </summary> |
1864 | public static void PrintCallStack() | 1907 | public static void PrintCallStack() |
1865 | { | 1908 | { |
1909 | PrintCallStack(m_log.DebugFormat); | ||
1910 | } | ||
1911 | |||
1912 | public delegate void DebugPrinter(string msg, params Object[] parm); | ||
1913 | public static void PrintCallStack(DebugPrinter printer) | ||
1914 | { | ||
1866 | StackTrace stackTrace = new StackTrace(true); // get call stack | 1915 | StackTrace stackTrace = new StackTrace(true); // get call stack |
1867 | StackFrame[] stackFrames = stackTrace.GetFrames(); // get method calls (frames) | 1916 | StackFrame[] stackFrames = stackTrace.GetFrames(); // get method calls (frames) |
1868 | 1917 | ||
@@ -1870,7 +1919,7 @@ namespace OpenSim.Framework | |||
1870 | foreach (StackFrame stackFrame in stackFrames) | 1919 | foreach (StackFrame stackFrame in stackFrames) |
1871 | { | 1920 | { |
1872 | MethodBase mb = stackFrame.GetMethod(); | 1921 | MethodBase mb = stackFrame.GetMethod(); |
1873 | m_log.DebugFormat("{0}.{1}:{2}", mb.DeclaringType, mb.Name, stackFrame.GetFileLineNumber()); // write method name | 1922 | printer("{0}.{1}:{2}", mb.DeclaringType, mb.Name, stackFrame.GetFileLineNumber()); // write method name |
1874 | } | 1923 | } |
1875 | } | 1924 | } |
1876 | 1925 | ||
@@ -2096,6 +2145,17 @@ namespace OpenSim.Framework | |||
2096 | return firstName + "." + lastName + " " + "@" + uri.Authority; | 2145 | return firstName + "." + lastName + " " + "@" + uri.Authority; |
2097 | } | 2146 | } |
2098 | #endregion | 2147 | #endregion |
2148 | |||
2149 | /// <summary> | ||
2150 | /// Escapes the special characters used in "LIKE". | ||
2151 | /// </summary> | ||
2152 | /// <remarks> | ||
2153 | /// For example: EscapeForLike("foo_bar%baz") = "foo\_bar\%baz" | ||
2154 | /// </remarks> | ||
2155 | public static string EscapeForLike(string str) | ||
2156 | { | ||
2157 | return str.Replace("_", "\\_").Replace("%", "\\%"); | ||
2158 | } | ||
2099 | } | 2159 | } |
2100 | 2160 | ||
2101 | public class DoubleQueue<T> where T:class | 2161 | public class DoubleQueue<T> where T:class |