diff --git a/OpenSim/Framework/Monitoring/WorkManager.cs b/OpenSim/Framework/Monitoring/WorkManager.cs index 7a0910cfc5..c7198bf856 100755 --- a/OpenSim/Framework/Monitoring/WorkManager.cs +++ b/OpenSim/Framework/Monitoring/WorkManager.cs @@ -26,7 +26,7 @@ */ using System; -using System.Reflection; +using System.Runtime.CompilerServices; using System.Threading; using log4net; @@ -86,6 +86,7 @@ namespace OpenSim.Framework.Monitoring Watchdog.Stop(); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Thread StartThread(ThreadStart start, string name, bool alarmIfTimeout = false, bool log = true) { return StartThread(start, name, ThreadPriority.Normal, true, alarmIfTimeout, null, Watchdog.DEFAULT_WATCHDOG_TIMEOUT_MS, log); @@ -101,6 +102,7 @@ namespace OpenSim.Framework.Monitoring /// Trigger an alarm function is we have timed out /// If true then creation of thread is logged. /// The newly created Thread object + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Thread StartThread( ThreadStart start, string name, ThreadPriority priority, bool alarmIfTimeout, bool log = true) { @@ -245,11 +247,18 @@ namespace OpenSim.Framework.Monitoring /// /// /// The name of the job. This is used in monitoring and debugging. - public static void RunInThreadPool(System.Threading.WaitCallback callback, object obj, string name, bool timeout = true) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void RunInThreadPool(WaitCallback callback, object obj, string name, bool timeout = true) { Util.FireAndForget(callback, obj, name, timeout); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void RunInThreadPool(WaitCallback callback, string name, bool timeout = true) + { + Util.FireAndForget(callback, null, name, timeout); + } + private static void HandleControlCommand(string module, string[] args) { // if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_udpServer.Scene) diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 1033484020..c0ad22eaed 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -248,13 +248,13 @@ namespace OpenSim.Framework public static Encoding UTF8 = Encoding.UTF8; public static Encoding UTF8NoBomEncoding = new UTF8Encoding(false); - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] UTF8Getbytes(string s) { return UTF8.GetBytes(s); } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] UTF8NBGetbytes(string s) { return UTF8NoBomEncoding.GetBytes(s); @@ -388,7 +388,7 @@ namespace OpenSim.Framework get { return randomClass; } } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ulong UIntsToLong(uint X, uint Y) { return ((ulong)X << 32) | (ulong)Y; @@ -398,7 +398,7 @@ namespace OpenSim.Framework // Region handles are based on the coordinate of the region corner with lower X and Y // var regions need more work than this to get that right corner from a generic world position // this corner must be on a grid point - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ulong RegionWorldLocToHandle(uint X, uint Y) { ulong handle = X & 0xffffff00; // make sure it matchs grid coord points. @@ -407,7 +407,7 @@ namespace OpenSim.Framework return handle; } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ulong RegionGridLocToHandle(uint X, uint Y) { ulong handle = X; @@ -416,14 +416,14 @@ namespace OpenSim.Framework return handle; } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void RegionHandleToWorldLoc(ulong handle, out uint X, out uint Y) { X = (uint)(handle >> 32); Y = (uint)(handle & 0xfffffffful); } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void RegionHandleToRegionLoc(ulong handle, out uint X, out uint Y) { X = (uint)(handle >> 40) & 0x00ffffffu; // bring from higher half, divide by 256 and clean @@ -433,14 +433,14 @@ namespace OpenSim.Framework // A region location can be 'world coordinates' (meters) or 'region grid coordinates' // grid coordinates have a fixed step of 256m as defined by viewers - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint WorldToRegionLoc(uint worldCoord) { return worldCoord >> 8; } // Convert a region's 'region grid coordinate' to its 'world coordinate'. - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint RegionToWorldLoc(uint regionCoord) { return regionCoord << 8; @@ -592,17 +592,20 @@ namespace OpenSim.Framework return true; } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T Clamp(T x, T min, T max) where T : IComparable { - return x.CompareTo(max) > 0 ? max : - x.CompareTo(min) < 0 ? min : - x; + if(x.CompareTo(max) > 0) + return max; + + if(x.CompareTo(min) < 0) + return min; + return x; } // Clamp the maximum magnitude of a vector - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Vector3 ClampV(Vector3 x, float max) { float lenSq = x.LengthSquared(); @@ -750,7 +753,7 @@ namespace OpenSim.Framework } } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool IsHexa(char c) { if (c >= '0' && c <= '9') @@ -874,7 +877,7 @@ namespace OpenSim.Framework return ids; } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool IsHexa(byte c) { if (c >= '0' && c <= '9') @@ -2520,7 +2523,7 @@ namespace OpenSim.Framework return found.ToArray(); } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string AppendEndSlash(string path) { int len = path.Length; @@ -2530,7 +2533,7 @@ namespace OpenSim.Framework return path; } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string TrimEndSlash(string path) { int len = path.Length; @@ -2687,7 +2690,7 @@ namespace OpenSim.Framework return data; } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int osUTF8Getbytes(string srcstr, byte[] dstarray, int maxdstlen, bool NullTerm = true) { return osUTF8Getbytes(srcstr, dstarray, 0, maxdstlen, NullTerm); @@ -3054,11 +3057,13 @@ namespace OpenSim.Framework private static readonly Dictionary m_fireAndForgetCallsInProgress = new Dictionary(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void FireAndForget(System.Threading.WaitCallback callback) { FireAndForget(callback, null, null); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void FireAndForget(System.Threading.WaitCallback callback, object obj) { FireAndForget(callback, obj, null); @@ -3412,33 +3417,33 @@ namespace OpenSim.Framework // returns a timestamp in seconds as double // using the time resolution avaiable to StopWatch - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double GetTimeStamp() { return Stopwatch.GetTimestamp() * TimeStampClockPeriod; } // returns a timestamp in ms as double - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double GetTimeStampMS() { return Stopwatch.GetTimestamp() * TimeStampClockPeriodMS; } // doing math in ticks is usefull to avoid loss of resolution - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetTimeStampTicks() { return Stopwatch.GetTimestamp(); } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double TimeStampTicksToMS(long ticks) { return ticks * TimeStampClockPeriodMS; } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AddToGatheredIds(Dictionary uuids, UUID id, sbyte type) { if (id == UUID.Zero)