aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Util.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Util.cs57
1 files changed, 49 insertions, 8 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index e76a37b..ba3a751 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;
@@ -1652,6 +1671,7 @@ namespace OpenSim.Framework
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 m_ThreadPool = new SmartThreadPool(2000, maxThreads, 2);
1674 m_ThreadPool.Name = "Util";
1655 } 1675 }
1656 1676
1657 public static int FireAndForgetCount() 1677 public static int FireAndForgetCount()
@@ -1724,7 +1744,7 @@ namespace OpenSim.Framework
1724 break; 1744 break;
1725 case FireAndForgetMethod.SmartThreadPool: 1745 case FireAndForgetMethod.SmartThreadPool:
1726 if (m_ThreadPool == null) 1746 if (m_ThreadPool == null)
1727 m_ThreadPool = new SmartThreadPool(2000, 15, 2); 1747 InitThreadPool(15);
1728 m_ThreadPool.QueueWorkItem(SmartThreadPoolCallback, new object[] { realCallback, obj }); 1748 m_ThreadPool.QueueWorkItem(SmartThreadPoolCallback, new object[] { realCallback, obj });
1729 break; 1749 break;
1730 case FireAndForgetMethod.Thread: 1750 case FireAndForgetMethod.Thread:
@@ -1753,12 +1773,16 @@ namespace OpenSim.Framework
1753 StringBuilder sb = new StringBuilder(); 1773 StringBuilder sb = new StringBuilder();
1754 if (FireAndForgetMethod == FireAndForgetMethod.SmartThreadPool) 1774 if (FireAndForgetMethod == FireAndForgetMethod.SmartThreadPool)
1755 { 1775 {
1756 threadPoolUsed = "SmartThreadPool"; 1776 // ROBUST currently leaves this the FireAndForgetMethod but never actually initializes the threadpool.
1757 maxThreads = m_ThreadPool.MaxThreads; 1777 if (m_ThreadPool != null)
1758 minThreads = m_ThreadPool.MinThreads; 1778 {
1759 inUseThreads = m_ThreadPool.InUseThreads; 1779 threadPoolUsed = "SmartThreadPool";
1760 allocatedThreads = m_ThreadPool.ActiveThreads; 1780 maxThreads = m_ThreadPool.MaxThreads;
1761 waitingCallbacks = m_ThreadPool.WaitingCallbacks; 1781 minThreads = m_ThreadPool.MinThreads;
1782 inUseThreads = m_ThreadPool.InUseThreads;
1783 allocatedThreads = m_ThreadPool.ActiveThreads;
1784 waitingCallbacks = m_ThreadPool.WaitingCallbacks;
1785 }
1762 } 1786 }
1763 else if ( 1787 else if (
1764 FireAndForgetMethod == FireAndForgetMethod.UnsafeQueueUserWorkItem 1788 FireAndForgetMethod == FireAndForgetMethod.UnsafeQueueUserWorkItem
@@ -1863,6 +1887,12 @@ namespace OpenSim.Framework
1863 /// </summary> 1887 /// </summary>
1864 public static void PrintCallStack() 1888 public static void PrintCallStack()
1865 { 1889 {
1890 PrintCallStack(m_log.DebugFormat);
1891 }
1892
1893 public delegate void DebugPrinter(string msg, params Object[] parm);
1894 public static void PrintCallStack(DebugPrinter printer)
1895 {
1866 StackTrace stackTrace = new StackTrace(true); // get call stack 1896 StackTrace stackTrace = new StackTrace(true); // get call stack
1867 StackFrame[] stackFrames = stackTrace.GetFrames(); // get method calls (frames) 1897 StackFrame[] stackFrames = stackTrace.GetFrames(); // get method calls (frames)
1868 1898
@@ -1870,7 +1900,7 @@ namespace OpenSim.Framework
1870 foreach (StackFrame stackFrame in stackFrames) 1900 foreach (StackFrame stackFrame in stackFrames)
1871 { 1901 {
1872 MethodBase mb = stackFrame.GetMethod(); 1902 MethodBase mb = stackFrame.GetMethod();
1873 m_log.DebugFormat("{0}.{1}:{2}", mb.DeclaringType, mb.Name, stackFrame.GetFileLineNumber()); // write method name 1903 printer("{0}.{1}:{2}", mb.DeclaringType, mb.Name, stackFrame.GetFileLineNumber()); // write method name
1874 } 1904 }
1875 } 1905 }
1876 1906
@@ -2096,5 +2126,16 @@ namespace OpenSim.Framework
2096 return firstName + "." + lastName + " " + "@" + uri.Authority; 2126 return firstName + "." + lastName + " " + "@" + uri.Authority;
2097 } 2127 }
2098 #endregion 2128 #endregion
2129
2130 /// <summary>
2131 /// Escapes the special characters used in "LIKE".
2132 /// </summary>
2133 /// <remarks>
2134 /// For example: EscapeForLike("foo_bar%baz") = "foo\_bar\%baz"
2135 /// </remarks>
2136 public static string EscapeForLike(string str)
2137 {
2138 return str.Replace("_", "\\_").Replace("%", "\\%");
2139 }
2099 } 2140 }
2100} 2141}