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.cs45
1 files changed, 37 insertions, 8 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index e76a37b..c049247 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -299,6 +299,13 @@ namespace OpenSim.Framework
299 x; 299 x;
300 } 300 }
301 301
302 // Inclusive, within range test (true if equal to the endpoints)
303 public static bool InRange<T>(T x, T min, T max)
304 where T : IComparable<T>
305 {
306 return x.CompareTo(max) <= 0 && x.CompareTo(min) >= 0;
307 }
308
302 public static uint GetNextXferID() 309 public static uint GetNextXferID()
303 { 310 {
304 uint id = 0; 311 uint id = 0;
@@ -1652,6 +1659,7 @@ namespace OpenSim.Framework
1652 throw new InvalidOperationException("SmartThreadPool is already initialized"); 1659 throw new InvalidOperationException("SmartThreadPool is already initialized");
1653 1660
1654 m_ThreadPool = new SmartThreadPool(2000, maxThreads, 2); 1661 m_ThreadPool = new SmartThreadPool(2000, maxThreads, 2);
1662 m_ThreadPool.Name = "Util";
1655 } 1663 }
1656 1664
1657 public static int FireAndForgetCount() 1665 public static int FireAndForgetCount()
@@ -1724,7 +1732,7 @@ namespace OpenSim.Framework
1724 break; 1732 break;
1725 case FireAndForgetMethod.SmartThreadPool: 1733 case FireAndForgetMethod.SmartThreadPool:
1726 if (m_ThreadPool == null) 1734 if (m_ThreadPool == null)
1727 m_ThreadPool = new SmartThreadPool(2000, 15, 2); 1735 InitThreadPool(15);
1728 m_ThreadPool.QueueWorkItem(SmartThreadPoolCallback, new object[] { realCallback, obj }); 1736 m_ThreadPool.QueueWorkItem(SmartThreadPoolCallback, new object[] { realCallback, obj });
1729 break; 1737 break;
1730 case FireAndForgetMethod.Thread: 1738 case FireAndForgetMethod.Thread:
@@ -1753,12 +1761,16 @@ namespace OpenSim.Framework
1753 StringBuilder sb = new StringBuilder(); 1761 StringBuilder sb = new StringBuilder();
1754 if (FireAndForgetMethod == FireAndForgetMethod.SmartThreadPool) 1762 if (FireAndForgetMethod == FireAndForgetMethod.SmartThreadPool)
1755 { 1763 {
1756 threadPoolUsed = "SmartThreadPool"; 1764 // ROBUST currently leaves this the FireAndForgetMethod but never actually initializes the threadpool.
1757 maxThreads = m_ThreadPool.MaxThreads; 1765 if (m_ThreadPool != null)
1758 minThreads = m_ThreadPool.MinThreads; 1766 {
1759 inUseThreads = m_ThreadPool.InUseThreads; 1767 threadPoolUsed = "SmartThreadPool";
1760 allocatedThreads = m_ThreadPool.ActiveThreads; 1768 maxThreads = m_ThreadPool.MaxThreads;
1761 waitingCallbacks = m_ThreadPool.WaitingCallbacks; 1769 minThreads = m_ThreadPool.MinThreads;
1770 inUseThreads = m_ThreadPool.InUseThreads;
1771 allocatedThreads = m_ThreadPool.ActiveThreads;
1772 waitingCallbacks = m_ThreadPool.WaitingCallbacks;
1773 }
1762 } 1774 }
1763 else if ( 1775 else if (
1764 FireAndForgetMethod == FireAndForgetMethod.UnsafeQueueUserWorkItem 1776 FireAndForgetMethod == FireAndForgetMethod.UnsafeQueueUserWorkItem
@@ -1863,6 +1875,12 @@ namespace OpenSim.Framework
1863 /// </summary> 1875 /// </summary>
1864 public static void PrintCallStack() 1876 public static void PrintCallStack()
1865 { 1877 {
1878 PrintCallStack(m_log.DebugFormat);
1879 }
1880
1881 public delegate void DebugPrinter(string msg, params Object[] parm);
1882 public static void PrintCallStack(DebugPrinter printer)
1883 {
1866 StackTrace stackTrace = new StackTrace(true); // get call stack 1884 StackTrace stackTrace = new StackTrace(true); // get call stack
1867 StackFrame[] stackFrames = stackTrace.GetFrames(); // get method calls (frames) 1885 StackFrame[] stackFrames = stackTrace.GetFrames(); // get method calls (frames)
1868 1886
@@ -1870,7 +1888,7 @@ namespace OpenSim.Framework
1870 foreach (StackFrame stackFrame in stackFrames) 1888 foreach (StackFrame stackFrame in stackFrames)
1871 { 1889 {
1872 MethodBase mb = stackFrame.GetMethod(); 1890 MethodBase mb = stackFrame.GetMethod();
1873 m_log.DebugFormat("{0}.{1}:{2}", mb.DeclaringType, mb.Name, stackFrame.GetFileLineNumber()); // write method name 1891 printer("{0}.{1}:{2}", mb.DeclaringType, mb.Name, stackFrame.GetFileLineNumber()); // write method name
1874 } 1892 }
1875 } 1893 }
1876 1894
@@ -2096,5 +2114,16 @@ namespace OpenSim.Framework
2096 return firstName + "." + lastName + " " + "@" + uri.Authority; 2114 return firstName + "." + lastName + " " + "@" + uri.Authority;
2097 } 2115 }
2098 #endregion 2116 #endregion
2117
2118 /// <summary>
2119 /// Escapes the special characters used in "LIKE".
2120 /// </summary>
2121 /// <remarks>
2122 /// For example: EscapeForLike("foo_bar%baz") = "foo\_bar\%baz"
2123 /// </remarks>
2124 public static string EscapeForLike(string str)
2125 {
2126 return str.Replace("_", "\\_").Replace("%", "\\%");
2127 }
2099 } 2128 }
2100} 2129}