aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Util.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Util.cs303
1 files changed, 159 insertions, 144 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 1afc5a4..187ed4f 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -30,6 +30,8 @@ using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Data; 31using System.Data;
32using System.Diagnostics; 32using System.Diagnostics;
33using System.Drawing;
34using System.Drawing.Imaging;
33using System.Globalization; 35using System.Globalization;
34using System.IO; 36using System.IO;
35using System.IO.Compression; 37using System.IO.Compression;
@@ -92,6 +94,7 @@ namespace OpenSim.Framework
92 // explicitly given 94 // explicitly given
93 All = 0x8e000, 95 All = 0x8e000,
94 AllAndExport = 0x9e000, 96 AllAndExport = 0x9e000,
97 AllAndExportNoMod = 0x9a000,
95 AllEffective = 0x9e000, 98 AllEffective = 0x9e000,
96 UnfoldedMask = 0x1e000 99 UnfoldedMask = 0x1e000
97 } 100 }
@@ -108,9 +111,7 @@ namespace OpenSim.Framework
108 { 111 {
109 None, 112 None,
110 RegressionTest, 113 RegressionTest,
111 UnsafeQueueUserWorkItem,
112 QueueUserWorkItem, 114 QueueUserWorkItem,
113 BeginInvoke,
114 SmartThreadPool, 115 SmartThreadPool,
115 Thread, 116 Thread,
116 } 117 }
@@ -261,10 +262,7 @@ namespace OpenSim.Framework
261 /// <returns>The distance between the two vectors</returns> 262 /// <returns>The distance between the two vectors</returns>
262 public static double GetDistanceTo(Vector3 a, Vector3 b) 263 public static double GetDistanceTo(Vector3 a, Vector3 b)
263 { 264 {
264 float dx = a.X - b.X; 265 return Vector3.Distance(a,b);
265 float dy = a.Y - b.Y;
266 float dz = a.Z - b.Z;
267 return Math.Sqrt(dx * dx + dy * dy + dz * dz);
268 } 266 }
269 267
270 /// <summary> 268 /// <summary>
@@ -276,10 +274,7 @@ namespace OpenSim.Framework
276 /// <returns></returns> 274 /// <returns></returns>
277 public static bool DistanceLessThan(Vector3 a, Vector3 b, double amount) 275 public static bool DistanceLessThan(Vector3 a, Vector3 b, double amount)
278 { 276 {
279 float dx = a.X - b.X; 277 return Vector3.DistanceSquared(a,b) < (amount * amount);
280 float dy = a.Y - b.Y;
281 float dz = a.Z - b.Z;
282 return (dx*dx + dy*dy + dz*dz) < (amount*amount);
283 } 278 }
284 279
285 /// <summary> 280 /// <summary>
@@ -380,15 +375,17 @@ namespace OpenSim.Framework
380 get { return randomClass; } 375 get { return randomClass; }
381 } 376 }
382 377
378 [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
383 public static ulong UIntsToLong(uint X, uint Y) 379 public static ulong UIntsToLong(uint X, uint Y)
384 { 380 {
385 return Utils.UIntsToLong(X, Y); 381 return ((ulong)X << 32) | (ulong)Y;
386 } 382 }
387 383
388 // Regions are identified with a 'handle' made up of its world coordinates packed into a ulong. 384 // Regions are identified with a 'handle' made up of its world coordinates packed into a ulong.
389 // Region handles are based on the coordinate of the region corner with lower X and Y 385 // Region handles are based on the coordinate of the region corner with lower X and Y
390 // var regions need more work than this to get that right corner from a generic world position 386 // var regions need more work than this to get that right corner from a generic world position
391 // this corner must be on a grid point 387 // this corner must be on a grid point
388 [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
392 public static ulong RegionWorldLocToHandle(uint X, uint Y) 389 public static ulong RegionWorldLocToHandle(uint X, uint Y)
393 { 390 {
394 ulong handle = X & 0xffffff00; // make sure it matchs grid coord points. 391 ulong handle = X & 0xffffff00; // make sure it matchs grid coord points.
@@ -397,6 +394,7 @@ namespace OpenSim.Framework
397 return handle; 394 return handle;
398 } 395 }
399 396
397 [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
400 public static ulong RegionGridLocToHandle(uint X, uint Y) 398 public static ulong RegionGridLocToHandle(uint X, uint Y)
401 { 399 {
402 ulong handle = X; 400 ulong handle = X;
@@ -405,12 +403,14 @@ namespace OpenSim.Framework
405 return handle; 403 return handle;
406 } 404 }
407 405
406 [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
408 public static void RegionHandleToWorldLoc(ulong handle, out uint X, out uint Y) 407 public static void RegionHandleToWorldLoc(ulong handle, out uint X, out uint Y)
409 { 408 {
410 X = (uint)(handle >> 32); 409 X = (uint)(handle >> 32);
411 Y = (uint)(handle & 0xfffffffful); 410 Y = (uint)(handle & 0xfffffffful);
412 } 411 }
413 412
413 [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
414 public static void RegionHandleToRegionLoc(ulong handle, out uint X, out uint Y) 414 public static void RegionHandleToRegionLoc(ulong handle, out uint X, out uint Y)
415 { 415 {
416 X = (uint)(handle >> 40) & 0x00ffffffu; // bring from higher half, divide by 256 and clean 416 X = (uint)(handle >> 40) & 0x00ffffffu; // bring from higher half, divide by 256 and clean
@@ -420,21 +420,25 @@ namespace OpenSim.Framework
420 420
421 // A region location can be 'world coordinates' (meters) or 'region grid coordinates' 421 // A region location can be 'world coordinates' (meters) or 'region grid coordinates'
422 // grid coordinates have a fixed step of 256m as defined by viewers 422 // grid coordinates have a fixed step of 256m as defined by viewers
423 [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
423 public static uint WorldToRegionLoc(uint worldCoord) 424 public static uint WorldToRegionLoc(uint worldCoord)
424 { 425 {
425 return worldCoord >> 8; 426 return worldCoord >> 8;
426 } 427 }
427 428
428 // Convert a region's 'region grid coordinate' to its 'world coordinate'. 429 // Convert a region's 'region grid coordinate' to its 'world coordinate'.
430 [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
429 public static uint RegionToWorldLoc(uint regionCoord) 431 public static uint RegionToWorldLoc(uint regionCoord)
430 { 432 {
431 return regionCoord << 8; 433 return regionCoord << 8;
432 } 434 }
433 435
434 436
435 public static bool checkServiceURI(string uristr, out string serviceURI) 437 public static bool checkServiceURI(string uristr, out string serviceURI, out string serviceHost, out string serviceIPstr)
436 { 438 {
437 serviceURI = string.Empty; 439 serviceURI = string.Empty;
440 serviceHost = string.Empty;
441 serviceIPstr = string.Empty;
438 try 442 try
439 { 443 {
440 Uri uri = new Uri(uristr); 444 Uri uri = new Uri(uristr);
@@ -443,6 +447,13 @@ namespace OpenSim.Framework
443 serviceURI = serviceURI.Trim(new char[] { '/', ' ' }) +":80/"; 447 serviceURI = serviceURI.Trim(new char[] { '/', ' ' }) +":80/";
444 else if(uri.Port == 443) 448 else if(uri.Port == 443)
445 serviceURI = serviceURI.Trim(new char[] { '/', ' ' }) +":443/"; 449 serviceURI = serviceURI.Trim(new char[] { '/', ' ' }) +":443/";
450 serviceHost = uri.Host;
451
452 IPEndPoint ep = Util.getEndPoint(serviceHost,uri.Port);
453 if(ep == null)
454 return false;
455
456 serviceIPstr = ep.Address.ToString();
446 return true; 457 return true;
447 } 458 }
448 catch 459 catch
@@ -452,9 +463,10 @@ namespace OpenSim.Framework
452 return false; 463 return false;
453 } 464 }
454 465
455 public static bool buildHGRegionURI(string inputName, out string serverURI, out string regionName) 466 public static bool buildHGRegionURI(string inputName, out string serverURI, out string serverHost, out string regionName)
456 { 467 {
457 serverURI = string.Empty; 468 serverURI = string.Empty;
469 serverHost = string.Empty;
458 regionName = string.Empty; 470 regionName = string.Empty;
459 471
460 inputName = inputName.Trim(); 472 inputName = inputName.Trim();
@@ -563,6 +575,7 @@ namespace OpenSim.Framework
563 serverURI = serverURI.Trim(new char[] { '/', ' ' }) +":80/"; 575 serverURI = serverURI.Trim(new char[] { '/', ' ' }) +":80/";
564 else if(uri.Port == 443) 576 else if(uri.Port == 443)
565 serverURI = serverURI.Trim(new char[] { '/', ' ' }) +":443/"; 577 serverURI = serverURI.Trim(new char[] { '/', ' ' }) +":443/";
578 serverHost = uri.Host;
566 return true; 579 return true;
567 } 580 }
568 581
@@ -575,14 +588,15 @@ namespace OpenSim.Framework
575 } 588 }
576 589
577 // Clamp the maximum magnitude of a vector 590 // Clamp the maximum magnitude of a vector
591 [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
578 public static Vector3 ClampV(Vector3 x, float max) 592 public static Vector3 ClampV(Vector3 x, float max)
579 { 593 {
580 float lenSq = x.LengthSquared(); 594 float lenSq = x.LengthSquared();
581 if (lenSq > (max * max)) 595 if (lenSq > (max * max))
582 { 596 {
583 x = x / x.Length() * max; 597 lenSq = max / (float)Math.Sqrt(lenSq);
598 x = x * lenSq;
584 } 599 }
585
586 return x; 600 return x;
587 } 601 }
588 602
@@ -671,7 +685,7 @@ namespace OpenSim.Framework
671 public static string GetFormattedXml(string rawXml) 685 public static string GetFormattedXml(string rawXml)
672 { 686 {
673 XmlDocument xd = new XmlDocument(); 687 XmlDocument xd = new XmlDocument();
674 xd.XmlResolver=null; 688
675 xd.LoadXml(rawXml); 689 xd.LoadXml(rawXml);
676 690
677 StringBuilder sb = new StringBuilder(); 691 StringBuilder sb = new StringBuilder();
@@ -825,8 +839,8 @@ namespace OpenSim.Framework
825 839
826 private static byte[] ComputeMD5Hash(string data, Encoding encoding) 840 private static byte[] ComputeMD5Hash(string data, Encoding encoding)
827 { 841 {
828 MD5 md5 = MD5.Create(); 842 using(MD5 md5 = MD5.Create())
829 return md5.ComputeHash(encoding.GetBytes(data)); 843 return md5.ComputeHash(encoding.GetBytes(data));
830 } 844 }
831 845
832 /// <summary> 846 /// <summary>
@@ -859,11 +873,24 @@ namespace OpenSim.Framework
859 private static byte[] ComputeSHA1Hash(byte[] src) 873 private static byte[] ComputeSHA1Hash(byte[] src)
860 { 874 {
861 byte[] ret; 875 byte[] ret;
862 using(SHA1CryptoServiceProvider SHA1 = new SHA1CryptoServiceProvider()) 876 using (SHA1CryptoServiceProvider SHA1 = new SHA1CryptoServiceProvider())
863 ret = SHA1.ComputeHash(src); 877 ret = SHA1.ComputeHash(src);
864 return ret; 878 return ret;
865 } 879 }
866 880
881 public static UUID ComputeSHA1UUID(string src)
882 {
883 return ComputeSHA1UUID(Encoding.Default.GetBytes(src));
884 }
885
886 public static UUID ComputeSHA1UUID(byte[] src)
887 {
888 byte[] ret;
889 using (SHA1CryptoServiceProvider SHA1 = new SHA1CryptoServiceProvider())
890 ret = SHA1.ComputeHash(src);
891 return new UUID(ret, 2);
892 }
893
867 public static int fast_distance2d(int x, int y) 894 public static int fast_distance2d(int x, int y)
868 { 895 {
869 x = Math.Abs(x); 896 x = Math.Abs(x);
@@ -883,7 +910,7 @@ namespace OpenSim.Framework
883 /// <returns></returns> 910 /// <returns></returns>
884 public static bool IsInsideBox(Vector3 v, Vector3 min, Vector3 max) 911 public static bool IsInsideBox(Vector3 v, Vector3 min, Vector3 max)
885 { 912 {
886 return v.X >= min.X & v.Y >= min.Y && v.Z >= min.Z 913 return v.X >= min.X && v.Y >= min.Y && v.Z >= min.Z
887 && v.X <= max.X && v.Y <= max.Y && v.Z <= max.Z; 914 && v.X <= max.X && v.Y <= max.Y && v.Z <= max.Z;
888 } 915 }
889 916
@@ -1279,12 +1306,12 @@ namespace OpenSim.Framework
1279 1306
1280 public static string dbDir() 1307 public static string dbDir()
1281 { 1308 {
1282 return Path.Combine("..", Path.Combine("..", "db")); 1309 return Path.Combine("..", Path.Combine("..", "var/lib/db"));
1283 } 1310 }
1284 1311
1285 public static string cacheDir() 1312 public static string cacheDir()
1286 { 1313 {
1287 return Path.Combine("..", Path.Combine("..", "caches")); 1314 return Path.Combine("..", Path.Combine("..", "var/cache"));
1288 } 1315 }
1289 1316
1290 public static string configDir() 1317 public static string configDir()
@@ -1300,7 +1327,7 @@ namespace OpenSim.Framework
1300 1327
1301 public static string logsDir() 1328 public static string logsDir()
1302 { 1329 {
1303 return Path.Combine("..", "logs"); 1330 return Path.Combine("..", "var/log");
1304 } 1331 }
1305 1332
1306 public static string webDir() 1333 public static string webDir()
@@ -1935,7 +1962,9 @@ namespace OpenSim.Framework
1935 string ru = String.Empty; 1962 string ru = String.Empty;
1936 1963
1937 if (Environment.OSVersion.Platform == PlatformID.Unix) 1964 if (Environment.OSVersion.Platform == PlatformID.Unix)
1938 ru = "Unix/Mono"; 1965 {
1966 ru = "Unix/Mono";
1967 }
1939 else 1968 else
1940 if (Environment.OSVersion.Platform == PlatformID.MacOSX) 1969 if (Environment.OSVersion.Platform == PlatformID.MacOSX)
1941 ru = "OSX/Mono"; 1970 ru = "OSX/Mono";
@@ -2385,6 +2414,38 @@ namespace OpenSim.Framework
2385 return sb.ToString(); 2414 return sb.ToString();
2386 } 2415 }
2387 2416
2417 public static bool TryParseHttpRange(string header, out int start, out int end)
2418 {
2419 start = end = 0;
2420
2421 if (header.StartsWith("bytes="))
2422 {
2423 string[] rangeValues = header.Substring(6).Split('-');
2424
2425 if (rangeValues.Length == 2)
2426 {
2427 string rawStart = rangeValues[0].Trim();
2428 if (rawStart != "" && !Int32.TryParse(rawStart, out start))
2429 return false;
2430
2431 if (start < 0)
2432 return false;
2433
2434 string rawEnd = rangeValues[1].Trim();
2435 if (rawEnd == "")
2436 {
2437 end = -1;
2438 return true;
2439 }
2440 else if (Int32.TryParse(rawEnd, out end))
2441 return end > 0;
2442 }
2443 }
2444
2445 start = end = 0;
2446 return false;
2447 }
2448
2388 /// <summary> 2449 /// <summary>
2389 /// Used to trigger an early library load on Windows systems. 2450 /// Used to trigger an early library load on Windows systems.
2390 /// </summary> 2451 /// </summary>
@@ -2408,53 +2469,6 @@ namespace OpenSim.Framework
2408 2469
2409 #region FireAndForget Threading Pattern 2470 #region FireAndForget Threading Pattern
2410 2471
2411 /// <summary>
2412 /// Created to work around a limitation in Mono with nested delegates
2413 /// </summary>
2414 private sealed class FireAndForgetWrapper
2415 {
2416 private static volatile FireAndForgetWrapper instance;
2417 private static object syncRoot = new Object();
2418
2419 public static FireAndForgetWrapper Instance {
2420 get {
2421
2422 if (instance == null)
2423 {
2424 lock (syncRoot)
2425 {
2426 if (instance == null)
2427 {
2428 instance = new FireAndForgetWrapper();
2429 }
2430 }
2431 }
2432
2433 return instance;
2434 }
2435 }
2436
2437 public void FireAndForget(System.Threading.WaitCallback callback)
2438 {
2439 callback.BeginInvoke(null, EndFireAndForget, callback);
2440 }
2441
2442 public void FireAndForget(System.Threading.WaitCallback callback, object obj)
2443 {
2444 callback.BeginInvoke(obj, EndFireAndForget, callback);
2445 }
2446
2447 private static void EndFireAndForget(IAsyncResult ar)
2448 {
2449 System.Threading.WaitCallback callback = (System.Threading.WaitCallback)ar.AsyncState;
2450
2451 try { callback.EndInvoke(ar); }
2452 catch (Exception ex) { m_log.Error("[UTIL]: Asynchronous method threw an exception: " + ex.Message, ex); }
2453
2454 ar.AsyncWaitHandle.Close();
2455 }
2456 }
2457
2458 public static void InitThreadPool(int minThreads, int maxThreads) 2472 public static void InitThreadPool(int minThreads, int maxThreads)
2459 { 2473 {
2460 if (maxThreads < 2) 2474 if (maxThreads < 2)
@@ -2485,16 +2499,17 @@ namespace OpenSim.Framework
2485 2499
2486 switch (FireAndForgetMethod) 2500 switch (FireAndForgetMethod)
2487 { 2501 {
2488 case FireAndForgetMethod.UnsafeQueueUserWorkItem:
2489 case FireAndForgetMethod.QueueUserWorkItem: 2502 case FireAndForgetMethod.QueueUserWorkItem:
2490 case FireAndForgetMethod.BeginInvoke:
2491 int workerThreads, iocpThreads; 2503 int workerThreads, iocpThreads;
2492 ThreadPool.GetAvailableThreads(out workerThreads, out iocpThreads); 2504 ThreadPool.GetAvailableThreads(out workerThreads, out iocpThreads);
2493 return workerThreads; 2505 return workerThreads;
2494 case FireAndForgetMethod.SmartThreadPool: 2506 case FireAndForgetMethod.SmartThreadPool:
2495 return m_ThreadPool.MaxThreads - m_ThreadPool.InUseThreads; 2507 return m_ThreadPool.MaxThreads - m_ThreadPool.InUseThreads;
2496 case FireAndForgetMethod.Thread: 2508 case FireAndForgetMethod.Thread:
2497 return MAX_SYSTEM_THREADS - System.Diagnostics.Process.GetCurrentProcess().Threads.Count; 2509 {
2510 using(Process p = System.Diagnostics.Process.GetCurrentProcess())
2511 return MAX_SYSTEM_THREADS - p.Threads.Count;
2512 }
2498 default: 2513 default:
2499 throw new NotImplementedException(); 2514 throw new NotImplementedException();
2500 } 2515 }
@@ -2641,20 +2656,6 @@ namespace OpenSim.Framework
2641 public static void FireAndForget(System.Threading.WaitCallback callback, object obj, string context, bool dotimeout = true) 2656 public static void FireAndForget(System.Threading.WaitCallback callback, object obj, string context, bool dotimeout = true)
2642 { 2657 {
2643 Interlocked.Increment(ref numTotalThreadFuncsCalled); 2658 Interlocked.Increment(ref numTotalThreadFuncsCalled);
2644/*
2645 if (context != null)
2646 {
2647 if (!m_fireAndForgetCallsMade.ContainsKey(context))
2648 m_fireAndForgetCallsMade[context] = 1;
2649 else
2650 m_fireAndForgetCallsMade[context]++;
2651
2652 if (!m_fireAndForgetCallsInProgress.ContainsKey(context))
2653 m_fireAndForgetCallsInProgress[context] = 1;
2654 else
2655 m_fireAndForgetCallsInProgress[context]++;
2656 }
2657*/
2658 WaitCallback realCallback; 2659 WaitCallback realCallback;
2659 2660
2660 bool loggingEnabled = LogThreadPool > 0; 2661 bool loggingEnabled = LogThreadPool > 0;
@@ -2670,9 +2671,6 @@ namespace OpenSim.Framework
2670 { 2671 {
2671 Culture.SetCurrentCulture(); 2672 Culture.SetCurrentCulture();
2672 callback(o); 2673 callback(o);
2673
2674// if (context != null)
2675// m_fireAndForgetCallsInProgress[context]--;
2676 }; 2674 };
2677 } 2675 }
2678 else 2676 else
@@ -2693,7 +2691,6 @@ namespace OpenSim.Framework
2693 m_log.DebugFormat("Run threadfunc {0} (Queued {1}, Running {2})", threadFuncNum, numQueued1, numRunning1); 2691 m_log.DebugFormat("Run threadfunc {0} (Queued {1}, Running {2})", threadFuncNum, numQueued1, numRunning1);
2694 2692
2695 Culture.SetCurrentCulture(); 2693 Culture.SetCurrentCulture();
2696
2697 callback(o); 2694 callback(o);
2698 } 2695 }
2699 catch (ThreadAbortException) 2696 catch (ThreadAbortException)
@@ -2711,9 +2708,6 @@ namespace OpenSim.Framework
2711 activeThreads.TryRemove(threadFuncNum, out dummy); 2708 activeThreads.TryRemove(threadFuncNum, out dummy);
2712 if ((loggingEnabled || (threadFuncOverloadMode == 1)) && threadInfo.LogThread) 2709 if ((loggingEnabled || (threadFuncOverloadMode == 1)) && threadInfo.LogThread)
2713 m_log.DebugFormat("Exit threadfunc {0} ({1})", threadFuncNum, FormatDuration(threadInfo.Elapsed())); 2710 m_log.DebugFormat("Exit threadfunc {0} ({1})", threadFuncNum, FormatDuration(threadInfo.Elapsed()));
2714
2715// if (context != null)
2716// m_fireAndForgetCallsInProgress[context]--;
2717 } 2711 }
2718 }; 2712 };
2719 } 2713 }
@@ -2721,45 +2715,7 @@ namespace OpenSim.Framework
2721 long numQueued = Interlocked.Increment(ref numQueuedThreadFuncs); 2715 long numQueued = Interlocked.Increment(ref numQueuedThreadFuncs);
2722 try 2716 try
2723 { 2717 {
2724/* 2718 threadInfo.LogThread = false;
2725 long numRunning = numRunningThreadFuncs;
2726
2727 if (m_ThreadPool != null && LogOverloads)
2728 {
2729 if ((threadFuncOverloadMode == 0) && (numRunning >= m_ThreadPool.MaxThreads))
2730 {
2731 if (Interlocked.CompareExchange(ref threadFuncOverloadMode, 1, 0) == 0)
2732 m_log.DebugFormat("Threadfunc: enable overload mode (Queued {0}, Running {1})", numQueued, numRunning);
2733 }
2734 else if ((threadFuncOverloadMode == 1) && (numRunning <= (m_ThreadPool.MaxThreads * 2) / 3))
2735 {
2736 if (Interlocked.CompareExchange(ref threadFuncOverloadMode, 0, 1) == 1)
2737 m_log.DebugFormat("Threadfunc: disable overload mode (Queued {0}, Running {1})", numQueued, numRunning);
2738 }
2739 }
2740
2741 if (loggingEnabled || (threadFuncOverloadMode == 1))
2742 {
2743 string full, partial;
2744 GetFireAndForgetStackTrace(out full, out partial);
2745 threadInfo.StackTrace = full;
2746 threadInfo.LogThread = ShouldLogThread(partial);
2747
2748 if (threadInfo.LogThread)
2749 {
2750 m_log.DebugFormat("Queue threadfunc {0} (Queued {1}, Running {2}) {3}{4}",
2751 threadFuncNum, numQueued, numRunningThreadFuncs,
2752 (context == null) ? "" : ("(" + context + ") "),
2753 (LogThreadPool >= 2) ? full : partial);
2754 }
2755 }
2756 else
2757*/
2758 {
2759 // Since we didn't log "Queue threadfunc", don't log "Run threadfunc" or "End threadfunc" either.
2760 // Those log lines aren't useful when we don't know which function is running in the thread.
2761 threadInfo.LogThread = false;
2762 }
2763 2719
2764 switch (FireAndForgetMethod) 2720 switch (FireAndForgetMethod)
2765 { 2721 {
@@ -2767,16 +2723,9 @@ namespace OpenSim.Framework
2767 case FireAndForgetMethod.None: 2723 case FireAndForgetMethod.None:
2768 realCallback.Invoke(obj); 2724 realCallback.Invoke(obj);
2769 break; 2725 break;
2770 case FireAndForgetMethod.UnsafeQueueUserWorkItem:
2771 ThreadPool.UnsafeQueueUserWorkItem(realCallback, obj);
2772 break;
2773 case FireAndForgetMethod.QueueUserWorkItem: 2726 case FireAndForgetMethod.QueueUserWorkItem:
2774 ThreadPool.QueueUserWorkItem(realCallback, obj); 2727 ThreadPool.QueueUserWorkItem(realCallback, obj);
2775 break; 2728 break;
2776 case FireAndForgetMethod.BeginInvoke:
2777 FireAndForgetWrapper wrapper = FireAndForgetWrapper.Instance;
2778 wrapper.FireAndForget(realCallback, obj);
2779 break;
2780 case FireAndForgetMethod.SmartThreadPool: 2729 case FireAndForgetMethod.SmartThreadPool:
2781 if (m_ThreadPool == null) 2730 if (m_ThreadPool == null)
2782 InitThreadPool(2, 15); 2731 InitThreadPool(2, 15);
@@ -2879,6 +2828,12 @@ namespace OpenSim.Framework
2879 /// <returns>The stack trace, or null if failed to get it</returns> 2828 /// <returns>The stack trace, or null if failed to get it</returns>
2880 private static StackTrace GetStackTrace(Thread targetThread) 2829 private static StackTrace GetStackTrace(Thread targetThread)
2881 { 2830 {
2831
2832 return null;
2833/*
2834 not only this does not work on mono but it is not longer recomended on windows.
2835 can cause deadlocks etc.
2836
2882 if (IsPlatformMono) 2837 if (IsPlatformMono)
2883 { 2838 {
2884 // This doesn't work in Mono 2839 // This doesn't work in Mono
@@ -2941,6 +2896,7 @@ namespace OpenSim.Framework
2941 // Signal the fallack-thread to stop 2896 // Signal the fallack-thread to stop
2942 exitedSafely.Set(); 2897 exitedSafely.Set();
2943 } 2898 }
2899*/
2944 } 2900 }
2945#pragma warning restore 0618 2901#pragma warning restore 0618
2946 2902
@@ -3038,16 +2994,37 @@ namespace OpenSim.Framework
3038 return tcA - tcB; 2994 return tcA - tcB;
3039 } 2995 }
3040 2996
2997 public static long GetPhysicalMemUse()
2998 {
2999 using (Process p = System.Diagnostics.Process.GetCurrentProcess())
3000 return p.WorkingSet64;
3001 }
3002
3041 // returns a timestamp in ms as double 3003 // returns a timestamp in ms as double
3042 // using the time resolution avaiable to StopWatch 3004 // using the time resolution avaiable to StopWatch
3005 [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
3043 public static double GetTimeStamp() 3006 public static double GetTimeStamp()
3044 { 3007 {
3045 return (double)Stopwatch.GetTimestamp() * TimeStampClockPeriod; 3008 return Stopwatch.GetTimestamp() * TimeStampClockPeriod;
3046 } 3009 }
3047 3010
3011 [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
3048 public static double GetTimeStampMS() 3012 public static double GetTimeStampMS()
3049 { 3013 {
3050 return (double)Stopwatch.GetTimestamp() * TimeStampClockPeriodMS; 3014 return Stopwatch.GetTimestamp() * TimeStampClockPeriodMS;
3015 }
3016
3017 // doing math in ticks is usefull to avoid loss of resolution
3018 [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
3019 public static long GetTimeStampTicks()
3020 {
3021 return Stopwatch.GetTimestamp();
3022 }
3023
3024 [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
3025 public static double TimeStampTicksToMS(long ticks)
3026 {
3027 return ticks * TimeStampClockPeriodMS;
3051 } 3028 }
3052 3029
3053 /// <summary> 3030 /// <summary>
@@ -3428,9 +3405,46 @@ namespace OpenSim.Framework
3428 if (length > 2000) 3405 if (length > 2000)
3429 xml = xml.Substring(0, 2000) + "..."; 3406 xml = xml.Substring(0, 2000) + "...";
3430 3407
3408 for (int i = 0 ; i < xml.Length ; i++)
3409 {
3410 if (xml[i] < 0x20)
3411 {
3412 xml = "Unprintable binary data";
3413 break;
3414 }
3415 }
3416
3431 m_log.ErrorFormat("{0} Failed XML ({1} bytes) = {2}", message, length, xml); 3417 m_log.ErrorFormat("{0} Failed XML ({1} bytes) = {2}", message, length, xml);
3432 } 3418 }
3433 3419
3420 /// <summary>
3421 /// Performs a high quality image resize
3422 /// </summary>
3423 /// <param name="image">Image to resize</param>
3424 /// <param name="width">New width</param>
3425 /// <param name="height">New height</param>
3426 /// <returns>Resized image</returns>
3427 public static Bitmap ResizeImageSolid(Image image, int width, int height)
3428 {
3429 Bitmap result = new Bitmap(width, height, PixelFormat.Format24bppRgb);
3430
3431 using (ImageAttributes atrib = new ImageAttributes())
3432 using (Graphics graphics = Graphics.FromImage(result))
3433 {
3434 atrib.SetWrapMode(System.Drawing.Drawing2D.WrapMode.TileFlipXY);
3435 atrib.SetWrapMode(System.Drawing.Drawing2D.WrapMode.TileFlipXY);
3436 graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
3437 graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
3438 graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
3439 graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.None;
3440
3441 graphics.DrawImage(image,new Rectangle(0,0, result.Width, result.Height),
3442 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, atrib);
3443 }
3444
3445 return result;
3446 }
3447
3434 } 3448 }
3435 3449
3436/* don't like this code 3450/* don't like this code
@@ -3595,5 +3609,6 @@ namespace OpenSim.Framework
3595 { 3609 {
3596 rng.GetBytes(buff); 3610 rng.GetBytes(buff);
3597 } 3611 }
3612
3598 } 3613 }
3599} 3614}