From 4ab792cd13c92b7f2e33ba9c970907dfb924698f Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Wed, 30 Dec 2020 11:38:18 +0000 Subject: [PATCH] smartthreadpool: remove old windows(like CE) support, remove tabs.. (do runprebuild) --- .../SmartThreadPool/CallerThreadContext.cs | 14 +-- ThirdParty/SmartThreadPool/EventWaitHandle.cs | 104 ------------------ .../SmartThreadPool/EventWaitHandleFactory.cs | 82 -------------- ThirdParty/SmartThreadPool/Exceptions.cs | 3 - ThirdParty/SmartThreadPool/Interfaces.cs | 78 +++++-------- .../SmartThreadPool/InternalInterfaces.cs | 2 +- ThirdParty/SmartThreadPool/PriorityQueue.cs | 6 +- ThirdParty/SmartThreadPool/SLExt.cs | 16 --- .../SmartThreadPool/STPEventWaitHandle.cs | 32 ------ .../SmartThreadPool/STPPerformanceCounter.cs | 88 ++++++++------- ThirdParty/SmartThreadPool/STPStartInfo.cs | 43 +++----- .../SmartThreadPool.ThreadEntry.cs | 8 +- ThirdParty/SmartThreadPool/SmartThreadPool.cs | 6 +- ThirdParty/SmartThreadPool/WIGStartInfo.cs | 56 +++++----- ThirdParty/SmartThreadPool/WorkItem.cs | 39 ++----- ThirdParty/SmartThreadPool/WorkItemFactory.cs | 54 ++++----- ThirdParty/SmartThreadPool/WorkItemsGroup.cs | 31 +++--- .../SmartThreadPool/WorkItemsGroupBase.cs | 14 +-- ThirdParty/SmartThreadPool/WorkItemsQueue.cs | 47 +------- 19 files changed, 195 insertions(+), 528 deletions(-) delete mode 100644 ThirdParty/SmartThreadPool/EventWaitHandle.cs delete mode 100644 ThirdParty/SmartThreadPool/EventWaitHandleFactory.cs delete mode 100644 ThirdParty/SmartThreadPool/SLExt.cs diff --git a/ThirdParty/SmartThreadPool/CallerThreadContext.cs b/ThirdParty/SmartThreadPool/CallerThreadContext.cs index 925c39b18b..82653985a7 100644 --- a/ThirdParty/SmartThreadPool/CallerThreadContext.cs +++ b/ThirdParty/SmartThreadPool/CallerThreadContext.cs @@ -11,15 +11,15 @@ using System.Runtime.Remoting.Messaging; namespace Amib.Threading.Internal { -#region CallerThreadContext class + #region CallerThreadContext class /// /// This class stores the caller call context in order to restore - /// it when the work item is executed in the thread pool environment. + /// it when the work item is executed in the thread pool environment. /// internal class CallerThreadContext { -#region Prepare reflection information + #region Prepare reflection information // Cached type information. private static readonly MethodInfo getLogicalCallContextMethodInfo = @@ -36,7 +36,7 @@ namespace Amib.Threading.Internal if (fi != null) { - return (string) fi.GetValue(null); + return (string)fi.GetValue(null); } return "HttpContext"; @@ -44,7 +44,7 @@ namespace Amib.Threading.Internal #endregion -#region Private fields + #region Private fields private HttpContext _httpContext; private LogicalCallContext _callContext; @@ -88,7 +88,7 @@ namespace Amib.Threading.Internal // TODO: In NET 2.0, redo using the new feature of ExecutionContext class - Capture() // Capture Call Context - if(captureCallContext && (getLogicalCallContextMethodInfo != null)) + if (captureCallContext && (getLogicalCallContextMethodInfo != null)) { callerThreadContext._callContext = (LogicalCallContext)getLogicalCallContextMethodInfo.Invoke(Thread.CurrentThread, null); if (callerThreadContext._callContext != null) @@ -124,7 +124,7 @@ namespace Amib.Threading.Internal setLogicalCallContextMethodInfo.Invoke(Thread.CurrentThread, new object[] { callerThreadContext._callContext }); } - // Restore HttpContext + // Restore HttpContext if (callerThreadContext._httpContext != null) { HttpContext.Current = callerThreadContext._httpContext; diff --git a/ThirdParty/SmartThreadPool/EventWaitHandle.cs b/ThirdParty/SmartThreadPool/EventWaitHandle.cs deleted file mode 100644 index b7983cd72a..0000000000 --- a/ThirdParty/SmartThreadPool/EventWaitHandle.cs +++ /dev/null @@ -1,104 +0,0 @@ -#if (_WINDOWS_CE) - -using System; -using System.Runtime.InteropServices; -using System.Threading; - -namespace Amib.Threading.Internal -{ - /// - /// EventWaitHandle class - /// In WindowsCE this class doesn't exist and I needed the WaitAll and WaitAny implementation. - /// So I wrote this class to implement these two methods with some of their overloads. - /// It uses the WaitForMultipleObjects API to do the WaitAll and WaitAny. - /// Note that this class doesn't even inherit from WaitHandle! - /// - public class STPEventWaitHandle - { - #region Public Constants - - public const int WaitTimeout = Timeout.Infinite; - - #endregion - - #region Private External Constants - - private const Int32 WAIT_FAILED = -1; - private const Int32 WAIT_TIMEOUT = 0x102; - private const UInt32 INFINITE = 0xFFFFFFFF; - - #endregion - - #region WaitAll and WaitAny - - internal static bool WaitOne(WaitHandle waitHandle, int millisecondsTimeout, bool exitContext) - { - return waitHandle.WaitOne(millisecondsTimeout, exitContext); - } - - private static IntPtr[] PrepareNativeHandles(WaitHandle[] waitHandles) - { - IntPtr[] nativeHandles = new IntPtr[waitHandles.Length]; - for (int i = 0; i < waitHandles.Length; i++) - { - nativeHandles[i] = waitHandles[i].Handle; - } - return nativeHandles; - } - - public static bool WaitAll(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) - { - uint timeout = millisecondsTimeout < 0 ? INFINITE : (uint)millisecondsTimeout; - - IntPtr[] nativeHandles = PrepareNativeHandles(waitHandles); - - int result = WaitForMultipleObjects((uint)waitHandles.Length, nativeHandles, true, timeout); - - if (result == WAIT_TIMEOUT || result == WAIT_FAILED) - { - return false; - } - - return true; - } - - - public static int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) - { - uint timeout = millisecondsTimeout < 0 ? INFINITE : (uint)millisecondsTimeout; - - IntPtr[] nativeHandles = PrepareNativeHandles(waitHandles); - - int result = WaitForMultipleObjects((uint)waitHandles.Length, nativeHandles, false, timeout); - - if (result >= 0 && result < waitHandles.Length) - { - return result; - } - - return -1; - } - - public static int WaitAny(WaitHandle[] waitHandles) - { - return WaitAny(waitHandles, Timeout.Infinite, false); - } - - public static int WaitAny(WaitHandle[] waitHandles, TimeSpan timeout, bool exitContext) - { - int millisecondsTimeout = (int)timeout.TotalMilliseconds; - - return WaitAny(waitHandles, millisecondsTimeout, false); - } - - #endregion - - #region External methods - - [DllImport("coredll.dll", SetLastError = true)] - public static extern int WaitForMultipleObjects(uint nCount, IntPtr[] lpHandles, bool fWaitAll, uint dwMilliseconds); - - #endregion - } -} -#endif \ No newline at end of file diff --git a/ThirdParty/SmartThreadPool/EventWaitHandleFactory.cs b/ThirdParty/SmartThreadPool/EventWaitHandleFactory.cs deleted file mode 100644 index ece24de838..0000000000 --- a/ThirdParty/SmartThreadPool/EventWaitHandleFactory.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System.Threading; - -#if (_WINDOWS_CE) -using System; -using System.Runtime.InteropServices; -#endif - -namespace Amib.Threading.Internal -{ - /// - /// EventWaitHandleFactory class. - /// This is a static class that creates AutoResetEvent and ManualResetEvent objects. - /// In WindowCE the WaitForMultipleObjects API fails to use the Handle property - /// of XxxResetEvent. It can use only handles that were created by the CreateEvent API. - /// Consequently this class creates the needed XxxResetEvent and replaces the handle if - /// it's a WindowsCE OS. - /// - public static class EventWaitHandleFactory - { - /// - /// Create a new AutoResetEvent object - /// - /// Return a new AutoResetEvent object - public static AutoResetEvent CreateAutoResetEvent() - { - AutoResetEvent waitHandle = new AutoResetEvent(false); - -#if (_WINDOWS_CE) - ReplaceEventHandle(waitHandle, false, false); -#endif - - return waitHandle; - } - - /// - /// Create a new ManualResetEvent object - /// - /// Return a new ManualResetEvent object - public static ManualResetEvent CreateManualResetEvent(bool initialState) - { - ManualResetEvent waitHandle = new ManualResetEvent(initialState); - -#if (_WINDOWS_CE) - ReplaceEventHandle(waitHandle, true, initialState); -#endif - - return waitHandle; - } - -#if (_WINDOWS_CE) - - /// - /// Replace the event handle - /// - /// The WaitHandle object which its handle needs to be replaced. - /// Indicates if the event is a ManualResetEvent (true) or an AutoResetEvent (false) - /// The initial state of the event - private static void ReplaceEventHandle(WaitHandle waitHandle, bool manualReset, bool initialState) - { - // Store the old handle - IntPtr oldHandle = waitHandle.Handle; - - // Create a new event - IntPtr newHandle = CreateEvent(IntPtr.Zero, manualReset, initialState, null); - - // Replace the old event with the new event - waitHandle.Handle = newHandle; - - // Close the old event - CloseHandle (oldHandle); - } - - [DllImport("coredll.dll", SetLastError = true)] - public static extern IntPtr CreateEvent(IntPtr lpEventAttributes, bool bManualReset, bool bInitialState, string lpName); - - //Handle - [DllImport("coredll.dll", SetLastError = true)] - public static extern bool CloseHandle(IntPtr hObject); -#endif - - } -} diff --git a/ThirdParty/SmartThreadPool/Exceptions.cs b/ThirdParty/SmartThreadPool/Exceptions.cs index 6c6a88bab1..7afa1b5e27 100644 --- a/ThirdParty/SmartThreadPool/Exceptions.cs +++ b/ThirdParty/SmartThreadPool/Exceptions.cs @@ -68,7 +68,6 @@ namespace Amib.Threading } -#if !(_WINDOWS_CE) && !(_SILVERLIGHT) && !(WINDOWS_PHONE) /// /// Represents an exception in case IWorkItemResult.GetResult has been canceled /// @@ -105,7 +104,5 @@ namespace Amib.Threading } } -#endif - #endregion } diff --git a/ThirdParty/SmartThreadPool/Interfaces.cs b/ThirdParty/SmartThreadPool/Interfaces.cs index 8cc23a04ff..741b3a1667 100644 --- a/ThirdParty/SmartThreadPool/Interfaces.cs +++ b/ThirdParty/SmartThreadPool/Interfaces.cs @@ -30,13 +30,13 @@ namespace Amib.Threading public delegate void WorkItemsGroupIdleHandler(IWorkItemsGroup workItemsGroup); /// - /// A delegate to call after a thread is created, but before + /// A delegate to call after a thread is created, but before /// it's first use. /// public delegate void ThreadInitializationHandler(); /// - /// A delegate to call when a thread is about to exit, after + /// A delegate to call when a thread is about to exit, after /// it is no longer belong to the pool. /// public delegate void ThreadTerminationHandler(); @@ -61,7 +61,7 @@ namespace Amib.Threading #endregion - #region IWorkItemsGroup interface + #region IWorkItemsGroup interface /// /// IWorkItemsGroup interface @@ -150,7 +150,7 @@ namespace Amib.Threading /// Queue a work item /// /// A callback to execute - /// Returns a work item result + /// Returns a work item result IWorkItemResult QueueWorkItem(WorkItemCallback callback); /// @@ -166,7 +166,7 @@ namespace Amib.Threading /// /// A callback to execute /// - /// The context object of the work item. Used for passing arguments to the work item. + /// The context object of the work item. Used for passing arguments to the work item. /// /// Returns a work item result IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state); @@ -176,7 +176,7 @@ namespace Amib.Threading /// /// A callback to execute /// - /// The context object of the work item. Used for passing arguments to the work item. + /// The context object of the work item. Used for passing arguments to the work item. /// /// The work item priority /// Returns a work item result @@ -187,7 +187,7 @@ namespace Amib.Threading /// /// A callback to execute /// - /// The context object of the work item. Used for passing arguments to the work item. + /// The context object of the work item. Used for passing arguments to the work item. /// /// /// A delegate to call after the callback completion @@ -200,7 +200,7 @@ namespace Amib.Threading /// /// A callback to execute /// - /// The context object of the work item. Used for passing arguments to the work item. + /// The context object of the work item. Used for passing arguments to the work item. /// /// /// A delegate to call after the callback completion @@ -214,7 +214,7 @@ namespace Amib.Threading /// /// A callback to execute /// - /// The context object of the work item. Used for passing arguments to the work item. + /// The context object of the work item. Used for passing arguments to the work item. /// /// /// A delegate to call after the callback completion @@ -228,7 +228,7 @@ namespace Amib.Threading /// /// A callback to execute /// - /// The context object of the work item. Used for passing arguments to the work item. + /// The context object of the work item. Used for passing arguments to the work item. /// /// /// A delegate to call after the callback completion @@ -252,7 +252,7 @@ namespace Amib.Threading /// Work item information /// A callback to execute /// - /// The context object of the work item. Used for passing arguments to the work item. + /// The context object of the work item. Used for passing arguments to the work item. /// /// Returns a work item result IWorkItemResult QueueWorkItem(WorkItemInfo workItemInfo, WorkItemCallback callback, object state); @@ -271,19 +271,19 @@ namespace Amib.Threading /// Queue a work item. /// /// Returns a IWorkItemResult object, but its GetResult() will always return null - IWorkItemResult QueueWorkItem (Action action, WorkItemPriority priority); + IWorkItemResult QueueWorkItem(Action action, WorkItemPriority priority); /// /// Queue a work item. /// /// Returns a IWorkItemResult object, but its GetResult() will always return null - IWorkItemResult QueueWorkItem (Action action, T arg, WorkItemPriority priority); + IWorkItemResult QueueWorkItem(Action action, T arg, WorkItemPriority priority); /// /// Queue a work item. /// /// Returns a IWorkItemResult object, but its GetResult() will always return null - IWorkItemResult QueueWorkItem (Action action, T arg); + IWorkItemResult QueueWorkItem(Action action, T arg); /// /// Queue a work item. @@ -295,7 +295,7 @@ namespace Amib.Threading /// Queue a work item. /// /// Returns a IWorkItemResult object, but its GetResult() will always return null - IWorkItemResult QueueWorkItem (Action action, T1 arg1, T2 arg2, WorkItemPriority priority); + IWorkItemResult QueueWorkItem(Action action, T1 arg1, T2 arg2, WorkItemPriority priority); /// /// Queue a work item. @@ -307,7 +307,7 @@ namespace Amib.Threading /// Queue a work item. /// /// Returns a IWorkItemResult object, but its GetResult() will always return null - IWorkItemResult QueueWorkItem (Action action, T1 arg1, T2 arg2, T3 arg3, WorkItemPriority priority); + IWorkItemResult QueueWorkItem(Action action, T1 arg1, T2 arg2, T3 arg3, WorkItemPriority priority); /// /// Queue a work item. @@ -319,7 +319,7 @@ namespace Amib.Threading /// Queue a work item. /// /// Returns a IWorkItemResult object, but its GetResult() will always return null - IWorkItemResult QueueWorkItem (Action action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, WorkItemPriority priority); + IWorkItemResult QueueWorkItem(Action action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, WorkItemPriority priority); #endregion @@ -328,35 +328,35 @@ namespace Amib.Threading /// /// Queue a work item. /// - /// Returns a IWorkItemResult<TResult> object. + /// Returns a IWorkItemResult<TResult> object. /// its GetResult() returns a TResult object IWorkItemResult QueueWorkItem(Func func); /// /// Queue a work item. /// - /// Returns a IWorkItemResult<TResult> object. + /// Returns a IWorkItemResult<TResult> object. /// its GetResult() returns a TResult object IWorkItemResult QueueWorkItem(Func func, T arg); /// /// Queue a work item. /// - /// Returns a IWorkItemResult<TResult> object. + /// Returns a IWorkItemResult<TResult> object. /// its GetResult() returns a TResult object IWorkItemResult QueueWorkItem(Func func, T1 arg1, T2 arg2); /// /// Queue a work item. /// - /// Returns a IWorkItemResult<TResult> object. + /// Returns a IWorkItemResult<TResult> object. /// its GetResult() returns a TResult object IWorkItemResult QueueWorkItem(Func func, T1 arg1, T2 arg2, T3 arg3); /// /// Queue a work item. /// - /// Returns a IWorkItemResult<TResult> object. + /// Returns a IWorkItemResult<TResult> object. /// its GetResult() returns a TResult object IWorkItemResult QueueWorkItem(Func func, T1 arg1, T2 arg2, T3 arg3, T4 arg4); @@ -373,22 +373,22 @@ namespace Amib.Threading /// /// Never call to the PostExecute call back /// - Never = 0x00, + Never = 0x00, /// /// Call to the PostExecute only when the work item is cancelled /// - WhenWorkItemCanceled = 0x01, + WhenWorkItemCanceled = 0x01, /// /// Call to the PostExecute only when the work item is not cancelled /// - WhenWorkItemNotCanceled = 0x02, + WhenWorkItemNotCanceled = 0x02, /// /// Always call to the PostExecute /// - Always = WhenWorkItemCanceled | WhenWorkItemNotCanceled, + Always = WhenWorkItemCanceled | WhenWorkItemNotCanceled, } #endregion @@ -460,7 +460,7 @@ namespace Amib.Threading /// /// Timeout in milliseconds, or -1 for infinite /// - /// true to exit the synchronization domain for the context before the wait (if in a synchronized context), and reacquire it; otherwise, false. + /// true to exit the synchronization domain for the context before the wait (if in a synchronized context), and reacquire it; otherwise, false. /// /// A cancel wait handle to interrupt the blocking if needed /// The result of the work item @@ -525,7 +525,7 @@ namespace Amib.Threading /// /// Timeout in milliseconds, or -1 for infinite /// - /// true to exit the synchronization domain for the context before the wait (if in a synchronized context), and reacquire it; otherwise, false. + /// true to exit the synchronization domain for the context before the wait (if in a synchronized context), and reacquire it; otherwise, false. /// /// A cancel wait handle to interrupt the blocking if needed /// Filled with the exception if one was thrown @@ -566,7 +566,7 @@ namespace Amib.Threading bool IsCanceled { get; } /// - /// Gets the user-defined object that contains context data + /// Gets the user-defined object that contains context data /// for the work item method. /// object State { get; } @@ -582,7 +582,7 @@ namespace Amib.Threading /// If the work item is completed, it will remain completed /// If the work item is in progress then the user can check the SmartThreadPool.IsWorkItemCanceled /// property to check if the work item has been cancelled. If the abortExecution is set to true then - /// the Smart Thread Pool will send an AbortException to the running thread to stop the execution + /// the Smart Thread Pool will send an AbortException to the running thread to stop the execution /// of the work item. When an in progress work item is canceled its GetResult will throw WorkItemCancelException. /// If the work item is already cancelled it will remain cancelled /// @@ -607,22 +607,4 @@ namespace Amib.Threading } #endregion - - #region .NET 3.5 - - // All these delegate are built-in .NET 3.5 - // Comment/Remove them when compiling to .NET 3.5 to avoid ambiguity. - - public delegate void Action(); - public delegate void Action(T1 arg1, T2 arg2); - public delegate void Action(T1 arg1, T2 arg2, T3 arg3); - public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4); - - public delegate TResult Func(); - public delegate TResult Func(T arg1); - public delegate TResult Func(T1 arg1, T2 arg2); - public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3); - public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4); - - #endregion } diff --git a/ThirdParty/SmartThreadPool/InternalInterfaces.cs b/ThirdParty/SmartThreadPool/InternalInterfaces.cs index 3055117407..0072e10019 100644 --- a/ThirdParty/SmartThreadPool/InternalInterfaces.cs +++ b/ThirdParty/SmartThreadPool/InternalInterfaces.cs @@ -16,7 +16,7 @@ namespace Amib.Threading.Internal { /// /// This method is intent for internal use. - /// + /// IWorkItemResult GetWorkItemResult(); } diff --git a/ThirdParty/SmartThreadPool/PriorityQueue.cs b/ThirdParty/SmartThreadPool/PriorityQueue.cs index 3ea608436d..ce04751bbd 100644 --- a/ThirdParty/SmartThreadPool/PriorityQueue.cs +++ b/ThirdParty/SmartThreadPool/PriorityQueue.cs @@ -26,7 +26,7 @@ namespace Amib.Threading.Internal private readonly LinkedList[] _queues = new LinkedList[_queuesCount]; /// - /// The total number of work items within the queues + /// The total number of work items within the queues /// private int _workItemsCount; @@ -110,7 +110,7 @@ namespace Amib.Threading.Internal } /// - /// The number of work items + /// The number of work items /// public int Count { @@ -121,7 +121,7 @@ namespace Amib.Threading.Internal } /// - /// Clear all the work items + /// Clear all the work items /// public void Clear() { diff --git a/ThirdParty/SmartThreadPool/SLExt.cs b/ThirdParty/SmartThreadPool/SLExt.cs deleted file mode 100644 index 23a60bcb90..0000000000 --- a/ThirdParty/SmartThreadPool/SLExt.cs +++ /dev/null @@ -1,16 +0,0 @@ -#if _SILVERLIGHT - -using System.Threading; - -namespace Amib.Threading -{ - public enum ThreadPriority - { - Lowest, - BelowNormal, - Normal, - AboveNormal, - Highest, - } -} -#endif diff --git a/ThirdParty/SmartThreadPool/STPEventWaitHandle.cs b/ThirdParty/SmartThreadPool/STPEventWaitHandle.cs index 9b17f694a5..aca3a2c75c 100644 --- a/ThirdParty/SmartThreadPool/STPEventWaitHandle.cs +++ b/ThirdParty/SmartThreadPool/STPEventWaitHandle.cs @@ -1,36 +1,8 @@ -#if !(_WINDOWS_CE) - using System; using System.Threading; namespace Amib.Threading.Internal { -#if _WINDOWS || WINDOWS_PHONE - internal static class STPEventWaitHandle - { - public const int WaitTimeout = Timeout.Infinite; - - internal static bool WaitAll(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) - { - return WaitHandle.WaitAll(waitHandles, millisecondsTimeout); - } - - internal static int WaitAny(WaitHandle[] waitHandles) - { - return WaitHandle.WaitAny(waitHandles); - } - - internal static int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) - { - return WaitHandle.WaitAny(waitHandles, millisecondsTimeout); - } - - internal static bool WaitOne(WaitHandle waitHandle, int millisecondsTimeout, bool exitContext) - { - return waitHandle.WaitOne(millisecondsTimeout); - } - } -#else internal static class STPEventWaitHandle { public const int WaitTimeout = Timeout.Infinite; @@ -55,8 +27,4 @@ namespace Amib.Threading.Internal return waitHandle.WaitOne(millisecondsTimeout, exitContext); } } -#endif - } - -#endif \ No newline at end of file diff --git a/ThirdParty/SmartThreadPool/STPPerformanceCounter.cs b/ThirdParty/SmartThreadPool/STPPerformanceCounter.cs index bd68499668..64d738e815 100644 --- a/ThirdParty/SmartThreadPool/STPPerformanceCounter.cs +++ b/ThirdParty/SmartThreadPool/STPPerformanceCounter.cs @@ -23,7 +23,6 @@ namespace Amib.Threading.Internal void SampleWorkItemsWaitTime(TimeSpan workItemWaitTime); void SampleWorkItemsProcessTime(TimeSpan workItemProcessTime); } -#if !(_WINDOWS_CE) && !(_SILVERLIGHT) && !(WINDOWS_PHONE) internal enum STPPerformanceCounterType { @@ -51,7 +50,7 @@ namespace Amib.Threading.Internal LastCounter = 14, } - + /// /// Summary description for STPPerformanceCounter. @@ -65,8 +64,8 @@ namespace Amib.Threading.Internal // Methods public STPPerformanceCounter( - string counterName, - string counterHelp, + string counterName, + string counterHelp, PerformanceCounterType pcType) { _counterName = counterName; @@ -77,13 +76,13 @@ namespace Amib.Threading.Internal public void AddCounterToCollection(CounterCreationDataCollection counterData) { CounterCreationData counterCreationData = new CounterCreationData( - _counterName, - _counterHelp, + _counterName, + _counterHelp, _pcType); counterData.Add(counterCreationData); } - + // Properties public string Name { @@ -107,37 +106,37 @@ namespace Amib.Threading.Internal { _instance = new STPPerformanceCounters(); } - + private STPPerformanceCounters() { - STPPerformanceCounter[] stpPerformanceCounters = new STPPerformanceCounter[] - { - new STPPerformanceCounter("Active threads", "The current number of available in the thread pool.", PerformanceCounterType.NumberOfItems32), - new STPPerformanceCounter("In use threads", "The current number of threads that execute a work item.", PerformanceCounterType.NumberOfItems32), - new STPPerformanceCounter("Overhead threads", "The current number of threads that are active, but are not in use.", PerformanceCounterType.NumberOfItems32), - new STPPerformanceCounter("% overhead threads", "The current number of threads that are active, but are not in use in percents.", PerformanceCounterType.RawFraction), - new STPPerformanceCounter("% overhead threads base", "The current number of threads that are active, but are not in use in percents.", PerformanceCounterType.RawBase), + STPPerformanceCounter[] stpPerformanceCounters = new STPPerformanceCounter[] + { + new STPPerformanceCounter("Active threads", "The current number of available in the thread pool.", PerformanceCounterType.NumberOfItems32), + new STPPerformanceCounter("In use threads", "The current number of threads that execute a work item.", PerformanceCounterType.NumberOfItems32), + new STPPerformanceCounter("Overhead threads", "The current number of threads that are active, but are not in use.", PerformanceCounterType.NumberOfItems32), + new STPPerformanceCounter("% overhead threads", "The current number of threads that are active, but are not in use in percents.", PerformanceCounterType.RawFraction), + new STPPerformanceCounter("% overhead threads base", "The current number of threads that are active, but are not in use in percents.", PerformanceCounterType.RawBase), - new STPPerformanceCounter("Work Items", "The number of work items in the Smart Thread Pool. Both queued and processed.", PerformanceCounterType.NumberOfItems32), - new STPPerformanceCounter("Work Items in queue", "The current number of work items in the queue", PerformanceCounterType.NumberOfItems32), - new STPPerformanceCounter("Work Items processed", "The number of work items already processed", PerformanceCounterType.NumberOfItems32), + new STPPerformanceCounter("Work Items", "The number of work items in the Smart Thread Pool. Both queued and processed.", PerformanceCounterType.NumberOfItems32), + new STPPerformanceCounter("Work Items in queue", "The current number of work items in the queue", PerformanceCounterType.NumberOfItems32), + new STPPerformanceCounter("Work Items processed", "The number of work items already processed", PerformanceCounterType.NumberOfItems32), - new STPPerformanceCounter("Work Items queued/sec", "The number of work items queued per second", PerformanceCounterType.RateOfCountsPerSecond32), - new STPPerformanceCounter("Work Items processed/sec", "The number of work items processed per second", PerformanceCounterType.RateOfCountsPerSecond32), + new STPPerformanceCounter("Work Items queued/sec", "The number of work items queued per second", PerformanceCounterType.RateOfCountsPerSecond32), + new STPPerformanceCounter("Work Items processed/sec", "The number of work items processed per second", PerformanceCounterType.RateOfCountsPerSecond32), - new STPPerformanceCounter("Avg. Work Item wait time/sec", "The average time a work item supends in the queue waiting for its turn to execute.", PerformanceCounterType.AverageCount64), - new STPPerformanceCounter("Avg. Work Item wait time base", "The average time a work item supends in the queue waiting for its turn to execute.", PerformanceCounterType.AverageBase), + new STPPerformanceCounter("Avg. Work Item wait time/sec", "The average time a work item supends in the queue waiting for its turn to execute.", PerformanceCounterType.AverageCount64), + new STPPerformanceCounter("Avg. Work Item wait time base", "The average time a work item supends in the queue waiting for its turn to execute.", PerformanceCounterType.AverageBase), - new STPPerformanceCounter("Avg. Work Item process time/sec", "The average time it takes to process a work item.", PerformanceCounterType.AverageCount64), - new STPPerformanceCounter("Avg. Work Item process time base", "The average time it takes to process a work item.", PerformanceCounterType.AverageBase), + new STPPerformanceCounter("Avg. Work Item process time/sec", "The average time it takes to process a work item.", PerformanceCounterType.AverageCount64), + new STPPerformanceCounter("Avg. Work Item process time base", "The average time it takes to process a work item.", PerformanceCounterType.AverageBase), - new STPPerformanceCounter("Work Items Groups", "The current number of work item groups associated with the Smart Thread Pool.", PerformanceCounterType.NumberOfItems32), + new STPPerformanceCounter("Work Items Groups", "The current number of work item groups associated with the Smart Thread Pool.", PerformanceCounterType.NumberOfItems32), }; _stpPerformanceCounters = stpPerformanceCounters; SetupCategory(); } - + private void SetupCategory() { if (!PerformanceCounterCategory.Exists(_stpCategoryName)) @@ -150,14 +149,14 @@ namespace Amib.Threading.Internal } PerformanceCounterCategory.Create( - _stpCategoryName, - _stpCategoryHelp, + _stpCategoryName, + _stpCategoryHelp, PerformanceCounterCategoryType.MultiInstance, counters); - + } } - + // Properties public static STPPerformanceCounters Instance { @@ -166,7 +165,7 @@ namespace Amib.Threading.Internal return _instance; } } - } + } internal class STPInstancePerformanceCounter : IDisposable { @@ -181,14 +180,14 @@ namespace Amib.Threading.Internal } public STPInstancePerformanceCounter( - string instance, + string instance, STPPerformanceCounterType spcType) : this() { STPPerformanceCounters counters = STPPerformanceCounters.Instance; _pcs = new PerformanceCounter( - STPPerformanceCounters._stpCategoryName, - counters._stpPerformanceCounters[(int) spcType].Name, - instance, + STPPerformanceCounters._stpCategoryName, + counters._stpPerformanceCounters[(int) spcType].Name, + instance, false); _pcs.RawValue = _pcs.RawValue; } @@ -203,7 +202,7 @@ namespace Amib.Threading.Internal _pcs = null; } } - + public void Dispose() { Dispose(true); @@ -220,12 +219,12 @@ namespace Amib.Threading.Internal } _isDisposed = true; } - + public virtual void Increment() { _pcs.Increment(); } - + public virtual void IncrementBy(long val) { _pcs.IncrementBy(val); @@ -259,7 +258,7 @@ namespace Amib.Threading.Internal { _stpInstanceNullPerformanceCounter = new STPInstanceNullPerformanceCounter(); } - + public STPInstancePerformanceCounters(string instance) { _isDisposed = false; @@ -274,7 +273,7 @@ namespace Amib.Threading.Internal if (instance != null) { _pcs[i] = new STPInstancePerformanceCounter( - instance, + instance, (STPPerformanceCounterType) i); } else @@ -283,7 +282,7 @@ namespace Amib.Threading.Internal } } } - + public void Close() { @@ -316,7 +315,7 @@ namespace Amib.Threading.Internal } _isDisposed = true; } - + private STPInstancePerformanceCounter GetCounter(STPPerformanceCounterType spcType) { return _pcs[(int) spcType]; @@ -354,7 +353,6 @@ namespace Amib.Threading.Internal GetCounter(STPPerformanceCounterType.AvgWorkItemProcessTimeBase).Increment(); } } -#endif internal class NullSTPInstancePerformanceCounters : ISTPInstancePerformanceCounters, ISTPPerformanceCountersReader { @@ -365,9 +363,9 @@ namespace Amib.Threading.Internal get { return _instance; } } - public void Close() {} + public void Close() {} public void Dispose() {} - + public void SampleThreads(long activeThreads, long inUseThreads) {} public void SampleWorkItems(long workItemsQueued, long workItemsProcessed) {} public void SampleWorkItemsWaitTime(TimeSpan workItemWaitTime) {} diff --git a/ThirdParty/SmartThreadPool/STPStartInfo.cs b/ThirdParty/SmartThreadPool/STPStartInfo.cs index 8ea547c33d..d458c77386 100644 --- a/ThirdParty/SmartThreadPool/STPStartInfo.cs +++ b/ThirdParty/SmartThreadPool/STPStartInfo.cs @@ -11,9 +11,7 @@ namespace Amib.Threading private int _idleTimeout = SmartThreadPool.DefaultIdleTimeout; private int _minWorkerThreads = SmartThreadPool.DefaultMinWorkerThreads; private int _maxWorkerThreads = SmartThreadPool.DefaultMaxWorkerThreads; -#if !(WINDOWS_PHONE) private ThreadPriority _threadPriority = SmartThreadPool.DefaultThreadPriority; -#endif private string _performanceCounterInstanceName = SmartThreadPool.DefaultPerformanceCounterInstanceName; private bool _areThreadsBackground = SmartThreadPool.DefaultAreThreadsBackground; private bool _enableLocalPerformanceCounters; @@ -23,9 +21,7 @@ namespace Amib.Threading public STPStartInfo() { _performanceCounterInstanceName = SmartThreadPool.DefaultPerformanceCounterInstanceName; -#if !(WINDOWS_PHONE) _threadPriority = SmartThreadPool.DefaultThreadPriority; -#endif _maxWorkerThreads = SmartThreadPool.DefaultMaxWorkerThreads; _idleTimeout = SmartThreadPool.DefaultIdleTimeout; _minWorkerThreads = SmartThreadPool.DefaultMinWorkerThreads; @@ -37,16 +33,12 @@ namespace Amib.Threading _idleTimeout = stpStartInfo.IdleTimeout; _minWorkerThreads = stpStartInfo.MinWorkerThreads; _maxWorkerThreads = stpStartInfo.MaxWorkerThreads; -#if !(WINDOWS_PHONE) _threadPriority = stpStartInfo.ThreadPriority; -#endif _performanceCounterInstanceName = stpStartInfo.PerformanceCounterInstanceName; _enableLocalPerformanceCounters = stpStartInfo._enableLocalPerformanceCounters; _threadPoolName = stpStartInfo._threadPoolName; _areThreadsBackground = stpStartInfo.AreThreadsBackground; -#if !(_SILVERLIGHT) && !(WINDOWS_PHONE) _apartmentState = stpStartInfo._apartmentState; -#endif } /// @@ -63,7 +55,6 @@ namespace Amib.Threading } } - /// /// Get/Set the lower limit of threads in the pool. /// @@ -77,7 +68,6 @@ namespace Amib.Threading } } - /// /// Get/Set the upper limit of threads in the pool. /// @@ -91,7 +81,6 @@ namespace Amib.Threading } } -#if !(WINDOWS_PHONE) /// /// Get/Set the scheduling priority of the threads in the pool. /// The Os handles the scheduling. @@ -105,15 +94,16 @@ namespace Amib.Threading _threadPriority = value; } } -#endif + /// /// Get/Set the thread pool name. Threads will get names depending on this. /// - public virtual string ThreadPoolName { + public virtual string ThreadPoolName + { get { return _threadPoolName; } set { - ThrowIfReadOnly (); + ThrowIfReadOnly(); _threadPoolName = value; } } @@ -134,7 +124,7 @@ namespace Amib.Threading /// /// Enable/Disable the local performance counter. - /// This enables the user to get some performance information about the SmartThreadPool + /// This enables the user to get some performance information about the SmartThreadPool /// without using Windows performance counters. (Useful on WindowsCE, Silverlight, etc.) /// The default is false. /// @@ -152,14 +142,14 @@ namespace Amib.Threading /// Get/Set backgroundness of thread in thread pool. /// public virtual bool AreThreadsBackground - { - get { return _areThreadsBackground; } - set - { - ThrowIfReadOnly (); - _areThreadsBackground = value; - } - } + { + get { return _areThreadsBackground; } + set + { + ThrowIfReadOnly(); + _areThreadsBackground = value; + } + } /// /// Get a readonly version of this STPStartInfo. @@ -170,8 +160,6 @@ namespace Amib.Threading return new STPStartInfo(this) { _readOnly = true }; } -#if !(_SILVERLIGHT) && !(WINDOWS_PHONE) - private ApartmentState _apartmentState = SmartThreadPool.DefaultApartmentState; /// @@ -187,8 +175,6 @@ namespace Amib.Threading } } -#if !(_SILVERLIGHT) && !(WINDOWS_PHONE) - /// /// Get/Set the max stack size of threads in the thread pool /// @@ -205,8 +191,5 @@ namespace Amib.Threading _maxStackSize = value; } } -#endif - -#endif } } diff --git a/ThirdParty/SmartThreadPool/SmartThreadPool.ThreadEntry.cs b/ThirdParty/SmartThreadPool/SmartThreadPool.ThreadEntry.cs index 4713332dea..c1fa5a87a3 100644 --- a/ThirdParty/SmartThreadPool/SmartThreadPool.ThreadEntry.cs +++ b/ThirdParty/SmartThreadPool/SmartThreadPool.ThreadEntry.cs @@ -26,15 +26,15 @@ namespace Amib.Threading /// /// A reference from each thread in the thread pool to its SmartThreadPool /// object container. - /// With this variable a thread can know whatever it belongs to a + /// With this variable a thread can know whatever it belongs to a /// SmartThreadPool. /// private readonly SmartThreadPool _associatedSmartThreadPool; /// - /// A reference to the current work item a thread from the thread pool + /// A reference to the current work item a thread from the thread pool /// is executing. - /// + /// public WorkItem CurrentWorkItem { get; set; } public ThreadEntry(SmartThreadPool stp) @@ -57,4 +57,4 @@ namespace Amib.Threading #endregion } -} \ No newline at end of file +} diff --git a/ThirdParty/SmartThreadPool/SmartThreadPool.cs b/ThirdParty/SmartThreadPool/SmartThreadPool.cs index 021e668468..26744c493f 100644 --- a/ThirdParty/SmartThreadPool/SmartThreadPool.cs +++ b/ThirdParty/SmartThreadPool/SmartThreadPool.cs @@ -251,14 +251,12 @@ namespace Amib.Threading /// Signaled when the thread pool is idle, i.e. no thread is busy /// and the work items queue is empty /// - //private ManualResetEvent _isIdleWaitHandle = new ManualResetEvent(true); - private ManualResetEvent _isIdleWaitHandle = EventWaitHandleFactory.CreateManualResetEvent(true); + private ManualResetEvent _isIdleWaitHandle = new ManualResetEvent(true); /// /// An event to signal all the threads to quit immediately. /// - //private ManualResetEvent _shuttingDownEvent = new ManualResetEvent(false); - private ManualResetEvent _shuttingDownEvent = EventWaitHandleFactory.CreateManualResetEvent(false); + private ManualResetEvent _shuttingDownEvent = new ManualResetEvent(false); /// /// A flag to indicate if the Smart Thread Pool is now suspended. diff --git a/ThirdParty/SmartThreadPool/WIGStartInfo.cs b/ThirdParty/SmartThreadPool/WIGStartInfo.cs index 756ac1f231..4ea92b9c56 100644 --- a/ThirdParty/SmartThreadPool/WIGStartInfo.cs +++ b/ThirdParty/SmartThreadPool/WIGStartInfo.cs @@ -56,10 +56,10 @@ namespace Amib.Threading public virtual bool UseCallerCallContext { get { return _useCallerCallContext; } - set - { - ThrowIfReadOnly(); - _useCallerCallContext = value; + set + { + ThrowIfReadOnly(); + _useCallerCallContext = value; } } @@ -70,10 +70,10 @@ namespace Amib.Threading public virtual bool UseCallerHttpContext { get { return _useCallerHttpContext; } - set - { - ThrowIfReadOnly(); - _useCallerHttpContext = value; + set + { + ThrowIfReadOnly(); + _useCallerHttpContext = value; } } @@ -84,10 +84,10 @@ namespace Amib.Threading public virtual bool DisposeOfStateObjects { get { return _disposeOfStateObjects; } - set - { - ThrowIfReadOnly(); - _disposeOfStateObjects = value; + set + { + ThrowIfReadOnly(); + _disposeOfStateObjects = value; } } @@ -98,10 +98,10 @@ namespace Amib.Threading public virtual CallToPostExecute CallToPostExecute { get { return _callToPostExecute; } - set - { - ThrowIfReadOnly(); - _callToPostExecute = value; + set + { + ThrowIfReadOnly(); + _callToPostExecute = value; } } @@ -112,10 +112,10 @@ namespace Amib.Threading public virtual PostExecuteWorkItemCallback PostExecuteWorkItemCallback { get { return _postExecuteWorkItemCallback; } - set - { - ThrowIfReadOnly(); - _postExecuteWorkItemCallback = value; + set + { + ThrowIfReadOnly(); + _postExecuteWorkItemCallback = value; } } @@ -127,10 +127,10 @@ namespace Amib.Threading public virtual bool StartSuspended { get { return _startSuspended; } - set - { - ThrowIfReadOnly(); - _startSuspended = value; + set + { + ThrowIfReadOnly(); + _startSuspended = value; } } @@ -152,10 +152,10 @@ namespace Amib.Threading public virtual bool FillStateWithArgs { get { return _fillStateWithArgs; } - set - { - ThrowIfReadOnly(); - _fillStateWithArgs = value; + set + { + ThrowIfReadOnly(); + _fillStateWithArgs = value; } } diff --git a/ThirdParty/SmartThreadPool/WorkItem.cs b/ThirdParty/SmartThreadPool/WorkItem.cs index edb8ac022d..7dd32de8bb 100644 --- a/ThirdParty/SmartThreadPool/WorkItem.cs +++ b/ThirdParty/SmartThreadPool/WorkItem.cs @@ -61,12 +61,11 @@ namespace Amib.Threading.Internal /// private object _state; -#if !(_WINDOWS_CE) && !(_SILVERLIGHT) && !(WINDOWS_PHONE) /// /// Stores the caller's context /// private readonly CallerThreadContext _callerContext; -#endif + /// /// Holds the result of the mehtod /// @@ -88,7 +87,7 @@ namespace Amib.Threading.Internal private ManualResetEvent _workItemCompleted; /// - /// A reference count to the _workItemCompleted. + /// A reference count to the _workItemCompleted. /// When it reaches to zero _workItemCompleted is Closed /// private int _workItemCompletedRefCount; @@ -114,13 +113,13 @@ namespace Amib.Threading.Internal private event WorkItemStateCallback _workItemCompletedEvent; /// - /// A reference to an object that indicates whatever the + /// A reference to an object that indicates whatever the /// WorkItemsGroup has been canceled /// private CanceledWorkItemsGroup _canceledWorkItemsGroup = CanceledWorkItemsGroup.NotCanceledWorkItemsGroup; /// - /// A reference to an object that indicates whatever the + /// A reference to an object that indicates whatever the /// SmartThreadPool has been canceled /// private CanceledWorkItemsGroup _canceledSmartThreadPool = CanceledWorkItemsGroup.NotCanceledWorkItemsGroup; @@ -197,7 +196,7 @@ namespace Amib.Threading.Internal /// The WorkItemInfo of te workitem /// Callback delegate for the callback. /// State with which to call the callback delegate. - /// + /// /// We assume that the WorkItem object is created within the thread /// that meant to run the callback public WorkItem( @@ -209,12 +208,10 @@ namespace Amib.Threading.Internal _workItemsGroup = workItemsGroup; _workItemInfo = workItemInfo; -#if !(_WINDOWS_CE) && !(_SILVERLIGHT) && !(WINDOWS_PHONE) if (_workItemInfo.UseCallerCallContext || _workItemInfo.UseCallerHttpContext) { _callerContext = CallerThreadContext.Capture(_workItemInfo.UseCallerCallContext, _workItemInfo.UseCallerHttpContext); } -#endif _callback = callback; _state = state; @@ -359,15 +356,12 @@ namespace Amib.Threading.Internal /// private void ExecuteWorkItem() { - -#if !(_WINDOWS_CE) && !(_SILVERLIGHT) && !(WINDOWS_PHONE) CallerThreadContext ctc = null; if (null != _callerContext) { ctc = CallerThreadContext.Capture(_callerContext.CapturedCallContext, _callerContext.CapturedHttpContext); CallerThreadContext.Apply(_callerContext); } -#endif Exception exception = null; object result = null; @@ -402,22 +396,19 @@ namespace Amib.Threading.Internal { tae.GetHashCode(); // Check if the work item was cancelled - // If we got a ThreadAbortException and the STP is not shutting down, it means the + // If we got a ThreadAbortException and the STP is not shutting down, it means the // work items was cancelled. if (!SmartThreadPool.CurrentThreadEntry.AssociatedSmartThreadPool.IsShuttingdown) { -#if !(_WINDOWS_CE) && !(_SILVERLIGHT) && !(WINDOWS_PHONE) Thread.ResetAbort(); -#endif } } -#if !(_WINDOWS_CE) && !(_SILVERLIGHT) && !(WINDOWS_PHONE) if (null != _callerContext) { CallerThreadContext.Apply(ctc); } -#endif + if (!SmartThreadPool.IsWorkItemCanceled) { @@ -471,7 +462,7 @@ namespace Amib.Threading.Internal /// Array of work item result objects /// The number of milliseconds to wait, or Timeout.Infinite (-1) to wait indefinitely. /// - /// true to exit the synchronization domain for the context before the wait (if in a synchronized context), and reacquire it; otherwise, false. + /// true to exit the synchronization domain for the context before the wait (if in a synchronized context), and reacquire it; otherwise, false. /// /// A cancel wait handle to interrupt the wait if needed /// @@ -553,7 +544,7 @@ namespace Amib.Threading.Internal /// Array of work item result objects /// The number of milliseconds to wait, or Timeout.Infinite (-1) to wait indefinitely. /// - /// true to exit the synchronization domain for the context before the wait (if in a synchronized context), and reacquire it; otherwise, false. + /// true to exit the synchronization domain for the context before the wait (if in a synchronized context), and reacquire it; otherwise, false. /// /// A cancel wait handle to interrupt the wait if needed /// @@ -709,12 +700,6 @@ namespace Amib.Threading.Internal /// Returns true on success or false if the work item is in progress or already completed private bool Cancel(bool abortExecution) { -#if (_WINDOWS_CE) - if(abortExecution) - { - throw new ArgumentOutOfRangeException("abortExecution", "WindowsCE doesn't support this feature"); - } -#endif bool success = false; bool signalComplete = false; @@ -856,7 +841,7 @@ namespace Amib.Threading.Internal { case 0: // The work item signaled - // Note that the signal could be also as a result of canceling the + // Note that the signal could be also as a result of canceling the // work item (not the get result) break; case 1: @@ -884,7 +869,7 @@ namespace Amib.Threading.Internal } /// - /// A wait handle to wait for completion, cancel, or timeout + /// A wait handle to wait for completion, cancel, or timeout /// private WaitHandle GetWaitHandle() { @@ -892,7 +877,7 @@ namespace Amib.Threading.Internal { if (null == _workItemCompleted) { - _workItemCompleted = EventWaitHandleFactory.CreateManualResetEvent(IsCompleted); + _workItemCompleted = new ManualResetEvent(IsCompleted); } ++_workItemCompletedRefCount; } diff --git a/ThirdParty/SmartThreadPool/WorkItemFactory.cs b/ThirdParty/SmartThreadPool/WorkItemFactory.cs index 471eb20c7a..6a2e95b78b 100644 --- a/ThirdParty/SmartThreadPool/WorkItemFactory.cs +++ b/ThirdParty/SmartThreadPool/WorkItemFactory.cs @@ -2,7 +2,7 @@ using System; namespace Amib.Threading.Internal { - #region WorkItemFactory class + #region WorkItemFactory class public class WorkItemFactory { @@ -32,7 +32,7 @@ namespace Amib.Threading.Internal public static WorkItem CreateWorkItem( IWorkItemsGroup workItemsGroup, WIGStartInfo wigStartInfo, - WorkItemCallback callback, + WorkItemCallback callback, WorkItemPriority workItemPriority) { return CreateWorkItem(workItemsGroup, wigStartInfo, callback, null, workItemPriority); @@ -49,14 +49,14 @@ namespace Amib.Threading.Internal public static WorkItem CreateWorkItem( IWorkItemsGroup workItemsGroup, WIGStartInfo wigStartInfo, - WorkItemInfo workItemInfo, + WorkItemInfo workItemInfo, WorkItemCallback callback) { return CreateWorkItem( workItemsGroup, wigStartInfo, - workItemInfo, - callback, + workItemInfo, + callback, null); } @@ -67,17 +67,17 @@ namespace Amib.Threading.Internal /// Work item group start information /// A callback to execute /// - /// The context object of the work item. Used for passing arguments to the work item. + /// The context object of the work item. Used for passing arguments to the work item. /// /// Returns a work item public static WorkItem CreateWorkItem( IWorkItemsGroup workItemsGroup, WIGStartInfo wigStartInfo, - WorkItemCallback callback, + WorkItemCallback callback, object state) { ValidateCallback(callback); - + WorkItemInfo workItemInfo = new WorkItemInfo(); workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext; workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext; @@ -89,7 +89,7 @@ namespace Amib.Threading.Internal WorkItem workItem = new WorkItem( workItemsGroup, workItemInfo, - callback, + callback, state); return workItem; } @@ -101,15 +101,15 @@ namespace Amib.Threading.Internal /// Work item group start information /// A callback to execute /// - /// The context object of the work item. Used for passing arguments to the work item. + /// The context object of the work item. Used for passing arguments to the work item. /// /// The work item priority /// Returns a work item public static WorkItem CreateWorkItem( IWorkItemsGroup workItemsGroup, WIGStartInfo wigStartInfo, - WorkItemCallback callback, - object state, + WorkItemCallback callback, + object state, WorkItemPriority workItemPriority) { ValidateCallback(callback); @@ -125,7 +125,7 @@ namespace Amib.Threading.Internal WorkItem workItem = new WorkItem( workItemsGroup, workItemInfo, - callback, + callback, state); return workItem; @@ -139,7 +139,7 @@ namespace Amib.Threading.Internal /// Work item information /// A callback to execute /// - /// The context object of the work item. Used for passing arguments to the work item. + /// The context object of the work item. Used for passing arguments to the work item. /// /// Returns a work item public static WorkItem CreateWorkItem( @@ -168,7 +168,7 @@ namespace Amib.Threading.Internal /// Work item group start information /// A callback to execute /// - /// The context object of the work item. Used for passing arguments to the work item. + /// The context object of the work item. Used for passing arguments to the work item. /// /// /// A delegate to call after the callback completion @@ -177,7 +177,7 @@ namespace Amib.Threading.Internal public static WorkItem CreateWorkItem( IWorkItemsGroup workItemsGroup, WIGStartInfo wigStartInfo, - WorkItemCallback callback, + WorkItemCallback callback, object state, PostExecuteWorkItemCallback postExecuteWorkItemCallback) { @@ -195,7 +195,7 @@ namespace Amib.Threading.Internal WorkItem workItem = new WorkItem( workItemsGroup, workItemInfo, - callback, + callback, state); return workItem; @@ -208,7 +208,7 @@ namespace Amib.Threading.Internal /// Work item group start information /// A callback to execute /// - /// The context object of the work item. Used for passing arguments to the work item. + /// The context object of the work item. Used for passing arguments to the work item. /// /// /// A delegate to call after the callback completion @@ -218,7 +218,7 @@ namespace Amib.Threading.Internal public static WorkItem CreateWorkItem( IWorkItemsGroup workItemsGroup, WIGStartInfo wigStartInfo, - WorkItemCallback callback, + WorkItemCallback callback, object state, PostExecuteWorkItemCallback postExecuteWorkItemCallback, WorkItemPriority workItemPriority) @@ -237,7 +237,7 @@ namespace Amib.Threading.Internal WorkItem workItem = new WorkItem( workItemsGroup, workItemInfo, - callback, + callback, state); return workItem; @@ -250,7 +250,7 @@ namespace Amib.Threading.Internal /// Work item group start information /// A callback to execute /// - /// The context object of the work item. Used for passing arguments to the work item. + /// The context object of the work item. Used for passing arguments to the work item. /// /// /// A delegate to call after the callback completion @@ -260,7 +260,7 @@ namespace Amib.Threading.Internal public static WorkItem CreateWorkItem( IWorkItemsGroup workItemsGroup, WIGStartInfo wigStartInfo, - WorkItemCallback callback, + WorkItemCallback callback, object state, PostExecuteWorkItemCallback postExecuteWorkItemCallback, CallToPostExecute callToPostExecute) @@ -279,7 +279,7 @@ namespace Amib.Threading.Internal WorkItem workItem = new WorkItem( workItemsGroup, workItemInfo, - callback, + callback, state); return workItem; @@ -292,7 +292,7 @@ namespace Amib.Threading.Internal /// Work item group start information /// A callback to execute /// - /// The context object of the work item. Used for passing arguments to the work item. + /// The context object of the work item. Used for passing arguments to the work item. /// /// /// A delegate to call after the callback completion @@ -303,7 +303,7 @@ namespace Amib.Threading.Internal public static WorkItem CreateWorkItem( IWorkItemsGroup workItemsGroup, WIGStartInfo wigStartInfo, - WorkItemCallback callback, + WorkItemCallback callback, object state, PostExecuteWorkItemCallback postExecuteWorkItemCallback, CallToPostExecute callToPostExecute, @@ -324,9 +324,9 @@ namespace Amib.Threading.Internal WorkItem workItem = new WorkItem( workItemsGroup, workItemInfo, - callback, + callback, state); - + return workItem; } diff --git a/ThirdParty/SmartThreadPool/WorkItemsGroup.cs b/ThirdParty/SmartThreadPool/WorkItemsGroup.cs index d429bc62f5..06b5c44fa7 100644 --- a/ThirdParty/SmartThreadPool/WorkItemsGroup.cs +++ b/ThirdParty/SmartThreadPool/WorkItemsGroup.cs @@ -6,7 +6,7 @@ using System.Diagnostics; namespace Amib.Threading.Internal { - #region WorkItemsGroup class + #region WorkItemsGroup class /// /// Summary description for WorkItemsGroup. @@ -18,7 +18,7 @@ namespace Amib.Threading.Internal private readonly object _lock = new object(); /// - /// A reference to the SmartThreadPool instance that created this + /// A reference to the SmartThreadPool instance that created this /// WorkItemsGroup. /// private readonly SmartThreadPool _stp; @@ -39,7 +39,7 @@ namespace Amib.Threading.Internal private int _concurrency; /// - /// Priority queue to hold work items before they are passed + /// Priority queue to hold work items before they are passed /// to the SmartThreadPool. /// private readonly PriorityQueue _workItemsQueue; @@ -53,7 +53,7 @@ namespace Amib.Threading.Internal /// /// Indicate how many work items are currently running in the SmartThreadPool. - /// This value is used with the Cancel, to calculate if we can send new + /// This value is used with the Cancel, to calculate if we can send new /// work items to the STP. /// private int _workItemsExecutingInStp = 0; @@ -66,8 +66,7 @@ namespace Amib.Threading.Internal /// /// Signaled when all of the WorkItemsGroup's work item completed. /// - //private readonly ManualResetEvent _isIdleWaitHandle = new ManualResetEvent(true); - private readonly ManualResetEvent _isIdleWaitHandle = EventWaitHandleFactory.CreateManualResetEvent(true); + private readonly ManualResetEvent _isIdleWaitHandle = new ManualResetEvent(true); /// /// A common object for all the work items that this work items group @@ -75,23 +74,21 @@ namespace Amib.Threading.Internal /// private CanceledWorkItemsGroup _canceledWorkItemsGroup = new CanceledWorkItemsGroup(); - #endregion + #endregion #region Construction public WorkItemsGroup( - SmartThreadPool stp, - int concurrency, + SmartThreadPool stp, + int concurrency, WIGStartInfo wigStartInfo) { if (concurrency <= 0) { throw new ArgumentOutOfRangeException( "concurrency", -#if !(_WINDOWS_CE) && !(_SILVERLIGHT) && !(WINDOWS_PHONE) concurrency, -#endif - "concurrency must be greater than zero"); + "concurrency must be greater than zero"); } _stp = stp; _concurrency = concurrency; @@ -106,7 +103,7 @@ namespace Amib.Threading.Internal _isSuspended = _workItemsGroupStartInfo.StartSuspended; } - #endregion + #endregion #region WorkItemsGroupBase Overrides @@ -165,7 +162,7 @@ namespace Amib.Threading.Internal return; } _isSuspended = false; - + EnqueueToSTPNextNWorkItem(Math.Min(_workItemsQueue.Count, _concurrency)); } @@ -200,7 +197,7 @@ namespace Amib.Threading.Internal remove { _onIdle -= value; } } - #endregion + #endregion #region Private methods @@ -217,7 +214,7 @@ namespace Amib.Threading.Internal { return; } - + EnqueueToSTPNextNWorkItem(_concurrency); } @@ -308,7 +305,7 @@ namespace Amib.Threading.Internal _workItemsQueue.Enqueue(workItem); //_stp.IncrementWorkItemsCount(); - if ((1 == _workItemsQueue.Count) && + if ((1 == _workItemsQueue.Count) && (0 == _workItemsInStpQueue)) { _stp.RegisterWorkItemsGroup(this); diff --git a/ThirdParty/SmartThreadPool/WorkItemsGroupBase.cs b/ThirdParty/SmartThreadPool/WorkItemsGroupBase.cs index 3a5dcc681e..27fae5e813 100644 --- a/ThirdParty/SmartThreadPool/WorkItemsGroupBase.cs +++ b/ThirdParty/SmartThreadPool/WorkItemsGroupBase.cs @@ -132,7 +132,7 @@ namespace Amib.Threading.Internal /// /// A callback to execute /// - /// The context object of the work item. Used for passing arguments to the work item. + /// The context object of the work item. Used for passing arguments to the work item. /// /// Returns a work item result public IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state) @@ -147,7 +147,7 @@ namespace Amib.Threading.Internal /// /// A callback to execute /// - /// The context object of the work item. Used for passing arguments to the work item. + /// The context object of the work item. Used for passing arguments to the work item. /// /// The work item priority /// Returns a work item result @@ -165,7 +165,7 @@ namespace Amib.Threading.Internal /// Work item information /// A callback to execute /// - /// The context object of the work item. Used for passing arguments to the work item. + /// The context object of the work item. Used for passing arguments to the work item. /// /// Returns a work item result public IWorkItemResult QueueWorkItem(WorkItemInfo workItemInfo, WorkItemCallback callback, object state) @@ -181,7 +181,7 @@ namespace Amib.Threading.Internal /// /// A callback to execute /// - /// The context object of the work item. Used for passing arguments to the work item. + /// The context object of the work item. Used for passing arguments to the work item. /// /// /// A delegate to call after the callback completion @@ -203,7 +203,7 @@ namespace Amib.Threading.Internal /// /// A callback to execute /// - /// The context object of the work item. Used for passing arguments to the work item. + /// The context object of the work item. Used for passing arguments to the work item. /// /// /// A delegate to call after the callback completion @@ -227,7 +227,7 @@ namespace Amib.Threading.Internal /// /// A callback to execute /// - /// The context object of the work item. Used for passing arguments to the work item. + /// The context object of the work item. Used for passing arguments to the work item. /// /// /// A delegate to call after the callback completion @@ -251,7 +251,7 @@ namespace Amib.Threading.Internal /// /// A callback to execute /// - /// The context object of the work item. Used for passing arguments to the work item. + /// The context object of the work item. Used for passing arguments to the work item. /// /// /// A delegate to call after the callback completion diff --git a/ThirdParty/SmartThreadPool/WorkItemsQueue.cs b/ThirdParty/SmartThreadPool/WorkItemsQueue.cs index d3c191bf35..6a6e039241 100644 --- a/ThirdParty/SmartThreadPool/WorkItemsQueue.cs +++ b/ThirdParty/SmartThreadPool/WorkItemsQueue.cs @@ -33,16 +33,8 @@ namespace Amib.Threading.Internal /// private bool _isWorkItemsQueueActive = true; - -#if (WINDOWS_PHONE) - private static readonly Dictionary _waiterEntries = new Dictionary(); -#elif (_WINDOWS_CE) - private static LocalDataStoreSlot _waiterEntrySlot = Thread.AllocateDataSlot(); -#else - [ThreadStatic] private static WaiterEntry _waiterEntry; -#endif /// @@ -50,36 +42,6 @@ namespace Amib.Threading.Internal /// private static WaiterEntry CurrentWaiterEntry { -#if (WINDOWS_PHONE) - get - { - lock (_waiterEntries) - { - WaiterEntry waiterEntry; - if (_waiterEntries.TryGetValue(Thread.CurrentThread.ManagedThreadId, out waiterEntry)) - { - return waiterEntry; - } - } - return null; - } - set - { - lock (_waiterEntries) - { - _waiterEntries[Thread.CurrentThread.ManagedThreadId] = value; - } - } -#elif (_WINDOWS_CE) - get - { - return Thread.GetData(_waiterEntrySlot) as WaiterEntry; - } - set - { - Thread.SetData(_waiterEntrySlot, value); - } -#else get { return _waiterEntry; @@ -88,12 +50,11 @@ namespace Amib.Threading.Internal { _waiterEntry = value; } -#endif } /// - /// A flag that indicates if the WorkItemsQueue has been disposed. - /// + /// A flag that indicates if the WorkItemsQueue has been disposed. + /// private bool _isDisposed = false; #endregion @@ -481,7 +442,7 @@ namespace Amib.Threading.Internal /// Event to signal the waiter that it got the work item. /// //private AutoResetEvent _waitHandle = new AutoResetEvent(false); - private AutoResetEvent _waitHandle = EventWaitHandleFactory.CreateAutoResetEvent(); + private AutoResetEvent _waitHandle = new AutoResetEvent(false); /// /// Flag to know if this waiter already quited from the queue @@ -498,7 +459,7 @@ namespace Amib.Threading.Internal /// A work item that passed directly to the waiter withou going /// through the queue /// - private WorkItem _workItem = null; + private WorkItem _workItem = null; private bool _isDisposed = false;