Merge branch 'master' into bulletsim4

user_profiles
Robert Adams 2013-05-02 07:02:28 -07:00
commit a9480aed85
27 changed files with 6369 additions and 6362 deletions

View File

@ -646,11 +646,12 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
} }
else else
{ {
if (remoteClient == null || so.OwnerID != remoteClient.AgentId) if (remoteClient == null || so.RootPart.OwnerID != remoteClient.AgentId)
{ {
// Taking copy of another person's item. Take to // Taking copy of another person's item. Take to
// Objects folder. // Objects folder.
folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.Object); folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.Object);
so.FromFolderID = UUID.Zero;
} }
else else
{ {
@ -666,10 +667,16 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
// //
if (action == DeRezAction.Take || action == DeRezAction.TakeCopy) if (action == DeRezAction.Take || action == DeRezAction.TakeCopy)
{ {
if (so.FromFolderID != UUID.Zero && userID == remoteClient.AgentId) if (so.FromFolderID != UUID.Zero && so.RootPart.OwnerID == remoteClient.AgentId)
{ {
InventoryFolderBase f = new InventoryFolderBase(so.FromFolderID, userID); InventoryFolderBase f = new InventoryFolderBase(so.FromFolderID, userID);
folder = m_Scene.InventoryService.GetFolder(f); folder = m_Scene.InventoryService.GetFolder(f);
if(folder.Type == 14 || folder.Type == 16)
{
// folder.Type = 6;
folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.Object);
}
} }
} }

View File

@ -1,138 +1,138 @@
#if !(_WINDOWS_CE) && !(_SILVERLIGHT) && !(WINDOWS_PHONE) #if !(_WINDOWS_CE) && !(_SILVERLIGHT) && !(WINDOWS_PHONE)
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Threading; using System.Threading;
using System.Reflection; using System.Reflection;
using System.Web; using System.Web;
using System.Runtime.Remoting.Messaging; using System.Runtime.Remoting.Messaging;
namespace Amib.Threading.Internal namespace Amib.Threading.Internal
{ {
#region CallerThreadContext class #region CallerThreadContext class
/// <summary> /// <summary>
/// This class stores the caller call context in order to restore /// 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.
/// </summary> /// </summary>
internal class CallerThreadContext internal class CallerThreadContext
{ {
#region Prepare reflection information #region Prepare reflection information
// Cached type information. // Cached type information.
private static readonly MethodInfo getLogicalCallContextMethodInfo = private static readonly MethodInfo getLogicalCallContextMethodInfo =
typeof(Thread).GetMethod("GetLogicalCallContext", BindingFlags.Instance | BindingFlags.NonPublic); typeof(Thread).GetMethod("GetLogicalCallContext", BindingFlags.Instance | BindingFlags.NonPublic);
private static readonly MethodInfo setLogicalCallContextMethodInfo = private static readonly MethodInfo setLogicalCallContextMethodInfo =
typeof(Thread).GetMethod("SetLogicalCallContext", BindingFlags.Instance | BindingFlags.NonPublic); typeof(Thread).GetMethod("SetLogicalCallContext", BindingFlags.Instance | BindingFlags.NonPublic);
private static string HttpContextSlotName = GetHttpContextSlotName(); private static string HttpContextSlotName = GetHttpContextSlotName();
private static string GetHttpContextSlotName() private static string GetHttpContextSlotName()
{ {
FieldInfo fi = typeof(HttpContext).GetField("CallContextSlotName", BindingFlags.Static | BindingFlags.NonPublic); FieldInfo fi = typeof(HttpContext).GetField("CallContextSlotName", BindingFlags.Static | BindingFlags.NonPublic);
if (fi != null) if (fi != null)
{ {
return (string) fi.GetValue(null); return (string) fi.GetValue(null);
} }
return "HttpContext"; return "HttpContext";
} }
#endregion #endregion
#region Private fields #region Private fields
private HttpContext _httpContext; private HttpContext _httpContext;
private LogicalCallContext _callContext; private LogicalCallContext _callContext;
#endregion #endregion
/// <summary> /// <summary>
/// Constructor /// Constructor
/// </summary> /// </summary>
private CallerThreadContext() private CallerThreadContext()
{ {
} }
public bool CapturedCallContext public bool CapturedCallContext
{ {
get get
{ {
return (null != _callContext); return (null != _callContext);
} }
} }
public bool CapturedHttpContext public bool CapturedHttpContext
{ {
get get
{ {
return (null != _httpContext); return (null != _httpContext);
} }
} }
/// <summary> /// <summary>
/// Captures the current thread context /// Captures the current thread context
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public static CallerThreadContext Capture( public static CallerThreadContext Capture(
bool captureCallContext, bool captureCallContext,
bool captureHttpContext) bool captureHttpContext)
{ {
Debug.Assert(captureCallContext || captureHttpContext); Debug.Assert(captureCallContext || captureHttpContext);
CallerThreadContext callerThreadContext = new CallerThreadContext(); CallerThreadContext callerThreadContext = new CallerThreadContext();
// TODO: In NET 2.0, redo using the new feature of ExecutionContext class - Capture() // TODO: In NET 2.0, redo using the new feature of ExecutionContext class - Capture()
// Capture Call Context // Capture Call Context
if(captureCallContext && (getLogicalCallContextMethodInfo != null)) if(captureCallContext && (getLogicalCallContextMethodInfo != null))
{ {
callerThreadContext._callContext = (LogicalCallContext)getLogicalCallContextMethodInfo.Invoke(Thread.CurrentThread, null); callerThreadContext._callContext = (LogicalCallContext)getLogicalCallContextMethodInfo.Invoke(Thread.CurrentThread, null);
if (callerThreadContext._callContext != null) if (callerThreadContext._callContext != null)
{ {
callerThreadContext._callContext = (LogicalCallContext)callerThreadContext._callContext.Clone(); callerThreadContext._callContext = (LogicalCallContext)callerThreadContext._callContext.Clone();
} }
} }
// Capture httpContext // Capture httpContext
if (captureHttpContext && (null != HttpContext.Current)) if (captureHttpContext && (null != HttpContext.Current))
{ {
callerThreadContext._httpContext = HttpContext.Current; callerThreadContext._httpContext = HttpContext.Current;
} }
return callerThreadContext; return callerThreadContext;
} }
/// <summary> /// <summary>
/// Applies the thread context stored earlier /// Applies the thread context stored earlier
/// </summary> /// </summary>
/// <param name="callerThreadContext"></param> /// <param name="callerThreadContext"></param>
public static void Apply(CallerThreadContext callerThreadContext) public static void Apply(CallerThreadContext callerThreadContext)
{ {
if (null == callerThreadContext) if (null == callerThreadContext)
{ {
throw new ArgumentNullException("callerThreadContext"); throw new ArgumentNullException("callerThreadContext");
} }
// Todo: In NET 2.0, redo using the new feature of ExecutionContext class - Run() // Todo: In NET 2.0, redo using the new feature of ExecutionContext class - Run()
// Restore call context // Restore call context
if ((callerThreadContext._callContext != null) && (setLogicalCallContextMethodInfo != null)) if ((callerThreadContext._callContext != null) && (setLogicalCallContextMethodInfo != null))
{ {
setLogicalCallContextMethodInfo.Invoke(Thread.CurrentThread, new object[] { callerThreadContext._callContext }); setLogicalCallContextMethodInfo.Invoke(Thread.CurrentThread, new object[] { callerThreadContext._callContext });
} }
// Restore HttpContext // Restore HttpContext
if (callerThreadContext._httpContext != null) if (callerThreadContext._httpContext != null)
{ {
HttpContext.Current = callerThreadContext._httpContext; HttpContext.Current = callerThreadContext._httpContext;
//CallContext.SetData(HttpContextSlotName, callerThreadContext._httpContext); //CallContext.SetData(HttpContextSlotName, callerThreadContext._httpContext);
} }
} }
} }
#endregion #endregion
} }
#endif #endif

View File

@ -1,14 +1,14 @@
namespace Amib.Threading.Internal namespace Amib.Threading.Internal
{ {
internal class CanceledWorkItemsGroup internal class CanceledWorkItemsGroup
{ {
public readonly static CanceledWorkItemsGroup NotCanceledWorkItemsGroup = new CanceledWorkItemsGroup(); public readonly static CanceledWorkItemsGroup NotCanceledWorkItemsGroup = new CanceledWorkItemsGroup();
public CanceledWorkItemsGroup() public CanceledWorkItemsGroup()
{ {
IsCanceled = false; IsCanceled = false;
} }
public bool IsCanceled { get; set; } public bool IsCanceled { get; set; }
} }
} }

View File

@ -1,104 +1,104 @@
#if (_WINDOWS_CE) #if (_WINDOWS_CE)
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
namespace Amib.Threading.Internal namespace Amib.Threading.Internal
{ {
/// <summary> /// <summary>
/// EventWaitHandle class /// EventWaitHandle class
/// In WindowsCE this class doesn't exist and I needed the WaitAll and WaitAny implementation. /// 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. /// 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. /// It uses the WaitForMultipleObjects API to do the WaitAll and WaitAny.
/// Note that this class doesn't even inherit from WaitHandle! /// Note that this class doesn't even inherit from WaitHandle!
/// </summary> /// </summary>
public class STPEventWaitHandle public class STPEventWaitHandle
{ {
#region Public Constants #region Public Constants
public const int WaitTimeout = Timeout.Infinite; public const int WaitTimeout = Timeout.Infinite;
#endregion #endregion
#region Private External Constants #region Private External Constants
private const Int32 WAIT_FAILED = -1; private const Int32 WAIT_FAILED = -1;
private const Int32 WAIT_TIMEOUT = 0x102; private const Int32 WAIT_TIMEOUT = 0x102;
private const UInt32 INFINITE = 0xFFFFFFFF; private const UInt32 INFINITE = 0xFFFFFFFF;
#endregion #endregion
#region WaitAll and WaitAny #region WaitAll and WaitAny
internal static bool WaitOne(WaitHandle waitHandle, int millisecondsTimeout, bool exitContext) internal static bool WaitOne(WaitHandle waitHandle, int millisecondsTimeout, bool exitContext)
{ {
return waitHandle.WaitOne(millisecondsTimeout, exitContext); return waitHandle.WaitOne(millisecondsTimeout, exitContext);
} }
private static IntPtr[] PrepareNativeHandles(WaitHandle[] waitHandles) private static IntPtr[] PrepareNativeHandles(WaitHandle[] waitHandles)
{ {
IntPtr[] nativeHandles = new IntPtr[waitHandles.Length]; IntPtr[] nativeHandles = new IntPtr[waitHandles.Length];
for (int i = 0; i < waitHandles.Length; i++) for (int i = 0; i < waitHandles.Length; i++)
{ {
nativeHandles[i] = waitHandles[i].Handle; nativeHandles[i] = waitHandles[i].Handle;
} }
return nativeHandles; return nativeHandles;
} }
public static bool WaitAll(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) public static bool WaitAll(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext)
{ {
uint timeout = millisecondsTimeout < 0 ? INFINITE : (uint)millisecondsTimeout; uint timeout = millisecondsTimeout < 0 ? INFINITE : (uint)millisecondsTimeout;
IntPtr[] nativeHandles = PrepareNativeHandles(waitHandles); IntPtr[] nativeHandles = PrepareNativeHandles(waitHandles);
int result = WaitForMultipleObjects((uint)waitHandles.Length, nativeHandles, true, timeout); int result = WaitForMultipleObjects((uint)waitHandles.Length, nativeHandles, true, timeout);
if (result == WAIT_TIMEOUT || result == WAIT_FAILED) if (result == WAIT_TIMEOUT || result == WAIT_FAILED)
{ {
return false; return false;
} }
return true; return true;
} }
public static int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) public static int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext)
{ {
uint timeout = millisecondsTimeout < 0 ? INFINITE : (uint)millisecondsTimeout; uint timeout = millisecondsTimeout < 0 ? INFINITE : (uint)millisecondsTimeout;
IntPtr[] nativeHandles = PrepareNativeHandles(waitHandles); IntPtr[] nativeHandles = PrepareNativeHandles(waitHandles);
int result = WaitForMultipleObjects((uint)waitHandles.Length, nativeHandles, false, timeout); int result = WaitForMultipleObjects((uint)waitHandles.Length, nativeHandles, false, timeout);
if (result >= 0 && result < waitHandles.Length) if (result >= 0 && result < waitHandles.Length)
{ {
return result; return result;
} }
return -1; return -1;
} }
public static int WaitAny(WaitHandle[] waitHandles) public static int WaitAny(WaitHandle[] waitHandles)
{ {
return WaitAny(waitHandles, Timeout.Infinite, false); return WaitAny(waitHandles, Timeout.Infinite, false);
} }
public static int WaitAny(WaitHandle[] waitHandles, TimeSpan timeout, bool exitContext) public static int WaitAny(WaitHandle[] waitHandles, TimeSpan timeout, bool exitContext)
{ {
int millisecondsTimeout = (int)timeout.TotalMilliseconds; int millisecondsTimeout = (int)timeout.TotalMilliseconds;
return WaitAny(waitHandles, millisecondsTimeout, false); return WaitAny(waitHandles, millisecondsTimeout, false);
} }
#endregion #endregion
#region External methods #region External methods
[DllImport("coredll.dll", SetLastError = true)] [DllImport("coredll.dll", SetLastError = true)]
public static extern int WaitForMultipleObjects(uint nCount, IntPtr[] lpHandles, bool fWaitAll, uint dwMilliseconds); public static extern int WaitForMultipleObjects(uint nCount, IntPtr[] lpHandles, bool fWaitAll, uint dwMilliseconds);
#endregion #endregion
} }
} }
#endif #endif

View File

@ -1,82 +1,82 @@
using System.Threading; using System.Threading;
#if (_WINDOWS_CE) #if (_WINDOWS_CE)
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
#endif #endif
namespace Amib.Threading.Internal namespace Amib.Threading.Internal
{ {
/// <summary> /// <summary>
/// EventWaitHandleFactory class. /// EventWaitHandleFactory class.
/// This is a static class that creates AutoResetEvent and ManualResetEvent objects. /// This is a static class that creates AutoResetEvent and ManualResetEvent objects.
/// In WindowCE the WaitForMultipleObjects API fails to use the Handle property /// 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. /// 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 /// Consequently this class creates the needed XxxResetEvent and replaces the handle if
/// it's a WindowsCE OS. /// it's a WindowsCE OS.
/// </summary> /// </summary>
public static class EventWaitHandleFactory public static class EventWaitHandleFactory
{ {
/// <summary> /// <summary>
/// Create a new AutoResetEvent object /// Create a new AutoResetEvent object
/// </summary> /// </summary>
/// <returns>Return a new AutoResetEvent object</returns> /// <returns>Return a new AutoResetEvent object</returns>
public static AutoResetEvent CreateAutoResetEvent() public static AutoResetEvent CreateAutoResetEvent()
{ {
AutoResetEvent waitHandle = new AutoResetEvent(false); AutoResetEvent waitHandle = new AutoResetEvent(false);
#if (_WINDOWS_CE) #if (_WINDOWS_CE)
ReplaceEventHandle(waitHandle, false, false); ReplaceEventHandle(waitHandle, false, false);
#endif #endif
return waitHandle; return waitHandle;
} }
/// <summary> /// <summary>
/// Create a new ManualResetEvent object /// Create a new ManualResetEvent object
/// </summary> /// </summary>
/// <returns>Return a new ManualResetEvent object</returns> /// <returns>Return a new ManualResetEvent object</returns>
public static ManualResetEvent CreateManualResetEvent(bool initialState) public static ManualResetEvent CreateManualResetEvent(bool initialState)
{ {
ManualResetEvent waitHandle = new ManualResetEvent(initialState); ManualResetEvent waitHandle = new ManualResetEvent(initialState);
#if (_WINDOWS_CE) #if (_WINDOWS_CE)
ReplaceEventHandle(waitHandle, true, initialState); ReplaceEventHandle(waitHandle, true, initialState);
#endif #endif
return waitHandle; return waitHandle;
} }
#if (_WINDOWS_CE) #if (_WINDOWS_CE)
/// <summary> /// <summary>
/// Replace the event handle /// Replace the event handle
/// </summary> /// </summary>
/// <param name="waitHandle">The WaitHandle object which its handle needs to be replaced.</param> /// <param name="waitHandle">The WaitHandle object which its handle needs to be replaced.</param>
/// <param name="manualReset">Indicates if the event is a ManualResetEvent (true) or an AutoResetEvent (false)</param> /// <param name="manualReset">Indicates if the event is a ManualResetEvent (true) or an AutoResetEvent (false)</param>
/// <param name="initialState">The initial state of the event</param> /// <param name="initialState">The initial state of the event</param>
private static void ReplaceEventHandle(WaitHandle waitHandle, bool manualReset, bool initialState) private static void ReplaceEventHandle(WaitHandle waitHandle, bool manualReset, bool initialState)
{ {
// Store the old handle // Store the old handle
IntPtr oldHandle = waitHandle.Handle; IntPtr oldHandle = waitHandle.Handle;
// Create a new event // Create a new event
IntPtr newHandle = CreateEvent(IntPtr.Zero, manualReset, initialState, null); IntPtr newHandle = CreateEvent(IntPtr.Zero, manualReset, initialState, null);
// Replace the old event with the new event // Replace the old event with the new event
waitHandle.Handle = newHandle; waitHandle.Handle = newHandle;
// Close the old event // Close the old event
CloseHandle (oldHandle); CloseHandle (oldHandle);
} }
[DllImport("coredll.dll", SetLastError = true)] [DllImport("coredll.dll", SetLastError = true)]
public static extern IntPtr CreateEvent(IntPtr lpEventAttributes, bool bManualReset, bool bInitialState, string lpName); public static extern IntPtr CreateEvent(IntPtr lpEventAttributes, bool bManualReset, bool bInitialState, string lpName);
//Handle //Handle
[DllImport("coredll.dll", SetLastError = true)] [DllImport("coredll.dll", SetLastError = true)]
public static extern bool CloseHandle(IntPtr hObject); public static extern bool CloseHandle(IntPtr hObject);
#endif #endif
} }
} }

View File

@ -1,111 +1,111 @@
using System; using System;
#if !(_WINDOWS_CE) #if !(_WINDOWS_CE)
using System.Runtime.Serialization; using System.Runtime.Serialization;
#endif #endif
namespace Amib.Threading namespace Amib.Threading
{ {
#region Exceptions #region Exceptions
/// <summary> /// <summary>
/// Represents an exception in case IWorkItemResult.GetResult has been canceled /// Represents an exception in case IWorkItemResult.GetResult has been canceled
/// </summary> /// </summary>
public sealed partial class WorkItemCancelException : Exception public sealed partial class WorkItemCancelException : Exception
{ {
public WorkItemCancelException() public WorkItemCancelException()
{ {
} }
public WorkItemCancelException(string message) public WorkItemCancelException(string message)
: base(message) : base(message)
{ {
} }
public WorkItemCancelException(string message, Exception e) public WorkItemCancelException(string message, Exception e)
: base(message, e) : base(message, e)
{ {
} }
} }
/// <summary> /// <summary>
/// Represents an exception in case IWorkItemResult.GetResult has been timed out /// Represents an exception in case IWorkItemResult.GetResult has been timed out
/// </summary> /// </summary>
public sealed partial class WorkItemTimeoutException : Exception public sealed partial class WorkItemTimeoutException : Exception
{ {
public WorkItemTimeoutException() public WorkItemTimeoutException()
{ {
} }
public WorkItemTimeoutException(string message) public WorkItemTimeoutException(string message)
: base(message) : base(message)
{ {
} }
public WorkItemTimeoutException(string message, Exception e) public WorkItemTimeoutException(string message, Exception e)
: base(message, e) : base(message, e)
{ {
} }
} }
/// <summary> /// <summary>
/// Represents an exception in case IWorkItemResult.GetResult has been timed out /// Represents an exception in case IWorkItemResult.GetResult has been timed out
/// </summary> /// </summary>
public sealed partial class WorkItemResultException : Exception public sealed partial class WorkItemResultException : Exception
{ {
public WorkItemResultException() public WorkItemResultException()
{ {
} }
public WorkItemResultException(string message) public WorkItemResultException(string message)
: base(message) : base(message)
{ {
} }
public WorkItemResultException(string message, Exception e) public WorkItemResultException(string message, Exception e)
: base(message, e) : base(message, e)
{ {
} }
} }
#if !(_WINDOWS_CE) && !(_SILVERLIGHT) && !(WINDOWS_PHONE) #if !(_WINDOWS_CE) && !(_SILVERLIGHT) && !(WINDOWS_PHONE)
/// <summary> /// <summary>
/// Represents an exception in case IWorkItemResult.GetResult has been canceled /// Represents an exception in case IWorkItemResult.GetResult has been canceled
/// </summary> /// </summary>
[Serializable] [Serializable]
public sealed partial class WorkItemCancelException public sealed partial class WorkItemCancelException
{ {
public WorkItemCancelException(SerializationInfo si, StreamingContext sc) public WorkItemCancelException(SerializationInfo si, StreamingContext sc)
: base(si, sc) : base(si, sc)
{ {
} }
} }
/// <summary> /// <summary>
/// Represents an exception in case IWorkItemResult.GetResult has been timed out /// Represents an exception in case IWorkItemResult.GetResult has been timed out
/// </summary> /// </summary>
[Serializable] [Serializable]
public sealed partial class WorkItemTimeoutException public sealed partial class WorkItemTimeoutException
{ {
public WorkItemTimeoutException(SerializationInfo si, StreamingContext sc) public WorkItemTimeoutException(SerializationInfo si, StreamingContext sc)
: base(si, sc) : base(si, sc)
{ {
} }
} }
/// <summary> /// <summary>
/// Represents an exception in case IWorkItemResult.GetResult has been timed out /// Represents an exception in case IWorkItemResult.GetResult has been timed out
/// </summary> /// </summary>
[Serializable] [Serializable]
public sealed partial class WorkItemResultException public sealed partial class WorkItemResultException
{ {
public WorkItemResultException(SerializationInfo si, StreamingContext sc) public WorkItemResultException(SerializationInfo si, StreamingContext sc)
: base(si, sc) : base(si, sc)
{ {
} }
} }
#endif #endif
#endregion #endregion
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,27 +1,27 @@

namespace Amib.Threading.Internal namespace Amib.Threading.Internal
{ {
/// <summary> /// <summary>
/// An internal delegate to call when the WorkItem starts or completes /// An internal delegate to call when the WorkItem starts or completes
/// </summary> /// </summary>
internal delegate void WorkItemStateCallback(WorkItem workItem); internal delegate void WorkItemStateCallback(WorkItem workItem);
internal interface IInternalWorkItemResult internal interface IInternalWorkItemResult
{ {
event WorkItemStateCallback OnWorkItemStarted; event WorkItemStateCallback OnWorkItemStarted;
event WorkItemStateCallback OnWorkItemCompleted; event WorkItemStateCallback OnWorkItemCompleted;
} }
internal interface IInternalWaitableResult internal interface IInternalWaitableResult
{ {
/// <summary> /// <summary>
/// This method is intent for internal use. /// This method is intent for internal use.
/// </summary> /// </summary>
IWorkItemResult GetWorkItemResult(); IWorkItemResult GetWorkItemResult();
} }
public interface IHasWorkItemPriority public interface IHasWorkItemPriority
{ {
WorkItemPriority WorkItemPriority { get; } WorkItemPriority WorkItemPriority { get; }
} }
} }

View File

@ -1,239 +1,239 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
namespace Amib.Threading.Internal namespace Amib.Threading.Internal
{ {
#region PriorityQueue class #region PriorityQueue class
/// <summary> /// <summary>
/// PriorityQueue class /// PriorityQueue class
/// This class is not thread safe because we use external lock /// This class is not thread safe because we use external lock
/// </summary> /// </summary>
public sealed class PriorityQueue : IEnumerable public sealed class PriorityQueue : IEnumerable
{ {
#region Private members #region Private members
/// <summary> /// <summary>
/// The number of queues, there is one for each type of priority /// The number of queues, there is one for each type of priority
/// </summary> /// </summary>
private const int _queuesCount = WorkItemPriority.Highest-WorkItemPriority.Lowest+1; private const int _queuesCount = WorkItemPriority.Highest-WorkItemPriority.Lowest+1;
/// <summary> /// <summary>
/// Work items queues. There is one for each type of priority /// Work items queues. There is one for each type of priority
/// </summary> /// </summary>
private readonly LinkedList<IHasWorkItemPriority>[] _queues = new LinkedList<IHasWorkItemPriority>[_queuesCount]; private readonly LinkedList<IHasWorkItemPriority>[] _queues = new LinkedList<IHasWorkItemPriority>[_queuesCount];
/// <summary> /// <summary>
/// The total number of work items within the queues /// The total number of work items within the queues
/// </summary> /// </summary>
private int _workItemsCount; private int _workItemsCount;
/// <summary> /// <summary>
/// Use with IEnumerable interface /// Use with IEnumerable interface
/// </summary> /// </summary>
private int _version; private int _version;
#endregion #endregion
#region Contructor #region Contructor
public PriorityQueue() public PriorityQueue()
{ {
for(int i = 0; i < _queues.Length; ++i) for(int i = 0; i < _queues.Length; ++i)
{ {
_queues[i] = new LinkedList<IHasWorkItemPriority>(); _queues[i] = new LinkedList<IHasWorkItemPriority>();
} }
} }
#endregion #endregion
#region Methods #region Methods
/// <summary> /// <summary>
/// Enqueue a work item. /// Enqueue a work item.
/// </summary> /// </summary>
/// <param name="workItem">A work item</param> /// <param name="workItem">A work item</param>
public void Enqueue(IHasWorkItemPriority workItem) public void Enqueue(IHasWorkItemPriority workItem)
{ {
Debug.Assert(null != workItem); Debug.Assert(null != workItem);
int queueIndex = _queuesCount-(int)workItem.WorkItemPriority-1; int queueIndex = _queuesCount-(int)workItem.WorkItemPriority-1;
Debug.Assert(queueIndex >= 0); Debug.Assert(queueIndex >= 0);
Debug.Assert(queueIndex < _queuesCount); Debug.Assert(queueIndex < _queuesCount);
_queues[queueIndex].AddLast(workItem); _queues[queueIndex].AddLast(workItem);
++_workItemsCount; ++_workItemsCount;
++_version; ++_version;
} }
/// <summary> /// <summary>
/// Dequeque a work item. /// Dequeque a work item.
/// </summary> /// </summary>
/// <returns>Returns the next work item</returns> /// <returns>Returns the next work item</returns>
public IHasWorkItemPriority Dequeue() public IHasWorkItemPriority Dequeue()
{ {
IHasWorkItemPriority workItem = null; IHasWorkItemPriority workItem = null;
if(_workItemsCount > 0) if(_workItemsCount > 0)
{ {
int queueIndex = GetNextNonEmptyQueue(-1); int queueIndex = GetNextNonEmptyQueue(-1);
Debug.Assert(queueIndex >= 0); Debug.Assert(queueIndex >= 0);
workItem = _queues[queueIndex].First.Value; workItem = _queues[queueIndex].First.Value;
_queues[queueIndex].RemoveFirst(); _queues[queueIndex].RemoveFirst();
Debug.Assert(null != workItem); Debug.Assert(null != workItem);
--_workItemsCount; --_workItemsCount;
++_version; ++_version;
} }
return workItem; return workItem;
} }
/// <summary> /// <summary>
/// Find the next non empty queue starting at queue queueIndex+1 /// Find the next non empty queue starting at queue queueIndex+1
/// </summary> /// </summary>
/// <param name="queueIndex">The index-1 to start from</param> /// <param name="queueIndex">The index-1 to start from</param>
/// <returns> /// <returns>
/// The index of the next non empty queue or -1 if all the queues are empty /// The index of the next non empty queue or -1 if all the queues are empty
/// </returns> /// </returns>
private int GetNextNonEmptyQueue(int queueIndex) private int GetNextNonEmptyQueue(int queueIndex)
{ {
for(int i = queueIndex+1; i < _queuesCount; ++i) for(int i = queueIndex+1; i < _queuesCount; ++i)
{ {
if(_queues[i].Count > 0) if(_queues[i].Count > 0)
{ {
return i; return i;
} }
} }
return -1; return -1;
} }
/// <summary> /// <summary>
/// The number of work items /// The number of work items
/// </summary> /// </summary>
public int Count public int Count
{ {
get get
{ {
return _workItemsCount; return _workItemsCount;
} }
} }
/// <summary> /// <summary>
/// Clear all the work items /// Clear all the work items
/// </summary> /// </summary>
public void Clear() public void Clear()
{ {
if (_workItemsCount > 0) if (_workItemsCount > 0)
{ {
foreach(LinkedList<IHasWorkItemPriority> queue in _queues) foreach(LinkedList<IHasWorkItemPriority> queue in _queues)
{ {
queue.Clear(); queue.Clear();
} }
_workItemsCount = 0; _workItemsCount = 0;
++_version; ++_version;
} }
} }
#endregion #endregion
#region IEnumerable Members #region IEnumerable Members
/// <summary> /// <summary>
/// Returns an enumerator to iterate over the work items /// Returns an enumerator to iterate over the work items
/// </summary> /// </summary>
/// <returns>Returns an enumerator</returns> /// <returns>Returns an enumerator</returns>
public IEnumerator GetEnumerator() public IEnumerator GetEnumerator()
{ {
return new PriorityQueueEnumerator(this); return new PriorityQueueEnumerator(this);
} }
#endregion #endregion
#region PriorityQueueEnumerator #region PriorityQueueEnumerator
/// <summary> /// <summary>
/// The class the implements the enumerator /// The class the implements the enumerator
/// </summary> /// </summary>
private class PriorityQueueEnumerator : IEnumerator private class PriorityQueueEnumerator : IEnumerator
{ {
private readonly PriorityQueue _priorityQueue; private readonly PriorityQueue _priorityQueue;
private int _version; private int _version;
private int _queueIndex; private int _queueIndex;
private IEnumerator _enumerator; private IEnumerator _enumerator;
public PriorityQueueEnumerator(PriorityQueue priorityQueue) public PriorityQueueEnumerator(PriorityQueue priorityQueue)
{ {
_priorityQueue = priorityQueue; _priorityQueue = priorityQueue;
_version = _priorityQueue._version; _version = _priorityQueue._version;
_queueIndex = _priorityQueue.GetNextNonEmptyQueue(-1); _queueIndex = _priorityQueue.GetNextNonEmptyQueue(-1);
if (_queueIndex >= 0) if (_queueIndex >= 0)
{ {
_enumerator = _priorityQueue._queues[_queueIndex].GetEnumerator(); _enumerator = _priorityQueue._queues[_queueIndex].GetEnumerator();
} }
else else
{ {
_enumerator = null; _enumerator = null;
} }
} }
#region IEnumerator Members #region IEnumerator Members
public void Reset() public void Reset()
{ {
_version = _priorityQueue._version; _version = _priorityQueue._version;
_queueIndex = _priorityQueue.GetNextNonEmptyQueue(-1); _queueIndex = _priorityQueue.GetNextNonEmptyQueue(-1);
if (_queueIndex >= 0) if (_queueIndex >= 0)
{ {
_enumerator = _priorityQueue._queues[_queueIndex].GetEnumerator(); _enumerator = _priorityQueue._queues[_queueIndex].GetEnumerator();
} }
else else
{ {
_enumerator = null; _enumerator = null;
} }
} }
public object Current public object Current
{ {
get get
{ {
Debug.Assert(null != _enumerator); Debug.Assert(null != _enumerator);
return _enumerator.Current; return _enumerator.Current;
} }
} }
public bool MoveNext() public bool MoveNext()
{ {
if (null == _enumerator) if (null == _enumerator)
{ {
return false; return false;
} }
if(_version != _priorityQueue._version) if(_version != _priorityQueue._version)
{ {
throw new InvalidOperationException("The collection has been modified"); throw new InvalidOperationException("The collection has been modified");
} }
if (!_enumerator.MoveNext()) if (!_enumerator.MoveNext())
{ {
_queueIndex = _priorityQueue.GetNextNonEmptyQueue(_queueIndex); _queueIndex = _priorityQueue.GetNextNonEmptyQueue(_queueIndex);
if(-1 == _queueIndex) if(-1 == _queueIndex)
{ {
return false; return false;
} }
_enumerator = _priorityQueue._queues[_queueIndex].GetEnumerator(); _enumerator = _priorityQueue._queues[_queueIndex].GetEnumerator();
_enumerator.MoveNext(); _enumerator.MoveNext();
return true; return true;
} }
return true; return true;
} }
#endregion #endregion
} }
#endregion #endregion
} }
#endregion #endregion
} }

View File

@ -1,23 +1,23 @@
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
[assembly: AssemblyTitle("Amib.Threading")] [assembly: AssemblyTitle("Amib.Threading")]
[assembly: AssemblyDescription("Smart Thread Pool")] [assembly: AssemblyDescription("Smart Thread Pool")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Amib.Threading")] [assembly: AssemblyProduct("Amib.Threading")]
[assembly: AssemblyCopyright("")] [assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
[assembly: Guid("c764a3de-c4f8-434d-85b5-a09830d1e44f")] [assembly: Guid("c764a3de-c4f8-434d-85b5-a09830d1e44f")]
[assembly: AssemblyVersion("2.2.3.0")] [assembly: AssemblyVersion("2.2.3.0")]
#if (_PUBLISH) #if (_PUBLISH)
[assembly: InternalsVisibleTo("STPTests,PublicKey=00240000048000009400000006020000002400005253413100040000010001004fe3d39add741ba7c8d52cd1eb0d94c7d79060ad956cbaff0e51c1dce94db10356b261778bc1ac3114b3218434da6fcd8416dd5507653809598f7d2afc422099ce4f6b7b0477f18e6c57c727ef2a7ab6ee56e6b4589fe44cb0e25f2875a3c65ab0383ee33c4dd93023f7ce1218bebc8b7a9a1dac878938f5c4f45ea74b6bd8ad")] [assembly: InternalsVisibleTo("STPTests,PublicKey=00240000048000009400000006020000002400005253413100040000010001004fe3d39add741ba7c8d52cd1eb0d94c7d79060ad956cbaff0e51c1dce94db10356b261778bc1ac3114b3218434da6fcd8416dd5507653809598f7d2afc422099ce4f6b7b0477f18e6c57c727ef2a7ab6ee56e6b4589fe44cb0e25f2875a3c65ab0383ee33c4dd93023f7ce1218bebc8b7a9a1dac878938f5c4f45ea74b6bd8ad")]
#else #else
[assembly: InternalsVisibleTo("STPTests")] [assembly: InternalsVisibleTo("STPTests")]
#endif #endif

View File

@ -1,16 +1,16 @@
#if _SILVERLIGHT #if _SILVERLIGHT
using System.Threading; using System.Threading;
namespace Amib.Threading namespace Amib.Threading
{ {
public enum ThreadPriority public enum ThreadPriority
{ {
Lowest, Lowest,
BelowNormal, BelowNormal,
Normal, Normal,
AboveNormal, AboveNormal,
Highest, Highest,
} }
} }
#endif #endif

View File

@ -1,62 +1,62 @@
#if !(_WINDOWS_CE) #if !(_WINDOWS_CE)
using System; using System;
using System.Threading; using System.Threading;
namespace Amib.Threading.Internal namespace Amib.Threading.Internal
{ {
#if _WINDOWS || WINDOWS_PHONE #if _WINDOWS || WINDOWS_PHONE
internal static class STPEventWaitHandle internal static class STPEventWaitHandle
{ {
public const int WaitTimeout = Timeout.Infinite; public const int WaitTimeout = Timeout.Infinite;
internal static bool WaitAll(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) internal static bool WaitAll(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext)
{ {
return WaitHandle.WaitAll(waitHandles, millisecondsTimeout); return WaitHandle.WaitAll(waitHandles, millisecondsTimeout);
} }
internal static int WaitAny(WaitHandle[] waitHandles) internal static int WaitAny(WaitHandle[] waitHandles)
{ {
return WaitHandle.WaitAny(waitHandles); return WaitHandle.WaitAny(waitHandles);
} }
internal static int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) internal static int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext)
{ {
return WaitHandle.WaitAny(waitHandles, millisecondsTimeout); return WaitHandle.WaitAny(waitHandles, millisecondsTimeout);
} }
internal static bool WaitOne(WaitHandle waitHandle, int millisecondsTimeout, bool exitContext) internal static bool WaitOne(WaitHandle waitHandle, int millisecondsTimeout, bool exitContext)
{ {
return waitHandle.WaitOne(millisecondsTimeout); return waitHandle.WaitOne(millisecondsTimeout);
} }
} }
#else #else
internal static class STPEventWaitHandle internal static class STPEventWaitHandle
{ {
public const int WaitTimeout = Timeout.Infinite; public const int WaitTimeout = Timeout.Infinite;
internal static bool WaitAll(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) internal static bool WaitAll(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext)
{ {
return WaitHandle.WaitAll(waitHandles, millisecondsTimeout, exitContext); return WaitHandle.WaitAll(waitHandles, millisecondsTimeout, exitContext);
} }
internal static int WaitAny(WaitHandle[] waitHandles) internal static int WaitAny(WaitHandle[] waitHandles)
{ {
return WaitHandle.WaitAny(waitHandles); return WaitHandle.WaitAny(waitHandles);
} }
internal static int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext) internal static int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout, bool exitContext)
{ {
return WaitHandle.WaitAny(waitHandles, millisecondsTimeout, exitContext); return WaitHandle.WaitAny(waitHandles, millisecondsTimeout, exitContext);
} }
internal static bool WaitOne(WaitHandle waitHandle, int millisecondsTimeout, bool exitContext) internal static bool WaitOne(WaitHandle waitHandle, int millisecondsTimeout, bool exitContext)
{ {
return waitHandle.WaitOne(millisecondsTimeout, exitContext); return waitHandle.WaitOne(millisecondsTimeout, exitContext);
} }
} }
#endif #endif
} }
#endif #endif

View File

@ -1,448 +1,448 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Threading; using System.Threading;
namespace Amib.Threading namespace Amib.Threading
{ {
public interface ISTPPerformanceCountersReader public interface ISTPPerformanceCountersReader
{ {
long InUseThreads { get; } long InUseThreads { get; }
long ActiveThreads { get; } long ActiveThreads { get; }
long WorkItemsQueued { get; } long WorkItemsQueued { get; }
long WorkItemsProcessed { get; } long WorkItemsProcessed { get; }
} }
} }
namespace Amib.Threading.Internal namespace Amib.Threading.Internal
{ {
internal interface ISTPInstancePerformanceCounters : IDisposable internal interface ISTPInstancePerformanceCounters : IDisposable
{ {
void Close(); void Close();
void SampleThreads(long activeThreads, long inUseThreads); void SampleThreads(long activeThreads, long inUseThreads);
void SampleWorkItems(long workItemsQueued, long workItemsProcessed); void SampleWorkItems(long workItemsQueued, long workItemsProcessed);
void SampleWorkItemsWaitTime(TimeSpan workItemWaitTime); void SampleWorkItemsWaitTime(TimeSpan workItemWaitTime);
void SampleWorkItemsProcessTime(TimeSpan workItemProcessTime); void SampleWorkItemsProcessTime(TimeSpan workItemProcessTime);
} }
#if !(_WINDOWS_CE) && !(_SILVERLIGHT) && !(WINDOWS_PHONE) #if !(_WINDOWS_CE) && !(_SILVERLIGHT) && !(WINDOWS_PHONE)
internal enum STPPerformanceCounterType internal enum STPPerformanceCounterType
{ {
// Fields // Fields
ActiveThreads = 0, ActiveThreads = 0,
InUseThreads = 1, InUseThreads = 1,
OverheadThreads = 2, OverheadThreads = 2,
OverheadThreadsPercent = 3, OverheadThreadsPercent = 3,
OverheadThreadsPercentBase = 4, OverheadThreadsPercentBase = 4,
WorkItems = 5, WorkItems = 5,
WorkItemsInQueue = 6, WorkItemsInQueue = 6,
WorkItemsProcessed = 7, WorkItemsProcessed = 7,
WorkItemsQueuedPerSecond = 8, WorkItemsQueuedPerSecond = 8,
WorkItemsProcessedPerSecond = 9, WorkItemsProcessedPerSecond = 9,
AvgWorkItemWaitTime = 10, AvgWorkItemWaitTime = 10,
AvgWorkItemWaitTimeBase = 11, AvgWorkItemWaitTimeBase = 11,
AvgWorkItemProcessTime = 12, AvgWorkItemProcessTime = 12,
AvgWorkItemProcessTimeBase = 13, AvgWorkItemProcessTimeBase = 13,
WorkItemsGroups = 14, WorkItemsGroups = 14,
LastCounter = 14, LastCounter = 14,
} }
/// <summary> /// <summary>
/// Summary description for STPPerformanceCounter. /// Summary description for STPPerformanceCounter.
/// </summary> /// </summary>
internal class STPPerformanceCounter internal class STPPerformanceCounter
{ {
// Fields // Fields
private readonly PerformanceCounterType _pcType; private readonly PerformanceCounterType _pcType;
protected string _counterHelp; protected string _counterHelp;
protected string _counterName; protected string _counterName;
// Methods // Methods
public STPPerformanceCounter( public STPPerformanceCounter(
string counterName, string counterName,
string counterHelp, string counterHelp,
PerformanceCounterType pcType) PerformanceCounterType pcType)
{ {
_counterName = counterName; _counterName = counterName;
_counterHelp = counterHelp; _counterHelp = counterHelp;
_pcType = pcType; _pcType = pcType;
} }
public void AddCounterToCollection(CounterCreationDataCollection counterData) public void AddCounterToCollection(CounterCreationDataCollection counterData)
{ {
CounterCreationData counterCreationData = new CounterCreationData( CounterCreationData counterCreationData = new CounterCreationData(
_counterName, _counterName,
_counterHelp, _counterHelp,
_pcType); _pcType);
counterData.Add(counterCreationData); counterData.Add(counterCreationData);
} }
// Properties // Properties
public string Name public string Name
{ {
get get
{ {
return _counterName; return _counterName;
} }
} }
} }
internal class STPPerformanceCounters internal class STPPerformanceCounters
{ {
// Fields // Fields
internal STPPerformanceCounter[] _stpPerformanceCounters; internal STPPerformanceCounter[] _stpPerformanceCounters;
private static readonly STPPerformanceCounters _instance; private static readonly STPPerformanceCounters _instance;
internal const string _stpCategoryHelp = "SmartThreadPool performance counters"; internal const string _stpCategoryHelp = "SmartThreadPool performance counters";
internal const string _stpCategoryName = "SmartThreadPool"; internal const string _stpCategoryName = "SmartThreadPool";
// Methods // Methods
static STPPerformanceCounters() static STPPerformanceCounters()
{ {
_instance = new STPPerformanceCounters(); _instance = new STPPerformanceCounters();
} }
private STPPerformanceCounters() private STPPerformanceCounters()
{ {
STPPerformanceCounter[] stpPerformanceCounters = new STPPerformanceCounter[] STPPerformanceCounter[] stpPerformanceCounters = new STPPerformanceCounter[]
{ {
new STPPerformanceCounter("Active threads", "The current number of available in the thread pool.", PerformanceCounterType.NumberOfItems32), 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("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.", 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", "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("% 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", "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 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 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 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 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/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 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/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 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; _stpPerformanceCounters = stpPerformanceCounters;
SetupCategory(); SetupCategory();
} }
private void SetupCategory() private void SetupCategory()
{ {
if (!PerformanceCounterCategory.Exists(_stpCategoryName)) if (!PerformanceCounterCategory.Exists(_stpCategoryName))
{ {
CounterCreationDataCollection counters = new CounterCreationDataCollection(); CounterCreationDataCollection counters = new CounterCreationDataCollection();
for (int i = 0; i < _stpPerformanceCounters.Length; i++) for (int i = 0; i < _stpPerformanceCounters.Length; i++)
{ {
_stpPerformanceCounters[i].AddCounterToCollection(counters); _stpPerformanceCounters[i].AddCounterToCollection(counters);
} }
PerformanceCounterCategory.Create( PerformanceCounterCategory.Create(
_stpCategoryName, _stpCategoryName,
_stpCategoryHelp, _stpCategoryHelp,
PerformanceCounterCategoryType.MultiInstance, PerformanceCounterCategoryType.MultiInstance,
counters); counters);
} }
} }
// Properties // Properties
public static STPPerformanceCounters Instance public static STPPerformanceCounters Instance
{ {
get get
{ {
return _instance; return _instance;
} }
} }
} }
internal class STPInstancePerformanceCounter : IDisposable internal class STPInstancePerformanceCounter : IDisposable
{ {
// Fields // Fields
private bool _isDisposed; private bool _isDisposed;
private PerformanceCounter _pcs; private PerformanceCounter _pcs;
// Methods // Methods
protected STPInstancePerformanceCounter() protected STPInstancePerformanceCounter()
{ {
_isDisposed = false; _isDisposed = false;
} }
public STPInstancePerformanceCounter( public STPInstancePerformanceCounter(
string instance, string instance,
STPPerformanceCounterType spcType) : this() STPPerformanceCounterType spcType) : this()
{ {
STPPerformanceCounters counters = STPPerformanceCounters.Instance; STPPerformanceCounters counters = STPPerformanceCounters.Instance;
_pcs = new PerformanceCounter( _pcs = new PerformanceCounter(
STPPerformanceCounters._stpCategoryName, STPPerformanceCounters._stpCategoryName,
counters._stpPerformanceCounters[(int) spcType].Name, counters._stpPerformanceCounters[(int) spcType].Name,
instance, instance,
false); false);
_pcs.RawValue = _pcs.RawValue; _pcs.RawValue = _pcs.RawValue;
} }
public void Close() public void Close()
{ {
if (_pcs != null) if (_pcs != null)
{ {
_pcs.RemoveInstance(); _pcs.RemoveInstance();
_pcs.Close(); _pcs.Close();
_pcs = null; _pcs = null;
} }
} }
public void Dispose() public void Dispose()
{ {
Dispose(true); Dispose(true);
} }
public virtual void Dispose(bool disposing) public virtual void Dispose(bool disposing)
{ {
if (!_isDisposed) if (!_isDisposed)
{ {
if (disposing) if (disposing)
{ {
Close(); Close();
} }
} }
_isDisposed = true; _isDisposed = true;
} }
public virtual void Increment() public virtual void Increment()
{ {
_pcs.Increment(); _pcs.Increment();
} }
public virtual void IncrementBy(long val) public virtual void IncrementBy(long val)
{ {
_pcs.IncrementBy(val); _pcs.IncrementBy(val);
} }
public virtual void Set(long val) public virtual void Set(long val)
{ {
_pcs.RawValue = val; _pcs.RawValue = val;
} }
} }
internal class STPInstanceNullPerformanceCounter : STPInstancePerformanceCounter internal class STPInstanceNullPerformanceCounter : STPInstancePerformanceCounter
{ {
// Methods // Methods
public override void Increment() {} public override void Increment() {}
public override void IncrementBy(long value) {} public override void IncrementBy(long value) {}
public override void Set(long val) {} public override void Set(long val) {}
} }
internal class STPInstancePerformanceCounters : ISTPInstancePerformanceCounters internal class STPInstancePerformanceCounters : ISTPInstancePerformanceCounters
{ {
private bool _isDisposed; private bool _isDisposed;
// Fields // Fields
private STPInstancePerformanceCounter[] _pcs; private STPInstancePerformanceCounter[] _pcs;
private static readonly STPInstancePerformanceCounter _stpInstanceNullPerformanceCounter; private static readonly STPInstancePerformanceCounter _stpInstanceNullPerformanceCounter;
// Methods // Methods
static STPInstancePerformanceCounters() static STPInstancePerformanceCounters()
{ {
_stpInstanceNullPerformanceCounter = new STPInstanceNullPerformanceCounter(); _stpInstanceNullPerformanceCounter = new STPInstanceNullPerformanceCounter();
} }
public STPInstancePerformanceCounters(string instance) public STPInstancePerformanceCounters(string instance)
{ {
_isDisposed = false; _isDisposed = false;
_pcs = new STPInstancePerformanceCounter[(int)STPPerformanceCounterType.LastCounter]; _pcs = new STPInstancePerformanceCounter[(int)STPPerformanceCounterType.LastCounter];
// Call the STPPerformanceCounters.Instance so the static constructor will // Call the STPPerformanceCounters.Instance so the static constructor will
// intialize the STPPerformanceCounters singleton. // intialize the STPPerformanceCounters singleton.
STPPerformanceCounters.Instance.GetHashCode(); STPPerformanceCounters.Instance.GetHashCode();
for (int i = 0; i < _pcs.Length; i++) for (int i = 0; i < _pcs.Length; i++)
{ {
if (instance != null) if (instance != null)
{ {
_pcs[i] = new STPInstancePerformanceCounter( _pcs[i] = new STPInstancePerformanceCounter(
instance, instance,
(STPPerformanceCounterType) i); (STPPerformanceCounterType) i);
} }
else else
{ {
_pcs[i] = _stpInstanceNullPerformanceCounter; _pcs[i] = _stpInstanceNullPerformanceCounter;
} }
} }
} }
public void Close() public void Close()
{ {
if (null != _pcs) if (null != _pcs)
{ {
for (int i = 0; i < _pcs.Length; i++) for (int i = 0; i < _pcs.Length; i++)
{ {
if (null != _pcs[i]) if (null != _pcs[i])
{ {
_pcs[i].Dispose(); _pcs[i].Dispose();
} }
} }
_pcs = null; _pcs = null;
} }
} }
public void Dispose() public void Dispose()
{ {
Dispose(true); Dispose(true);
} }
public virtual void Dispose(bool disposing) public virtual void Dispose(bool disposing)
{ {
if (!_isDisposed) if (!_isDisposed)
{ {
if (disposing) if (disposing)
{ {
Close(); Close();
} }
} }
_isDisposed = true; _isDisposed = true;
} }
private STPInstancePerformanceCounter GetCounter(STPPerformanceCounterType spcType) private STPInstancePerformanceCounter GetCounter(STPPerformanceCounterType spcType)
{ {
return _pcs[(int) spcType]; return _pcs[(int) spcType];
} }
public void SampleThreads(long activeThreads, long inUseThreads) public void SampleThreads(long activeThreads, long inUseThreads)
{ {
GetCounter(STPPerformanceCounterType.ActiveThreads).Set(activeThreads); GetCounter(STPPerformanceCounterType.ActiveThreads).Set(activeThreads);
GetCounter(STPPerformanceCounterType.InUseThreads).Set(inUseThreads); GetCounter(STPPerformanceCounterType.InUseThreads).Set(inUseThreads);
GetCounter(STPPerformanceCounterType.OverheadThreads).Set(activeThreads-inUseThreads); GetCounter(STPPerformanceCounterType.OverheadThreads).Set(activeThreads-inUseThreads);
GetCounter(STPPerformanceCounterType.OverheadThreadsPercentBase).Set(activeThreads-inUseThreads); GetCounter(STPPerformanceCounterType.OverheadThreadsPercentBase).Set(activeThreads-inUseThreads);
GetCounter(STPPerformanceCounterType.OverheadThreadsPercent).Set(inUseThreads); GetCounter(STPPerformanceCounterType.OverheadThreadsPercent).Set(inUseThreads);
} }
public void SampleWorkItems(long workItemsQueued, long workItemsProcessed) public void SampleWorkItems(long workItemsQueued, long workItemsProcessed)
{ {
GetCounter(STPPerformanceCounterType.WorkItems).Set(workItemsQueued+workItemsProcessed); GetCounter(STPPerformanceCounterType.WorkItems).Set(workItemsQueued+workItemsProcessed);
GetCounter(STPPerformanceCounterType.WorkItemsInQueue).Set(workItemsQueued); GetCounter(STPPerformanceCounterType.WorkItemsInQueue).Set(workItemsQueued);
GetCounter(STPPerformanceCounterType.WorkItemsProcessed).Set(workItemsProcessed); GetCounter(STPPerformanceCounterType.WorkItemsProcessed).Set(workItemsProcessed);
GetCounter(STPPerformanceCounterType.WorkItemsQueuedPerSecond).Set(workItemsQueued); GetCounter(STPPerformanceCounterType.WorkItemsQueuedPerSecond).Set(workItemsQueued);
GetCounter(STPPerformanceCounterType.WorkItemsProcessedPerSecond).Set(workItemsProcessed); GetCounter(STPPerformanceCounterType.WorkItemsProcessedPerSecond).Set(workItemsProcessed);
} }
public void SampleWorkItemsWaitTime(TimeSpan workItemWaitTime) public void SampleWorkItemsWaitTime(TimeSpan workItemWaitTime)
{ {
GetCounter(STPPerformanceCounterType.AvgWorkItemWaitTime).IncrementBy((long)workItemWaitTime.TotalMilliseconds); GetCounter(STPPerformanceCounterType.AvgWorkItemWaitTime).IncrementBy((long)workItemWaitTime.TotalMilliseconds);
GetCounter(STPPerformanceCounterType.AvgWorkItemWaitTimeBase).Increment(); GetCounter(STPPerformanceCounterType.AvgWorkItemWaitTimeBase).Increment();
} }
public void SampleWorkItemsProcessTime(TimeSpan workItemProcessTime) public void SampleWorkItemsProcessTime(TimeSpan workItemProcessTime)
{ {
GetCounter(STPPerformanceCounterType.AvgWorkItemProcessTime).IncrementBy((long)workItemProcessTime.TotalMilliseconds); GetCounter(STPPerformanceCounterType.AvgWorkItemProcessTime).IncrementBy((long)workItemProcessTime.TotalMilliseconds);
GetCounter(STPPerformanceCounterType.AvgWorkItemProcessTimeBase).Increment(); GetCounter(STPPerformanceCounterType.AvgWorkItemProcessTimeBase).Increment();
} }
} }
#endif #endif
internal class NullSTPInstancePerformanceCounters : ISTPInstancePerformanceCounters, ISTPPerformanceCountersReader internal class NullSTPInstancePerformanceCounters : ISTPInstancePerformanceCounters, ISTPPerformanceCountersReader
{ {
private static readonly NullSTPInstancePerformanceCounters _instance = new NullSTPInstancePerformanceCounters(); private static readonly NullSTPInstancePerformanceCounters _instance = new NullSTPInstancePerformanceCounters();
public static NullSTPInstancePerformanceCounters Instance public static NullSTPInstancePerformanceCounters Instance
{ {
get { return _instance; } get { return _instance; }
} }
public void Close() {} public void Close() {}
public void Dispose() {} public void Dispose() {}
public void SampleThreads(long activeThreads, long inUseThreads) {} public void SampleThreads(long activeThreads, long inUseThreads) {}
public void SampleWorkItems(long workItemsQueued, long workItemsProcessed) {} public void SampleWorkItems(long workItemsQueued, long workItemsProcessed) {}
public void SampleWorkItemsWaitTime(TimeSpan workItemWaitTime) {} public void SampleWorkItemsWaitTime(TimeSpan workItemWaitTime) {}
public void SampleWorkItemsProcessTime(TimeSpan workItemProcessTime) {} public void SampleWorkItemsProcessTime(TimeSpan workItemProcessTime) {}
public long InUseThreads public long InUseThreads
{ {
get { return 0; } get { return 0; }
} }
public long ActiveThreads public long ActiveThreads
{ {
get { return 0; } get { return 0; }
} }
public long WorkItemsQueued public long WorkItemsQueued
{ {
get { return 0; } get { return 0; }
} }
public long WorkItemsProcessed public long WorkItemsProcessed
{ {
get { return 0; } get { return 0; }
} }
} }
internal class LocalSTPInstancePerformanceCounters : ISTPInstancePerformanceCounters, ISTPPerformanceCountersReader internal class LocalSTPInstancePerformanceCounters : ISTPInstancePerformanceCounters, ISTPPerformanceCountersReader
{ {
public void Close() { } public void Close() { }
public void Dispose() { } public void Dispose() { }
private long _activeThreads; private long _activeThreads;
private long _inUseThreads; private long _inUseThreads;
private long _workItemsQueued; private long _workItemsQueued;
private long _workItemsProcessed; private long _workItemsProcessed;
public long InUseThreads public long InUseThreads
{ {
get { return _inUseThreads; } get { return _inUseThreads; }
} }
public long ActiveThreads public long ActiveThreads
{ {
get { return _activeThreads; } get { return _activeThreads; }
} }
public long WorkItemsQueued public long WorkItemsQueued
{ {
get { return _workItemsQueued; } get { return _workItemsQueued; }
} }
public long WorkItemsProcessed public long WorkItemsProcessed
{ {
get { return _workItemsProcessed; } get { return _workItemsProcessed; }
} }
public void SampleThreads(long activeThreads, long inUseThreads) public void SampleThreads(long activeThreads, long inUseThreads)
{ {
_activeThreads = activeThreads; _activeThreads = activeThreads;
_inUseThreads = inUseThreads; _inUseThreads = inUseThreads;
} }
public void SampleWorkItems(long workItemsQueued, long workItemsProcessed) public void SampleWorkItems(long workItemsQueued, long workItemsProcessed)
{ {
_workItemsQueued = workItemsQueued; _workItemsQueued = workItemsQueued;
_workItemsProcessed = workItemsProcessed; _workItemsProcessed = workItemsProcessed;
} }
public void SampleWorkItemsWaitTime(TimeSpan workItemWaitTime) public void SampleWorkItemsWaitTime(TimeSpan workItemWaitTime)
{ {
// Not supported // Not supported
} }
public void SampleWorkItemsProcessTime(TimeSpan workItemProcessTime) public void SampleWorkItemsProcessTime(TimeSpan workItemProcessTime)
{ {
// Not supported // Not supported
} }
} }
} }

View File

@ -1,212 +1,212 @@
using System; using System;
using System.Threading; using System.Threading;
namespace Amib.Threading namespace Amib.Threading
{ {
/// <summary> /// <summary>
/// Summary description for STPStartInfo. /// Summary description for STPStartInfo.
/// </summary> /// </summary>
public class STPStartInfo : WIGStartInfo public class STPStartInfo : WIGStartInfo
{ {
private int _idleTimeout = SmartThreadPool.DefaultIdleTimeout; private int _idleTimeout = SmartThreadPool.DefaultIdleTimeout;
private int _minWorkerThreads = SmartThreadPool.DefaultMinWorkerThreads; private int _minWorkerThreads = SmartThreadPool.DefaultMinWorkerThreads;
private int _maxWorkerThreads = SmartThreadPool.DefaultMaxWorkerThreads; private int _maxWorkerThreads = SmartThreadPool.DefaultMaxWorkerThreads;
#if !(WINDOWS_PHONE) #if !(WINDOWS_PHONE)
private ThreadPriority _threadPriority = SmartThreadPool.DefaultThreadPriority; private ThreadPriority _threadPriority = SmartThreadPool.DefaultThreadPriority;
#endif #endif
private string _performanceCounterInstanceName = SmartThreadPool.DefaultPerformanceCounterInstanceName; private string _performanceCounterInstanceName = SmartThreadPool.DefaultPerformanceCounterInstanceName;
private bool _areThreadsBackground = SmartThreadPool.DefaultAreThreadsBackground; private bool _areThreadsBackground = SmartThreadPool.DefaultAreThreadsBackground;
private bool _enableLocalPerformanceCounters; private bool _enableLocalPerformanceCounters;
private string _threadPoolName = SmartThreadPool.DefaultThreadPoolName; private string _threadPoolName = SmartThreadPool.DefaultThreadPoolName;
private int? _maxStackSize = SmartThreadPool.DefaultMaxStackSize; private int? _maxStackSize = SmartThreadPool.DefaultMaxStackSize;
public STPStartInfo() public STPStartInfo()
{ {
_performanceCounterInstanceName = SmartThreadPool.DefaultPerformanceCounterInstanceName; _performanceCounterInstanceName = SmartThreadPool.DefaultPerformanceCounterInstanceName;
#if !(WINDOWS_PHONE) #if !(WINDOWS_PHONE)
_threadPriority = SmartThreadPool.DefaultThreadPriority; _threadPriority = SmartThreadPool.DefaultThreadPriority;
#endif #endif
_maxWorkerThreads = SmartThreadPool.DefaultMaxWorkerThreads; _maxWorkerThreads = SmartThreadPool.DefaultMaxWorkerThreads;
_idleTimeout = SmartThreadPool.DefaultIdleTimeout; _idleTimeout = SmartThreadPool.DefaultIdleTimeout;
_minWorkerThreads = SmartThreadPool.DefaultMinWorkerThreads; _minWorkerThreads = SmartThreadPool.DefaultMinWorkerThreads;
} }
public STPStartInfo(STPStartInfo stpStartInfo) public STPStartInfo(STPStartInfo stpStartInfo)
: base(stpStartInfo) : base(stpStartInfo)
{ {
_idleTimeout = stpStartInfo.IdleTimeout; _idleTimeout = stpStartInfo.IdleTimeout;
_minWorkerThreads = stpStartInfo.MinWorkerThreads; _minWorkerThreads = stpStartInfo.MinWorkerThreads;
_maxWorkerThreads = stpStartInfo.MaxWorkerThreads; _maxWorkerThreads = stpStartInfo.MaxWorkerThreads;
#if !(WINDOWS_PHONE) #if !(WINDOWS_PHONE)
_threadPriority = stpStartInfo.ThreadPriority; _threadPriority = stpStartInfo.ThreadPriority;
#endif #endif
_performanceCounterInstanceName = stpStartInfo.PerformanceCounterInstanceName; _performanceCounterInstanceName = stpStartInfo.PerformanceCounterInstanceName;
_enableLocalPerformanceCounters = stpStartInfo._enableLocalPerformanceCounters; _enableLocalPerformanceCounters = stpStartInfo._enableLocalPerformanceCounters;
_threadPoolName = stpStartInfo._threadPoolName; _threadPoolName = stpStartInfo._threadPoolName;
_areThreadsBackground = stpStartInfo.AreThreadsBackground; _areThreadsBackground = stpStartInfo.AreThreadsBackground;
#if !(_SILVERLIGHT) && !(WINDOWS_PHONE) #if !(_SILVERLIGHT) && !(WINDOWS_PHONE)
_apartmentState = stpStartInfo._apartmentState; _apartmentState = stpStartInfo._apartmentState;
#endif #endif
} }
/// <summary> /// <summary>
/// Get/Set the idle timeout in milliseconds. /// Get/Set the idle timeout in milliseconds.
/// If a thread is idle (starved) longer than IdleTimeout then it may quit. /// If a thread is idle (starved) longer than IdleTimeout then it may quit.
/// </summary> /// </summary>
public virtual int IdleTimeout public virtual int IdleTimeout
{ {
get { return _idleTimeout; } get { return _idleTimeout; }
set set
{ {
ThrowIfReadOnly(); ThrowIfReadOnly();
_idleTimeout = value; _idleTimeout = value;
} }
} }
/// <summary> /// <summary>
/// Get/Set the lower limit of threads in the pool. /// Get/Set the lower limit of threads in the pool.
/// </summary> /// </summary>
public virtual int MinWorkerThreads public virtual int MinWorkerThreads
{ {
get { return _minWorkerThreads; } get { return _minWorkerThreads; }
set set
{ {
ThrowIfReadOnly(); ThrowIfReadOnly();
_minWorkerThreads = value; _minWorkerThreads = value;
} }
} }
/// <summary> /// <summary>
/// Get/Set the upper limit of threads in the pool. /// Get/Set the upper limit of threads in the pool.
/// </summary> /// </summary>
public virtual int MaxWorkerThreads public virtual int MaxWorkerThreads
{ {
get { return _maxWorkerThreads; } get { return _maxWorkerThreads; }
set set
{ {
ThrowIfReadOnly(); ThrowIfReadOnly();
_maxWorkerThreads = value; _maxWorkerThreads = value;
} }
} }
#if !(WINDOWS_PHONE) #if !(WINDOWS_PHONE)
/// <summary> /// <summary>
/// Get/Set the scheduling priority of the threads in the pool. /// Get/Set the scheduling priority of the threads in the pool.
/// The Os handles the scheduling. /// The Os handles the scheduling.
/// </summary> /// </summary>
public virtual ThreadPriority ThreadPriority public virtual ThreadPriority ThreadPriority
{ {
get { return _threadPriority; } get { return _threadPriority; }
set set
{ {
ThrowIfReadOnly(); ThrowIfReadOnly();
_threadPriority = value; _threadPriority = value;
} }
} }
#endif #endif
/// <summary> /// <summary>
/// Get/Set the thread pool name. Threads will get names depending on this. /// Get/Set the thread pool name. Threads will get names depending on this.
/// </summary> /// </summary>
public virtual string ThreadPoolName { public virtual string ThreadPoolName {
get { return _threadPoolName; } get { return _threadPoolName; }
set set
{ {
ThrowIfReadOnly (); ThrowIfReadOnly ();
_threadPoolName = value; _threadPoolName = value;
} }
} }
/// <summary> /// <summary>
/// Get/Set the performance counter instance name of this SmartThreadPool /// Get/Set the performance counter instance name of this SmartThreadPool
/// The default is null which indicate not to use performance counters at all. /// The default is null which indicate not to use performance counters at all.
/// </summary> /// </summary>
public virtual string PerformanceCounterInstanceName public virtual string PerformanceCounterInstanceName
{ {
get { return _performanceCounterInstanceName; } get { return _performanceCounterInstanceName; }
set set
{ {
ThrowIfReadOnly(); ThrowIfReadOnly();
_performanceCounterInstanceName = value; _performanceCounterInstanceName = value;
} }
} }
/// <summary> /// <summary>
/// Enable/Disable the local performance counter. /// 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.) /// without using Windows performance counters. (Useful on WindowsCE, Silverlight, etc.)
/// The default is false. /// The default is false.
/// </summary> /// </summary>
public virtual bool EnableLocalPerformanceCounters public virtual bool EnableLocalPerformanceCounters
{ {
get { return _enableLocalPerformanceCounters; } get { return _enableLocalPerformanceCounters; }
set set
{ {
ThrowIfReadOnly(); ThrowIfReadOnly();
_enableLocalPerformanceCounters = value; _enableLocalPerformanceCounters = value;
} }
} }
/// <summary> /// <summary>
/// Get/Set backgroundness of thread in thread pool. /// Get/Set backgroundness of thread in thread pool.
/// </summary> /// </summary>
public virtual bool AreThreadsBackground public virtual bool AreThreadsBackground
{ {
get { return _areThreadsBackground; } get { return _areThreadsBackground; }
set set
{ {
ThrowIfReadOnly (); ThrowIfReadOnly ();
_areThreadsBackground = value; _areThreadsBackground = value;
} }
} }
/// <summary> /// <summary>
/// Get a readonly version of this STPStartInfo. /// Get a readonly version of this STPStartInfo.
/// </summary> /// </summary>
/// <returns>Returns a readonly reference to this STPStartInfo</returns> /// <returns>Returns a readonly reference to this STPStartInfo</returns>
public new STPStartInfo AsReadOnly() public new STPStartInfo AsReadOnly()
{ {
return new STPStartInfo(this) { _readOnly = true }; return new STPStartInfo(this) { _readOnly = true };
} }
#if !(_SILVERLIGHT) && !(WINDOWS_PHONE) #if !(_SILVERLIGHT) && !(WINDOWS_PHONE)
private ApartmentState _apartmentState = SmartThreadPool.DefaultApartmentState; private ApartmentState _apartmentState = SmartThreadPool.DefaultApartmentState;
/// <summary> /// <summary>
/// Get/Set the apartment state of threads in the thread pool /// Get/Set the apartment state of threads in the thread pool
/// </summary> /// </summary>
public ApartmentState ApartmentState public ApartmentState ApartmentState
{ {
get { return _apartmentState; } get { return _apartmentState; }
set set
{ {
ThrowIfReadOnly(); ThrowIfReadOnly();
_apartmentState = value; _apartmentState = value;
} }
} }
#if !(_SILVERLIGHT) && !(WINDOWS_PHONE) #if !(_SILVERLIGHT) && !(WINDOWS_PHONE)
/// <summary> /// <summary>
/// Get/Set the max stack size of threads in the thread pool /// Get/Set the max stack size of threads in the thread pool
/// </summary> /// </summary>
public int? MaxStackSize public int? MaxStackSize
{ {
get { return _maxStackSize; } get { return _maxStackSize; }
set set
{ {
ThrowIfReadOnly(); ThrowIfReadOnly();
if (value.HasValue && value.Value < 0) if (value.HasValue && value.Value < 0)
{ {
throw new ArgumentOutOfRangeException("value", "Value must be greater than 0."); throw new ArgumentOutOfRangeException("value", "Value must be greater than 0.");
} }
_maxStackSize = value; _maxStackSize = value;
} }
} }
#endif #endif
#endif #endif
} }
} }

View File

@ -1,60 +1,60 @@

using System; using System;
using Amib.Threading.Internal; using Amib.Threading.Internal;
namespace Amib.Threading namespace Amib.Threading
{ {
public partial class SmartThreadPool public partial class SmartThreadPool
{ {
#region ThreadEntry class #region ThreadEntry class
internal class ThreadEntry internal class ThreadEntry
{ {
/// <summary> /// <summary>
/// The thread creation time /// The thread creation time
/// The value is stored as UTC value. /// The value is stored as UTC value.
/// </summary> /// </summary>
private readonly DateTime _creationTime; private readonly DateTime _creationTime;
/// <summary> /// <summary>
/// The last time this thread has been running /// The last time this thread has been running
/// It is updated by IAmAlive() method /// It is updated by IAmAlive() method
/// The value is stored as UTC value. /// The value is stored as UTC value.
/// </summary> /// </summary>
private DateTime _lastAliveTime; private DateTime _lastAliveTime;
/// <summary> /// <summary>
/// A reference from each thread in the thread pool to its SmartThreadPool /// A reference from each thread in the thread pool to its SmartThreadPool
/// object container. /// 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. /// SmartThreadPool.
/// </summary> /// </summary>
private readonly SmartThreadPool _associatedSmartThreadPool; private readonly SmartThreadPool _associatedSmartThreadPool;
/// <summary> /// <summary>
/// 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. /// is executing.
/// </summary> /// </summary>
public WorkItem CurrentWorkItem { get; set; } public WorkItem CurrentWorkItem { get; set; }
public ThreadEntry(SmartThreadPool stp) public ThreadEntry(SmartThreadPool stp)
{ {
_associatedSmartThreadPool = stp; _associatedSmartThreadPool = stp;
_creationTime = DateTime.UtcNow; _creationTime = DateTime.UtcNow;
_lastAliveTime = DateTime.MinValue; _lastAliveTime = DateTime.MinValue;
} }
public SmartThreadPool AssociatedSmartThreadPool public SmartThreadPool AssociatedSmartThreadPool
{ {
get { return _associatedSmartThreadPool; } get { return _associatedSmartThreadPool; }
} }
public void IAmAlive() public void IAmAlive()
{ {
_lastAliveTime = DateTime.UtcNow; _lastAliveTime = DateTime.UtcNow;
} }
} }
#endregion #endregion
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,89 +1,89 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace Amib.Threading.Internal namespace Amib.Threading.Internal
{ {
internal class SynchronizedDictionary<TKey, TValue> internal class SynchronizedDictionary<TKey, TValue>
{ {
private readonly Dictionary<TKey, TValue> _dictionary; private readonly Dictionary<TKey, TValue> _dictionary;
private readonly object _lock; private readonly object _lock;
public SynchronizedDictionary() public SynchronizedDictionary()
{ {
_lock = new object(); _lock = new object();
_dictionary = new Dictionary<TKey, TValue>(); _dictionary = new Dictionary<TKey, TValue>();
} }
public int Count public int Count
{ {
get { return _dictionary.Count; } get { return _dictionary.Count; }
} }
public bool Contains(TKey key) public bool Contains(TKey key)
{ {
lock (_lock) lock (_lock)
{ {
return _dictionary.ContainsKey(key); return _dictionary.ContainsKey(key);
} }
} }
public void Remove(TKey key) public void Remove(TKey key)
{ {
lock (_lock) lock (_lock)
{ {
_dictionary.Remove(key); _dictionary.Remove(key);
} }
} }
public object SyncRoot public object SyncRoot
{ {
get { return _lock; } get { return _lock; }
} }
public TValue this[TKey key] public TValue this[TKey key]
{ {
get get
{ {
lock (_lock) lock (_lock)
{ {
return _dictionary[key]; return _dictionary[key];
} }
} }
set set
{ {
lock (_lock) lock (_lock)
{ {
_dictionary[key] = value; _dictionary[key] = value;
} }
} }
} }
public Dictionary<TKey, TValue>.KeyCollection Keys public Dictionary<TKey, TValue>.KeyCollection Keys
{ {
get get
{ {
lock (_lock) lock (_lock)
{ {
return _dictionary.Keys; return _dictionary.Keys;
} }
} }
} }
public Dictionary<TKey, TValue>.ValueCollection Values public Dictionary<TKey, TValue>.ValueCollection Values
{ {
get get
{ {
lock (_lock) lock (_lock)
{ {
return _dictionary.Values; return _dictionary.Values;
} }
} }
} }
public void Clear() public void Clear()
{ {
lock (_lock) lock (_lock)
{ {
_dictionary.Clear(); _dictionary.Clear();
} }
} }
} }
} }

View File

@ -1,171 +1,171 @@
using System; using System;
namespace Amib.Threading namespace Amib.Threading
{ {
/// <summary> /// <summary>
/// Summary description for WIGStartInfo. /// Summary description for WIGStartInfo.
/// </summary> /// </summary>
public class WIGStartInfo public class WIGStartInfo
{ {
private bool _useCallerCallContext; private bool _useCallerCallContext;
private bool _useCallerHttpContext; private bool _useCallerHttpContext;
private bool _disposeOfStateObjects; private bool _disposeOfStateObjects;
private CallToPostExecute _callToPostExecute; private CallToPostExecute _callToPostExecute;
private PostExecuteWorkItemCallback _postExecuteWorkItemCallback; private PostExecuteWorkItemCallback _postExecuteWorkItemCallback;
private bool _startSuspended; private bool _startSuspended;
private WorkItemPriority _workItemPriority; private WorkItemPriority _workItemPriority;
private bool _fillStateWithArgs; private bool _fillStateWithArgs;
protected bool _readOnly; protected bool _readOnly;
public WIGStartInfo() public WIGStartInfo()
{ {
_fillStateWithArgs = SmartThreadPool.DefaultFillStateWithArgs; _fillStateWithArgs = SmartThreadPool.DefaultFillStateWithArgs;
_workItemPriority = SmartThreadPool.DefaultWorkItemPriority; _workItemPriority = SmartThreadPool.DefaultWorkItemPriority;
_startSuspended = SmartThreadPool.DefaultStartSuspended; _startSuspended = SmartThreadPool.DefaultStartSuspended;
_postExecuteWorkItemCallback = SmartThreadPool.DefaultPostExecuteWorkItemCallback; _postExecuteWorkItemCallback = SmartThreadPool.DefaultPostExecuteWorkItemCallback;
_callToPostExecute = SmartThreadPool.DefaultCallToPostExecute; _callToPostExecute = SmartThreadPool.DefaultCallToPostExecute;
_disposeOfStateObjects = SmartThreadPool.DefaultDisposeOfStateObjects; _disposeOfStateObjects = SmartThreadPool.DefaultDisposeOfStateObjects;
_useCallerHttpContext = SmartThreadPool.DefaultUseCallerHttpContext; _useCallerHttpContext = SmartThreadPool.DefaultUseCallerHttpContext;
_useCallerCallContext = SmartThreadPool.DefaultUseCallerCallContext; _useCallerCallContext = SmartThreadPool.DefaultUseCallerCallContext;
} }
public WIGStartInfo(WIGStartInfo wigStartInfo) public WIGStartInfo(WIGStartInfo wigStartInfo)
{ {
_useCallerCallContext = wigStartInfo.UseCallerCallContext; _useCallerCallContext = wigStartInfo.UseCallerCallContext;
_useCallerHttpContext = wigStartInfo.UseCallerHttpContext; _useCallerHttpContext = wigStartInfo.UseCallerHttpContext;
_disposeOfStateObjects = wigStartInfo.DisposeOfStateObjects; _disposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;
_callToPostExecute = wigStartInfo.CallToPostExecute; _callToPostExecute = wigStartInfo.CallToPostExecute;
_postExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback; _postExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback;
_workItemPriority = wigStartInfo.WorkItemPriority; _workItemPriority = wigStartInfo.WorkItemPriority;
_startSuspended = wigStartInfo.StartSuspended; _startSuspended = wigStartInfo.StartSuspended;
_fillStateWithArgs = wigStartInfo.FillStateWithArgs; _fillStateWithArgs = wigStartInfo.FillStateWithArgs;
} }
protected void ThrowIfReadOnly() protected void ThrowIfReadOnly()
{ {
if (_readOnly) if (_readOnly)
{ {
throw new NotSupportedException("This is a readonly instance and set is not supported"); throw new NotSupportedException("This is a readonly instance and set is not supported");
} }
} }
/// <summary> /// <summary>
/// Get/Set if to use the caller's security context /// Get/Set if to use the caller's security context
/// </summary> /// </summary>
public virtual bool UseCallerCallContext public virtual bool UseCallerCallContext
{ {
get { return _useCallerCallContext; } get { return _useCallerCallContext; }
set set
{ {
ThrowIfReadOnly(); ThrowIfReadOnly();
_useCallerCallContext = value; _useCallerCallContext = value;
} }
} }
/// <summary> /// <summary>
/// Get/Set if to use the caller's HTTP context /// Get/Set if to use the caller's HTTP context
/// </summary> /// </summary>
public virtual bool UseCallerHttpContext public virtual bool UseCallerHttpContext
{ {
get { return _useCallerHttpContext; } get { return _useCallerHttpContext; }
set set
{ {
ThrowIfReadOnly(); ThrowIfReadOnly();
_useCallerHttpContext = value; _useCallerHttpContext = value;
} }
} }
/// <summary> /// <summary>
/// Get/Set if to dispose of the state object of a work item /// Get/Set if to dispose of the state object of a work item
/// </summary> /// </summary>
public virtual bool DisposeOfStateObjects public virtual bool DisposeOfStateObjects
{ {
get { return _disposeOfStateObjects; } get { return _disposeOfStateObjects; }
set set
{ {
ThrowIfReadOnly(); ThrowIfReadOnly();
_disposeOfStateObjects = value; _disposeOfStateObjects = value;
} }
} }
/// <summary> /// <summary>
/// Get/Set the run the post execute options /// Get/Set the run the post execute options
/// </summary> /// </summary>
public virtual CallToPostExecute CallToPostExecute public virtual CallToPostExecute CallToPostExecute
{ {
get { return _callToPostExecute; } get { return _callToPostExecute; }
set set
{ {
ThrowIfReadOnly(); ThrowIfReadOnly();
_callToPostExecute = value; _callToPostExecute = value;
} }
} }
/// <summary> /// <summary>
/// Get/Set the default post execute callback /// Get/Set the default post execute callback
/// </summary> /// </summary>
public virtual PostExecuteWorkItemCallback PostExecuteWorkItemCallback public virtual PostExecuteWorkItemCallback PostExecuteWorkItemCallback
{ {
get { return _postExecuteWorkItemCallback; } get { return _postExecuteWorkItemCallback; }
set set
{ {
ThrowIfReadOnly(); ThrowIfReadOnly();
_postExecuteWorkItemCallback = value; _postExecuteWorkItemCallback = value;
} }
} }
/// <summary> /// <summary>
/// Get/Set if the work items execution should be suspended until the Start() /// Get/Set if the work items execution should be suspended until the Start()
/// method is called. /// method is called.
/// </summary> /// </summary>
public virtual bool StartSuspended public virtual bool StartSuspended
{ {
get { return _startSuspended; } get { return _startSuspended; }
set set
{ {
ThrowIfReadOnly(); ThrowIfReadOnly();
_startSuspended = value; _startSuspended = value;
} }
} }
/// <summary> /// <summary>
/// Get/Set the default priority that a work item gets when it is enqueued /// Get/Set the default priority that a work item gets when it is enqueued
/// </summary> /// </summary>
public virtual WorkItemPriority WorkItemPriority public virtual WorkItemPriority WorkItemPriority
{ {
get { return _workItemPriority; } get { return _workItemPriority; }
set { _workItemPriority = value; } set { _workItemPriority = value; }
} }
/// <summary> /// <summary>
/// Get/Set the if QueueWorkItem of Action&lt;...&gt;/Func&lt;...&gt; fill the /// Get/Set the if QueueWorkItem of Action&lt;...&gt;/Func&lt;...&gt; fill the
/// arguments as an object array into the state of the work item. /// arguments as an object array into the state of the work item.
/// The arguments can be access later by IWorkItemResult.State. /// The arguments can be access later by IWorkItemResult.State.
/// </summary> /// </summary>
public virtual bool FillStateWithArgs public virtual bool FillStateWithArgs
{ {
get { return _fillStateWithArgs; } get { return _fillStateWithArgs; }
set set
{ {
ThrowIfReadOnly(); ThrowIfReadOnly();
_fillStateWithArgs = value; _fillStateWithArgs = value;
} }
} }
/// <summary> /// <summary>
/// Get a readonly version of this WIGStartInfo /// Get a readonly version of this WIGStartInfo
/// </summary> /// </summary>
/// <returns>Returns a readonly reference to this WIGStartInfoRO</returns> /// <returns>Returns a readonly reference to this WIGStartInfoRO</returns>
public WIGStartInfo AsReadOnly() public WIGStartInfo AsReadOnly()
{ {
return new WIGStartInfo(this) { _readOnly = true }; return new WIGStartInfo(this) { _readOnly = true };
} }
} }
} }

View File

@ -1,190 +1,190 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
namespace Amib.Threading.Internal namespace Amib.Threading.Internal
{ {
public partial class WorkItem public partial class WorkItem
{ {
#region WorkItemResult class #region WorkItemResult class
private class WorkItemResult : IWorkItemResult, IInternalWorkItemResult, IInternalWaitableResult private class WorkItemResult : IWorkItemResult, IInternalWorkItemResult, IInternalWaitableResult
{ {
/// <summary> /// <summary>
/// A back reference to the work item /// A back reference to the work item
/// </summary> /// </summary>
private readonly WorkItem _workItem; private readonly WorkItem _workItem;
public WorkItemResult(WorkItem workItem) public WorkItemResult(WorkItem workItem)
{ {
_workItem = workItem; _workItem = workItem;
} }
internal WorkItem GetWorkItem() internal WorkItem GetWorkItem()
{ {
return _workItem; return _workItem;
} }
#region IWorkItemResult Members #region IWorkItemResult Members
public bool IsCompleted public bool IsCompleted
{ {
get get
{ {
return _workItem.IsCompleted; return _workItem.IsCompleted;
} }
} }
public bool IsCanceled public bool IsCanceled
{ {
get get
{ {
return _workItem.IsCanceled; return _workItem.IsCanceled;
} }
} }
public object GetResult() public object GetResult()
{ {
return _workItem.GetResult(Timeout.Infinite, true, null); return _workItem.GetResult(Timeout.Infinite, true, null);
} }
public object GetResult(int millisecondsTimeout, bool exitContext) public object GetResult(int millisecondsTimeout, bool exitContext)
{ {
return _workItem.GetResult(millisecondsTimeout, exitContext, null); return _workItem.GetResult(millisecondsTimeout, exitContext, null);
} }
public object GetResult(TimeSpan timeout, bool exitContext) public object GetResult(TimeSpan timeout, bool exitContext)
{ {
return _workItem.GetResult((int)timeout.TotalMilliseconds, exitContext, null); return _workItem.GetResult((int)timeout.TotalMilliseconds, exitContext, null);
} }
public object GetResult(int millisecondsTimeout, bool exitContext, WaitHandle cancelWaitHandle) public object GetResult(int millisecondsTimeout, bool exitContext, WaitHandle cancelWaitHandle)
{ {
return _workItem.GetResult(millisecondsTimeout, exitContext, cancelWaitHandle); return _workItem.GetResult(millisecondsTimeout, exitContext, cancelWaitHandle);
} }
public object GetResult(TimeSpan timeout, bool exitContext, WaitHandle cancelWaitHandle) public object GetResult(TimeSpan timeout, bool exitContext, WaitHandle cancelWaitHandle)
{ {
return _workItem.GetResult((int)timeout.TotalMilliseconds, exitContext, cancelWaitHandle); return _workItem.GetResult((int)timeout.TotalMilliseconds, exitContext, cancelWaitHandle);
} }
public object GetResult(out Exception e) public object GetResult(out Exception e)
{ {
return _workItem.GetResult(Timeout.Infinite, true, null, out e); return _workItem.GetResult(Timeout.Infinite, true, null, out e);
} }
public object GetResult(int millisecondsTimeout, bool exitContext, out Exception e) public object GetResult(int millisecondsTimeout, bool exitContext, out Exception e)
{ {
return _workItem.GetResult(millisecondsTimeout, exitContext, null, out e); return _workItem.GetResult(millisecondsTimeout, exitContext, null, out e);
} }
public object GetResult(TimeSpan timeout, bool exitContext, out Exception e) public object GetResult(TimeSpan timeout, bool exitContext, out Exception e)
{ {
return _workItem.GetResult((int)timeout.TotalMilliseconds, exitContext, null, out e); return _workItem.GetResult((int)timeout.TotalMilliseconds, exitContext, null, out e);
} }
public object GetResult(int millisecondsTimeout, bool exitContext, WaitHandle cancelWaitHandle, out Exception e) public object GetResult(int millisecondsTimeout, bool exitContext, WaitHandle cancelWaitHandle, out Exception e)
{ {
return _workItem.GetResult(millisecondsTimeout, exitContext, cancelWaitHandle, out e); return _workItem.GetResult(millisecondsTimeout, exitContext, cancelWaitHandle, out e);
} }
public object GetResult(TimeSpan timeout, bool exitContext, WaitHandle cancelWaitHandle, out Exception e) public object GetResult(TimeSpan timeout, bool exitContext, WaitHandle cancelWaitHandle, out Exception e)
{ {
return _workItem.GetResult((int)timeout.TotalMilliseconds, exitContext, cancelWaitHandle, out e); return _workItem.GetResult((int)timeout.TotalMilliseconds, exitContext, cancelWaitHandle, out e);
} }
public bool Cancel() public bool Cancel()
{ {
return Cancel(false); return Cancel(false);
} }
public bool Cancel(bool abortExecution) public bool Cancel(bool abortExecution)
{ {
return _workItem.Cancel(abortExecution); return _workItem.Cancel(abortExecution);
} }
public object State public object State
{ {
get get
{ {
return _workItem._state; return _workItem._state;
} }
} }
public WorkItemPriority WorkItemPriority public WorkItemPriority WorkItemPriority
{ {
get get
{ {
return _workItem._workItemInfo.WorkItemPriority; return _workItem._workItemInfo.WorkItemPriority;
} }
} }
/// <summary> /// <summary>
/// Return the result, same as GetResult() /// Return the result, same as GetResult()
/// </summary> /// </summary>
public object Result public object Result
{ {
get { return GetResult(); } get { return GetResult(); }
} }
/// <summary> /// <summary>
/// Returns the exception if occured otherwise returns null. /// Returns the exception if occured otherwise returns null.
/// This value is valid only after the work item completed, /// This value is valid only after the work item completed,
/// before that it is always null. /// before that it is always null.
/// </summary> /// </summary>
public object Exception public object Exception
{ {
get { return _workItem._exception; } get { return _workItem._exception; }
} }
#endregion #endregion
#region IInternalWorkItemResult Members #region IInternalWorkItemResult Members
public event WorkItemStateCallback OnWorkItemStarted public event WorkItemStateCallback OnWorkItemStarted
{ {
add add
{ {
_workItem.OnWorkItemStarted += value; _workItem.OnWorkItemStarted += value;
} }
remove remove
{ {
_workItem.OnWorkItemStarted -= value; _workItem.OnWorkItemStarted -= value;
} }
} }
public event WorkItemStateCallback OnWorkItemCompleted public event WorkItemStateCallback OnWorkItemCompleted
{ {
add add
{ {
_workItem.OnWorkItemCompleted += value; _workItem.OnWorkItemCompleted += value;
} }
remove remove
{ {
_workItem.OnWorkItemCompleted -= value; _workItem.OnWorkItemCompleted -= value;
} }
} }
#endregion #endregion
#region IInternalWorkItemResult Members #region IInternalWorkItemResult Members
public IWorkItemResult GetWorkItemResult() public IWorkItemResult GetWorkItemResult()
{ {
return this; return this;
} }
public IWorkItemResult<TResult> GetWorkItemResultT<TResult>() public IWorkItemResult<TResult> GetWorkItemResultT<TResult>()
{ {
return new WorkItemResultTWrapper<TResult>(this); return new WorkItemResultTWrapper<TResult>(this);
} }
#endregion #endregion
} }
#endregion #endregion
} }
} }

View File

@ -1,343 +1,343 @@
using System; using System;
namespace Amib.Threading.Internal namespace Amib.Threading.Internal
{ {
#region WorkItemFactory class #region WorkItemFactory class
public class WorkItemFactory public class WorkItemFactory
{ {
/// <summary> /// <summary>
/// Create a new work item /// Create a new work item
/// </summary> /// </summary>
/// <param name="workItemsGroup">The WorkItemsGroup of this workitem</param> /// <param name="workItemsGroup">The WorkItemsGroup of this workitem</param>
/// <param name="wigStartInfo">Work item group start information</param> /// <param name="wigStartInfo">Work item group start information</param>
/// <param name="callback">A callback to execute</param> /// <param name="callback">A callback to execute</param>
/// <returns>Returns a work item</returns> /// <returns>Returns a work item</returns>
public static WorkItem CreateWorkItem( public static WorkItem CreateWorkItem(
IWorkItemsGroup workItemsGroup, IWorkItemsGroup workItemsGroup,
WIGStartInfo wigStartInfo, WIGStartInfo wigStartInfo,
WorkItemCallback callback) WorkItemCallback callback)
{ {
return CreateWorkItem(workItemsGroup, wigStartInfo, callback, null); return CreateWorkItem(workItemsGroup, wigStartInfo, callback, null);
} }
/// <summary> /// <summary>
/// Create a new work item /// Create a new work item
/// </summary> /// </summary>
/// <param name="workItemsGroup">The WorkItemsGroup of this workitem</param> /// <param name="workItemsGroup">The WorkItemsGroup of this workitem</param>
/// <param name="wigStartInfo">Work item group start information</param> /// <param name="wigStartInfo">Work item group start information</param>
/// <param name="callback">A callback to execute</param> /// <param name="callback">A callback to execute</param>
/// <param name="workItemPriority">The priority of the work item</param> /// <param name="workItemPriority">The priority of the work item</param>
/// <returns>Returns a work item</returns> /// <returns>Returns a work item</returns>
public static WorkItem CreateWorkItem( public static WorkItem CreateWorkItem(
IWorkItemsGroup workItemsGroup, IWorkItemsGroup workItemsGroup,
WIGStartInfo wigStartInfo, WIGStartInfo wigStartInfo,
WorkItemCallback callback, WorkItemCallback callback,
WorkItemPriority workItemPriority) WorkItemPriority workItemPriority)
{ {
return CreateWorkItem(workItemsGroup, wigStartInfo, callback, null, workItemPriority); return CreateWorkItem(workItemsGroup, wigStartInfo, callback, null, workItemPriority);
} }
/// <summary> /// <summary>
/// Create a new work item /// Create a new work item
/// </summary> /// </summary>
/// <param name="workItemsGroup">The WorkItemsGroup of this workitem</param> /// <param name="workItemsGroup">The WorkItemsGroup of this workitem</param>
/// <param name="wigStartInfo">Work item group start information</param> /// <param name="wigStartInfo">Work item group start information</param>
/// <param name="workItemInfo">Work item info</param> /// <param name="workItemInfo">Work item info</param>
/// <param name="callback">A callback to execute</param> /// <param name="callback">A callback to execute</param>
/// <returns>Returns a work item</returns> /// <returns>Returns a work item</returns>
public static WorkItem CreateWorkItem( public static WorkItem CreateWorkItem(
IWorkItemsGroup workItemsGroup, IWorkItemsGroup workItemsGroup,
WIGStartInfo wigStartInfo, WIGStartInfo wigStartInfo,
WorkItemInfo workItemInfo, WorkItemInfo workItemInfo,
WorkItemCallback callback) WorkItemCallback callback)
{ {
return CreateWorkItem( return CreateWorkItem(
workItemsGroup, workItemsGroup,
wigStartInfo, wigStartInfo,
workItemInfo, workItemInfo,
callback, callback,
null); null);
} }
/// <summary> /// <summary>
/// Create a new work item /// Create a new work item
/// </summary> /// </summary>
/// <param name="workItemsGroup">The WorkItemsGroup of this workitem</param> /// <param name="workItemsGroup">The WorkItemsGroup of this workitem</param>
/// <param name="wigStartInfo">Work item group start information</param> /// <param name="wigStartInfo">Work item group start information</param>
/// <param name="callback">A callback to execute</param> /// <param name="callback">A callback to execute</param>
/// <param name="state"> /// <param name="state">
/// 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.
/// </param> /// </param>
/// <returns>Returns a work item</returns> /// <returns>Returns a work item</returns>
public static WorkItem CreateWorkItem( public static WorkItem CreateWorkItem(
IWorkItemsGroup workItemsGroup, IWorkItemsGroup workItemsGroup,
WIGStartInfo wigStartInfo, WIGStartInfo wigStartInfo,
WorkItemCallback callback, WorkItemCallback callback,
object state) object state)
{ {
ValidateCallback(callback); ValidateCallback(callback);
WorkItemInfo workItemInfo = new WorkItemInfo(); WorkItemInfo workItemInfo = new WorkItemInfo();
workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext; workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext;
workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext; workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext;
workItemInfo.PostExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback; workItemInfo.PostExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback;
workItemInfo.CallToPostExecute = wigStartInfo.CallToPostExecute; workItemInfo.CallToPostExecute = wigStartInfo.CallToPostExecute;
workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects; workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;
workItemInfo.WorkItemPriority = wigStartInfo.WorkItemPriority; workItemInfo.WorkItemPriority = wigStartInfo.WorkItemPriority;
WorkItem workItem = new WorkItem( WorkItem workItem = new WorkItem(
workItemsGroup, workItemsGroup,
workItemInfo, workItemInfo,
callback, callback,
state); state);
return workItem; return workItem;
} }
/// <summary> /// <summary>
/// Create a new work item /// Create a new work item
/// </summary> /// </summary>
/// <param name="workItemsGroup">The work items group</param> /// <param name="workItemsGroup">The work items group</param>
/// <param name="wigStartInfo">Work item group start information</param> /// <param name="wigStartInfo">Work item group start information</param>
/// <param name="callback">A callback to execute</param> /// <param name="callback">A callback to execute</param>
/// <param name="state"> /// <param name="state">
/// 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.
/// </param> /// </param>
/// <param name="workItemPriority">The work item priority</param> /// <param name="workItemPriority">The work item priority</param>
/// <returns>Returns a work item</returns> /// <returns>Returns a work item</returns>
public static WorkItem CreateWorkItem( public static WorkItem CreateWorkItem(
IWorkItemsGroup workItemsGroup, IWorkItemsGroup workItemsGroup,
WIGStartInfo wigStartInfo, WIGStartInfo wigStartInfo,
WorkItemCallback callback, WorkItemCallback callback,
object state, object state,
WorkItemPriority workItemPriority) WorkItemPriority workItemPriority)
{ {
ValidateCallback(callback); ValidateCallback(callback);
WorkItemInfo workItemInfo = new WorkItemInfo(); WorkItemInfo workItemInfo = new WorkItemInfo();
workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext; workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext;
workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext; workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext;
workItemInfo.PostExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback; workItemInfo.PostExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback;
workItemInfo.CallToPostExecute = wigStartInfo.CallToPostExecute; workItemInfo.CallToPostExecute = wigStartInfo.CallToPostExecute;
workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects; workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;
workItemInfo.WorkItemPriority = workItemPriority; workItemInfo.WorkItemPriority = workItemPriority;
WorkItem workItem = new WorkItem( WorkItem workItem = new WorkItem(
workItemsGroup, workItemsGroup,
workItemInfo, workItemInfo,
callback, callback,
state); state);
return workItem; return workItem;
} }
/// <summary> /// <summary>
/// Create a new work item /// Create a new work item
/// </summary> /// </summary>
/// <param name="workItemsGroup">The work items group</param> /// <param name="workItemsGroup">The work items group</param>
/// <param name="wigStartInfo">Work item group start information</param> /// <param name="wigStartInfo">Work item group start information</param>
/// <param name="workItemInfo">Work item information</param> /// <param name="workItemInfo">Work item information</param>
/// <param name="callback">A callback to execute</param> /// <param name="callback">A callback to execute</param>
/// <param name="state"> /// <param name="state">
/// 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.
/// </param> /// </param>
/// <returns>Returns a work item</returns> /// <returns>Returns a work item</returns>
public static WorkItem CreateWorkItem( public static WorkItem CreateWorkItem(
IWorkItemsGroup workItemsGroup, IWorkItemsGroup workItemsGroup,
WIGStartInfo wigStartInfo, WIGStartInfo wigStartInfo,
WorkItemInfo workItemInfo, WorkItemInfo workItemInfo,
WorkItemCallback callback, WorkItemCallback callback,
object state) object state)
{ {
ValidateCallback(callback); ValidateCallback(callback);
ValidateCallback(workItemInfo.PostExecuteWorkItemCallback); ValidateCallback(workItemInfo.PostExecuteWorkItemCallback);
WorkItem workItem = new WorkItem( WorkItem workItem = new WorkItem(
workItemsGroup, workItemsGroup,
new WorkItemInfo(workItemInfo), new WorkItemInfo(workItemInfo),
callback, callback,
state); state);
return workItem; return workItem;
} }
/// <summary> /// <summary>
/// Create a new work item /// Create a new work item
/// </summary> /// </summary>
/// <param name="workItemsGroup">The work items group</param> /// <param name="workItemsGroup">The work items group</param>
/// <param name="wigStartInfo">Work item group start information</param> /// <param name="wigStartInfo">Work item group start information</param>
/// <param name="callback">A callback to execute</param> /// <param name="callback">A callback to execute</param>
/// <param name="state"> /// <param name="state">
/// 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.
/// </param> /// </param>
/// <param name="postExecuteWorkItemCallback"> /// <param name="postExecuteWorkItemCallback">
/// A delegate to call after the callback completion /// A delegate to call after the callback completion
/// </param> /// </param>
/// <returns>Returns a work item</returns> /// <returns>Returns a work item</returns>
public static WorkItem CreateWorkItem( public static WorkItem CreateWorkItem(
IWorkItemsGroup workItemsGroup, IWorkItemsGroup workItemsGroup,
WIGStartInfo wigStartInfo, WIGStartInfo wigStartInfo,
WorkItemCallback callback, WorkItemCallback callback,
object state, object state,
PostExecuteWorkItemCallback postExecuteWorkItemCallback) PostExecuteWorkItemCallback postExecuteWorkItemCallback)
{ {
ValidateCallback(callback); ValidateCallback(callback);
ValidateCallback(postExecuteWorkItemCallback); ValidateCallback(postExecuteWorkItemCallback);
WorkItemInfo workItemInfo = new WorkItemInfo(); WorkItemInfo workItemInfo = new WorkItemInfo();
workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext; workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext;
workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext; workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext;
workItemInfo.PostExecuteWorkItemCallback = postExecuteWorkItemCallback; workItemInfo.PostExecuteWorkItemCallback = postExecuteWorkItemCallback;
workItemInfo.CallToPostExecute = wigStartInfo.CallToPostExecute; workItemInfo.CallToPostExecute = wigStartInfo.CallToPostExecute;
workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects; workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;
workItemInfo.WorkItemPriority = wigStartInfo.WorkItemPriority; workItemInfo.WorkItemPriority = wigStartInfo.WorkItemPriority;
WorkItem workItem = new WorkItem( WorkItem workItem = new WorkItem(
workItemsGroup, workItemsGroup,
workItemInfo, workItemInfo,
callback, callback,
state); state);
return workItem; return workItem;
} }
/// <summary> /// <summary>
/// Create a new work item /// Create a new work item
/// </summary> /// </summary>
/// <param name="workItemsGroup">The work items group</param> /// <param name="workItemsGroup">The work items group</param>
/// <param name="wigStartInfo">Work item group start information</param> /// <param name="wigStartInfo">Work item group start information</param>
/// <param name="callback">A callback to execute</param> /// <param name="callback">A callback to execute</param>
/// <param name="state"> /// <param name="state">
/// 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.
/// </param> /// </param>
/// <param name="postExecuteWorkItemCallback"> /// <param name="postExecuteWorkItemCallback">
/// A delegate to call after the callback completion /// A delegate to call after the callback completion
/// </param> /// </param>
/// <param name="workItemPriority">The work item priority</param> /// <param name="workItemPriority">The work item priority</param>
/// <returns>Returns a work item</returns> /// <returns>Returns a work item</returns>
public static WorkItem CreateWorkItem( public static WorkItem CreateWorkItem(
IWorkItemsGroup workItemsGroup, IWorkItemsGroup workItemsGroup,
WIGStartInfo wigStartInfo, WIGStartInfo wigStartInfo,
WorkItemCallback callback, WorkItemCallback callback,
object state, object state,
PostExecuteWorkItemCallback postExecuteWorkItemCallback, PostExecuteWorkItemCallback postExecuteWorkItemCallback,
WorkItemPriority workItemPriority) WorkItemPriority workItemPriority)
{ {
ValidateCallback(callback); ValidateCallback(callback);
ValidateCallback(postExecuteWorkItemCallback); ValidateCallback(postExecuteWorkItemCallback);
WorkItemInfo workItemInfo = new WorkItemInfo(); WorkItemInfo workItemInfo = new WorkItemInfo();
workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext; workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext;
workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext; workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext;
workItemInfo.PostExecuteWorkItemCallback = postExecuteWorkItemCallback; workItemInfo.PostExecuteWorkItemCallback = postExecuteWorkItemCallback;
workItemInfo.CallToPostExecute = wigStartInfo.CallToPostExecute; workItemInfo.CallToPostExecute = wigStartInfo.CallToPostExecute;
workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects; workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;
workItemInfo.WorkItemPriority = workItemPriority; workItemInfo.WorkItemPriority = workItemPriority;
WorkItem workItem = new WorkItem( WorkItem workItem = new WorkItem(
workItemsGroup, workItemsGroup,
workItemInfo, workItemInfo,
callback, callback,
state); state);
return workItem; return workItem;
} }
/// <summary> /// <summary>
/// Create a new work item /// Create a new work item
/// </summary> /// </summary>
/// <param name="workItemsGroup">The work items group</param> /// <param name="workItemsGroup">The work items group</param>
/// <param name="wigStartInfo">Work item group start information</param> /// <param name="wigStartInfo">Work item group start information</param>
/// <param name="callback">A callback to execute</param> /// <param name="callback">A callback to execute</param>
/// <param name="state"> /// <param name="state">
/// 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.
/// </param> /// </param>
/// <param name="postExecuteWorkItemCallback"> /// <param name="postExecuteWorkItemCallback">
/// A delegate to call after the callback completion /// A delegate to call after the callback completion
/// </param> /// </param>
/// <param name="callToPostExecute">Indicates on which cases to call to the post execute callback</param> /// <param name="callToPostExecute">Indicates on which cases to call to the post execute callback</param>
/// <returns>Returns a work item</returns> /// <returns>Returns a work item</returns>
public static WorkItem CreateWorkItem( public static WorkItem CreateWorkItem(
IWorkItemsGroup workItemsGroup, IWorkItemsGroup workItemsGroup,
WIGStartInfo wigStartInfo, WIGStartInfo wigStartInfo,
WorkItemCallback callback, WorkItemCallback callback,
object state, object state,
PostExecuteWorkItemCallback postExecuteWorkItemCallback, PostExecuteWorkItemCallback postExecuteWorkItemCallback,
CallToPostExecute callToPostExecute) CallToPostExecute callToPostExecute)
{ {
ValidateCallback(callback); ValidateCallback(callback);
ValidateCallback(postExecuteWorkItemCallback); ValidateCallback(postExecuteWorkItemCallback);
WorkItemInfo workItemInfo = new WorkItemInfo(); WorkItemInfo workItemInfo = new WorkItemInfo();
workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext; workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext;
workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext; workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext;
workItemInfo.PostExecuteWorkItemCallback = postExecuteWorkItemCallback; workItemInfo.PostExecuteWorkItemCallback = postExecuteWorkItemCallback;
workItemInfo.CallToPostExecute = callToPostExecute; workItemInfo.CallToPostExecute = callToPostExecute;
workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects; workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;
workItemInfo.WorkItemPriority = wigStartInfo.WorkItemPriority; workItemInfo.WorkItemPriority = wigStartInfo.WorkItemPriority;
WorkItem workItem = new WorkItem( WorkItem workItem = new WorkItem(
workItemsGroup, workItemsGroup,
workItemInfo, workItemInfo,
callback, callback,
state); state);
return workItem; return workItem;
} }
/// <summary> /// <summary>
/// Create a new work item /// Create a new work item
/// </summary> /// </summary>
/// <param name="workItemsGroup">The work items group</param> /// <param name="workItemsGroup">The work items group</param>
/// <param name="wigStartInfo">Work item group start information</param> /// <param name="wigStartInfo">Work item group start information</param>
/// <param name="callback">A callback to execute</param> /// <param name="callback">A callback to execute</param>
/// <param name="state"> /// <param name="state">
/// 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.
/// </param> /// </param>
/// <param name="postExecuteWorkItemCallback"> /// <param name="postExecuteWorkItemCallback">
/// A delegate to call after the callback completion /// A delegate to call after the callback completion
/// </param> /// </param>
/// <param name="callToPostExecute">Indicates on which cases to call to the post execute callback</param> /// <param name="callToPostExecute">Indicates on which cases to call to the post execute callback</param>
/// <param name="workItemPriority">The work item priority</param> /// <param name="workItemPriority">The work item priority</param>
/// <returns>Returns a work item</returns> /// <returns>Returns a work item</returns>
public static WorkItem CreateWorkItem( public static WorkItem CreateWorkItem(
IWorkItemsGroup workItemsGroup, IWorkItemsGroup workItemsGroup,
WIGStartInfo wigStartInfo, WIGStartInfo wigStartInfo,
WorkItemCallback callback, WorkItemCallback callback,
object state, object state,
PostExecuteWorkItemCallback postExecuteWorkItemCallback, PostExecuteWorkItemCallback postExecuteWorkItemCallback,
CallToPostExecute callToPostExecute, CallToPostExecute callToPostExecute,
WorkItemPriority workItemPriority) WorkItemPriority workItemPriority)
{ {
ValidateCallback(callback); ValidateCallback(callback);
ValidateCallback(postExecuteWorkItemCallback); ValidateCallback(postExecuteWorkItemCallback);
WorkItemInfo workItemInfo = new WorkItemInfo(); WorkItemInfo workItemInfo = new WorkItemInfo();
workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext; workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext;
workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext; workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext;
workItemInfo.PostExecuteWorkItemCallback = postExecuteWorkItemCallback; workItemInfo.PostExecuteWorkItemCallback = postExecuteWorkItemCallback;
workItemInfo.CallToPostExecute = callToPostExecute; workItemInfo.CallToPostExecute = callToPostExecute;
workItemInfo.WorkItemPriority = workItemPriority; workItemInfo.WorkItemPriority = workItemPriority;
workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects; workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;
WorkItem workItem = new WorkItem( WorkItem workItem = new WorkItem(
workItemsGroup, workItemsGroup,
workItemInfo, workItemInfo,
callback, callback,
state); state);
return workItem; return workItem;
} }
private static void ValidateCallback(Delegate callback) private static void ValidateCallback(Delegate callback)
{ {
if (callback != null && callback.GetInvocationList().Length > 1) if (callback != null && callback.GetInvocationList().Length > 1)
{ {
throw new NotSupportedException("SmartThreadPool doesn't support delegates chains"); throw new NotSupportedException("SmartThreadPool doesn't support delegates chains");
} }
} }
} }
#endregion #endregion
} }

View File

@ -1,69 +1,69 @@
namespace Amib.Threading namespace Amib.Threading
{ {
#region WorkItemInfo class #region WorkItemInfo class
/// <summary> /// <summary>
/// Summary description for WorkItemInfo. /// Summary description for WorkItemInfo.
/// </summary> /// </summary>
public class WorkItemInfo public class WorkItemInfo
{ {
public WorkItemInfo() public WorkItemInfo()
{ {
UseCallerCallContext = SmartThreadPool.DefaultUseCallerCallContext; UseCallerCallContext = SmartThreadPool.DefaultUseCallerCallContext;
UseCallerHttpContext = SmartThreadPool.DefaultUseCallerHttpContext; UseCallerHttpContext = SmartThreadPool.DefaultUseCallerHttpContext;
DisposeOfStateObjects = SmartThreadPool.DefaultDisposeOfStateObjects; DisposeOfStateObjects = SmartThreadPool.DefaultDisposeOfStateObjects;
CallToPostExecute = SmartThreadPool.DefaultCallToPostExecute; CallToPostExecute = SmartThreadPool.DefaultCallToPostExecute;
PostExecuteWorkItemCallback = SmartThreadPool.DefaultPostExecuteWorkItemCallback; PostExecuteWorkItemCallback = SmartThreadPool.DefaultPostExecuteWorkItemCallback;
WorkItemPriority = SmartThreadPool.DefaultWorkItemPriority; WorkItemPriority = SmartThreadPool.DefaultWorkItemPriority;
} }
public WorkItemInfo(WorkItemInfo workItemInfo) public WorkItemInfo(WorkItemInfo workItemInfo)
{ {
UseCallerCallContext = workItemInfo.UseCallerCallContext; UseCallerCallContext = workItemInfo.UseCallerCallContext;
UseCallerHttpContext = workItemInfo.UseCallerHttpContext; UseCallerHttpContext = workItemInfo.UseCallerHttpContext;
DisposeOfStateObjects = workItemInfo.DisposeOfStateObjects; DisposeOfStateObjects = workItemInfo.DisposeOfStateObjects;
CallToPostExecute = workItemInfo.CallToPostExecute; CallToPostExecute = workItemInfo.CallToPostExecute;
PostExecuteWorkItemCallback = workItemInfo.PostExecuteWorkItemCallback; PostExecuteWorkItemCallback = workItemInfo.PostExecuteWorkItemCallback;
WorkItemPriority = workItemInfo.WorkItemPriority; WorkItemPriority = workItemInfo.WorkItemPriority;
Timeout = workItemInfo.Timeout; Timeout = workItemInfo.Timeout;
} }
/// <summary> /// <summary>
/// Get/Set if to use the caller's security context /// Get/Set if to use the caller's security context
/// </summary> /// </summary>
public bool UseCallerCallContext { get; set; } public bool UseCallerCallContext { get; set; }
/// <summary> /// <summary>
/// Get/Set if to use the caller's HTTP context /// Get/Set if to use the caller's HTTP context
/// </summary> /// </summary>
public bool UseCallerHttpContext { get; set; } public bool UseCallerHttpContext { get; set; }
/// <summary> /// <summary>
/// Get/Set if to dispose of the state object of a work item /// Get/Set if to dispose of the state object of a work item
/// </summary> /// </summary>
public bool DisposeOfStateObjects { get; set; } public bool DisposeOfStateObjects { get; set; }
/// <summary> /// <summary>
/// Get/Set the run the post execute options /// Get/Set the run the post execute options
/// </summary> /// </summary>
public CallToPostExecute CallToPostExecute { get; set; } public CallToPostExecute CallToPostExecute { get; set; }
/// <summary> /// <summary>
/// Get/Set the post execute callback /// Get/Set the post execute callback
/// </summary> /// </summary>
public PostExecuteWorkItemCallback PostExecuteWorkItemCallback { get; set; } public PostExecuteWorkItemCallback PostExecuteWorkItemCallback { get; set; }
/// <summary> /// <summary>
/// Get/Set the work item's priority /// Get/Set the work item's priority
/// </summary> /// </summary>
public WorkItemPriority WorkItemPriority { get; set; } public WorkItemPriority WorkItemPriority { get; set; }
/// <summary> /// <summary>
/// Get/Set the work item's timout in milliseconds. /// Get/Set the work item's timout in milliseconds.
/// This is a passive timout. When the timout expires the work item won't be actively aborted! /// This is a passive timout. When the timout expires the work item won't be actively aborted!
/// </summary> /// </summary>
public long Timeout { get; set; } public long Timeout { get; set; }
} }
#endregion #endregion
} }

View File

@ -1,128 +1,128 @@
using System; using System;
using System.Threading; using System.Threading;
namespace Amib.Threading.Internal namespace Amib.Threading.Internal
{ {
#region WorkItemResultTWrapper class #region WorkItemResultTWrapper class
internal class WorkItemResultTWrapper<TResult> : IWorkItemResult<TResult>, IInternalWaitableResult internal class WorkItemResultTWrapper<TResult> : IWorkItemResult<TResult>, IInternalWaitableResult
{ {
private readonly IWorkItemResult _workItemResult; private readonly IWorkItemResult _workItemResult;
public WorkItemResultTWrapper(IWorkItemResult workItemResult) public WorkItemResultTWrapper(IWorkItemResult workItemResult)
{ {
_workItemResult = workItemResult; _workItemResult = workItemResult;
} }
#region IWorkItemResult<TResult> Members #region IWorkItemResult<TResult> Members
public TResult GetResult() public TResult GetResult()
{ {
return (TResult)_workItemResult.GetResult(); return (TResult)_workItemResult.GetResult();
} }
public TResult GetResult(int millisecondsTimeout, bool exitContext) public TResult GetResult(int millisecondsTimeout, bool exitContext)
{ {
return (TResult)_workItemResult.GetResult(millisecondsTimeout, exitContext); return (TResult)_workItemResult.GetResult(millisecondsTimeout, exitContext);
} }
public TResult GetResult(TimeSpan timeout, bool exitContext) public TResult GetResult(TimeSpan timeout, bool exitContext)
{ {
return (TResult)_workItemResult.GetResult(timeout, exitContext); return (TResult)_workItemResult.GetResult(timeout, exitContext);
} }
public TResult GetResult(int millisecondsTimeout, bool exitContext, WaitHandle cancelWaitHandle) public TResult GetResult(int millisecondsTimeout, bool exitContext, WaitHandle cancelWaitHandle)
{ {
return (TResult)_workItemResult.GetResult(millisecondsTimeout, exitContext, cancelWaitHandle); return (TResult)_workItemResult.GetResult(millisecondsTimeout, exitContext, cancelWaitHandle);
} }
public TResult GetResult(TimeSpan timeout, bool exitContext, WaitHandle cancelWaitHandle) public TResult GetResult(TimeSpan timeout, bool exitContext, WaitHandle cancelWaitHandle)
{ {
return (TResult)_workItemResult.GetResult(timeout, exitContext, cancelWaitHandle); return (TResult)_workItemResult.GetResult(timeout, exitContext, cancelWaitHandle);
} }
public TResult GetResult(out Exception e) public TResult GetResult(out Exception e)
{ {
return (TResult)_workItemResult.GetResult(out e); return (TResult)_workItemResult.GetResult(out e);
} }
public TResult GetResult(int millisecondsTimeout, bool exitContext, out Exception e) public TResult GetResult(int millisecondsTimeout, bool exitContext, out Exception e)
{ {
return (TResult)_workItemResult.GetResult(millisecondsTimeout, exitContext, out e); return (TResult)_workItemResult.GetResult(millisecondsTimeout, exitContext, out e);
} }
public TResult GetResult(TimeSpan timeout, bool exitContext, out Exception e) public TResult GetResult(TimeSpan timeout, bool exitContext, out Exception e)
{ {
return (TResult)_workItemResult.GetResult(timeout, exitContext, out e); return (TResult)_workItemResult.GetResult(timeout, exitContext, out e);
} }
public TResult GetResult(int millisecondsTimeout, bool exitContext, WaitHandle cancelWaitHandle, out Exception e) public TResult GetResult(int millisecondsTimeout, bool exitContext, WaitHandle cancelWaitHandle, out Exception e)
{ {
return (TResult)_workItemResult.GetResult(millisecondsTimeout, exitContext, cancelWaitHandle, out e); return (TResult)_workItemResult.GetResult(millisecondsTimeout, exitContext, cancelWaitHandle, out e);
} }
public TResult GetResult(TimeSpan timeout, bool exitContext, WaitHandle cancelWaitHandle, out Exception e) public TResult GetResult(TimeSpan timeout, bool exitContext, WaitHandle cancelWaitHandle, out Exception e)
{ {
return (TResult)_workItemResult.GetResult(timeout, exitContext, cancelWaitHandle, out e); return (TResult)_workItemResult.GetResult(timeout, exitContext, cancelWaitHandle, out e);
} }
public bool IsCompleted public bool IsCompleted
{ {
get { return _workItemResult.IsCompleted; } get { return _workItemResult.IsCompleted; }
} }
public bool IsCanceled public bool IsCanceled
{ {
get { return _workItemResult.IsCanceled; } get { return _workItemResult.IsCanceled; }
} }
public object State public object State
{ {
get { return _workItemResult.State; } get { return _workItemResult.State; }
} }
public bool Cancel() public bool Cancel()
{ {
return _workItemResult.Cancel(); return _workItemResult.Cancel();
} }
public bool Cancel(bool abortExecution) public bool Cancel(bool abortExecution)
{ {
return _workItemResult.Cancel(abortExecution); return _workItemResult.Cancel(abortExecution);
} }
public WorkItemPriority WorkItemPriority public WorkItemPriority WorkItemPriority
{ {
get { return _workItemResult.WorkItemPriority; } get { return _workItemResult.WorkItemPriority; }
} }
public TResult Result public TResult Result
{ {
get { return (TResult)_workItemResult.Result; } get { return (TResult)_workItemResult.Result; }
} }
public object Exception public object Exception
{ {
get { return (TResult)_workItemResult.Exception; } get { return (TResult)_workItemResult.Exception; }
} }
#region IInternalWorkItemResult Members #region IInternalWorkItemResult Members
public IWorkItemResult GetWorkItemResult() public IWorkItemResult GetWorkItemResult()
{ {
return _workItemResult.GetWorkItemResult(); return _workItemResult.GetWorkItemResult();
} }
public IWorkItemResult<TRes> GetWorkItemResultT<TRes>() public IWorkItemResult<TRes> GetWorkItemResultT<TRes>()
{ {
return (IWorkItemResult<TRes>)this; return (IWorkItemResult<TRes>)this;
} }
#endregion #endregion
#endregion #endregion
} }
#endregion #endregion
} }

View File

@ -1,361 +1,361 @@
using System; using System;
using System.Threading; using System.Threading;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Diagnostics; using System.Diagnostics;
namespace Amib.Threading.Internal namespace Amib.Threading.Internal
{ {
#region WorkItemsGroup class #region WorkItemsGroup class
/// <summary> /// <summary>
/// Summary description for WorkItemsGroup. /// Summary description for WorkItemsGroup.
/// </summary> /// </summary>
public class WorkItemsGroup : WorkItemsGroupBase public class WorkItemsGroup : WorkItemsGroupBase
{ {
#region Private members #region Private members
private readonly object _lock = new object(); private readonly object _lock = new object();
/// <summary> /// <summary>
/// A reference to the SmartThreadPool instance that created this /// A reference to the SmartThreadPool instance that created this
/// WorkItemsGroup. /// WorkItemsGroup.
/// </summary> /// </summary>
private readonly SmartThreadPool _stp; private readonly SmartThreadPool _stp;
/// <summary> /// <summary>
/// The OnIdle event /// The OnIdle event
/// </summary> /// </summary>
private event WorkItemsGroupIdleHandler _onIdle; private event WorkItemsGroupIdleHandler _onIdle;
/// <summary> /// <summary>
/// A flag to indicate if the Work Items Group is now suspended. /// A flag to indicate if the Work Items Group is now suspended.
/// </summary> /// </summary>
private bool _isSuspended; private bool _isSuspended;
/// <summary> /// <summary>
/// Defines how many work items of this WorkItemsGroup can run at once. /// Defines how many work items of this WorkItemsGroup can run at once.
/// </summary> /// </summary>
private int _concurrency; private int _concurrency;
/// <summary> /// <summary>
/// Priority queue to hold work items before they are passed /// Priority queue to hold work items before they are passed
/// to the SmartThreadPool. /// to the SmartThreadPool.
/// </summary> /// </summary>
private readonly PriorityQueue _workItemsQueue; private readonly PriorityQueue _workItemsQueue;
/// <summary> /// <summary>
/// Indicate how many work items are waiting in the SmartThreadPool /// Indicate how many work items are waiting in the SmartThreadPool
/// queue. /// queue.
/// This value is used to apply the concurrency. /// This value is used to apply the concurrency.
/// </summary> /// </summary>
private int _workItemsInStpQueue; private int _workItemsInStpQueue;
/// <summary> /// <summary>
/// Indicate how many work items are currently running in the SmartThreadPool. /// 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. /// work items to the STP.
/// </summary> /// </summary>
private int _workItemsExecutingInStp = 0; private int _workItemsExecutingInStp = 0;
/// <summary> /// <summary>
/// WorkItemsGroup start information /// WorkItemsGroup start information
/// </summary> /// </summary>
private readonly WIGStartInfo _workItemsGroupStartInfo; private readonly WIGStartInfo _workItemsGroupStartInfo;
/// <summary> /// <summary>
/// Signaled when all of the WorkItemsGroup's work item completed. /// Signaled when all of the WorkItemsGroup's work item completed.
/// </summary> /// </summary>
//private readonly ManualResetEvent _isIdleWaitHandle = new ManualResetEvent(true); //private readonly ManualResetEvent _isIdleWaitHandle = new ManualResetEvent(true);
private readonly ManualResetEvent _isIdleWaitHandle = EventWaitHandleFactory.CreateManualResetEvent(true); private readonly ManualResetEvent _isIdleWaitHandle = EventWaitHandleFactory.CreateManualResetEvent(true);
/// <summary> /// <summary>
/// A common object for all the work items that this work items group /// A common object for all the work items that this work items group
/// generate so we can mark them to cancel in O(1) /// generate so we can mark them to cancel in O(1)
/// </summary> /// </summary>
private CanceledWorkItemsGroup _canceledWorkItemsGroup = new CanceledWorkItemsGroup(); private CanceledWorkItemsGroup _canceledWorkItemsGroup = new CanceledWorkItemsGroup();
#endregion #endregion
#region Construction #region Construction
public WorkItemsGroup( public WorkItemsGroup(
SmartThreadPool stp, SmartThreadPool stp,
int concurrency, int concurrency,
WIGStartInfo wigStartInfo) WIGStartInfo wigStartInfo)
{ {
if (concurrency <= 0) if (concurrency <= 0)
{ {
throw new ArgumentOutOfRangeException( throw new ArgumentOutOfRangeException(
"concurrency", "concurrency",
#if !(_WINDOWS_CE) && !(_SILVERLIGHT) && !(WINDOWS_PHONE) #if !(_WINDOWS_CE) && !(_SILVERLIGHT) && !(WINDOWS_PHONE)
concurrency, concurrency,
#endif #endif
"concurrency must be greater than zero"); "concurrency must be greater than zero");
} }
_stp = stp; _stp = stp;
_concurrency = concurrency; _concurrency = concurrency;
_workItemsGroupStartInfo = new WIGStartInfo(wigStartInfo).AsReadOnly(); _workItemsGroupStartInfo = new WIGStartInfo(wigStartInfo).AsReadOnly();
_workItemsQueue = new PriorityQueue(); _workItemsQueue = new PriorityQueue();
Name = "WorkItemsGroup"; Name = "WorkItemsGroup";
// The _workItemsInStpQueue gets the number of currently executing work items, // The _workItemsInStpQueue gets the number of currently executing work items,
// because once a work item is executing, it cannot be cancelled. // because once a work item is executing, it cannot be cancelled.
_workItemsInStpQueue = _workItemsExecutingInStp; _workItemsInStpQueue = _workItemsExecutingInStp;
_isSuspended = _workItemsGroupStartInfo.StartSuspended; _isSuspended = _workItemsGroupStartInfo.StartSuspended;
} }
#endregion #endregion
#region WorkItemsGroupBase Overrides #region WorkItemsGroupBase Overrides
public override int Concurrency public override int Concurrency
{ {
get { return _concurrency; } get { return _concurrency; }
set set
{ {
Debug.Assert(value > 0); Debug.Assert(value > 0);
int diff = value - _concurrency; int diff = value - _concurrency;
_concurrency = value; _concurrency = value;
if (diff > 0) if (diff > 0)
{ {
EnqueueToSTPNextNWorkItem(diff); EnqueueToSTPNextNWorkItem(diff);
} }
} }
} }
public override int WaitingCallbacks public override int WaitingCallbacks
{ {
get { return _workItemsQueue.Count; } get { return _workItemsQueue.Count; }
} }
public override object[] GetStates() public override object[] GetStates()
{ {
lock (_lock) lock (_lock)
{ {
object[] states = new object[_workItemsQueue.Count]; object[] states = new object[_workItemsQueue.Count];
int i = 0; int i = 0;
foreach (WorkItem workItem in _workItemsQueue) foreach (WorkItem workItem in _workItemsQueue)
{ {
states[i] = workItem.GetWorkItemResult().State; states[i] = workItem.GetWorkItemResult().State;
++i; ++i;
} }
return states; return states;
} }
} }
/// <summary> /// <summary>
/// WorkItemsGroup start information /// WorkItemsGroup start information
/// </summary> /// </summary>
public override WIGStartInfo WIGStartInfo public override WIGStartInfo WIGStartInfo
{ {
get { return _workItemsGroupStartInfo; } get { return _workItemsGroupStartInfo; }
} }
/// <summary> /// <summary>
/// Start the Work Items Group if it was started suspended /// Start the Work Items Group if it was started suspended
/// </summary> /// </summary>
public override void Start() public override void Start()
{ {
// If the Work Items Group already started then quit // If the Work Items Group already started then quit
if (!_isSuspended) if (!_isSuspended)
{ {
return; return;
} }
_isSuspended = false; _isSuspended = false;
EnqueueToSTPNextNWorkItem(Math.Min(_workItemsQueue.Count, _concurrency)); EnqueueToSTPNextNWorkItem(Math.Min(_workItemsQueue.Count, _concurrency));
} }
public override void Cancel(bool abortExecution) public override void Cancel(bool abortExecution)
{ {
lock (_lock) lock (_lock)
{ {
_canceledWorkItemsGroup.IsCanceled = true; _canceledWorkItemsGroup.IsCanceled = true;
_workItemsQueue.Clear(); _workItemsQueue.Clear();
_workItemsInStpQueue = 0; _workItemsInStpQueue = 0;
_canceledWorkItemsGroup = new CanceledWorkItemsGroup(); _canceledWorkItemsGroup = new CanceledWorkItemsGroup();
} }
if (abortExecution) if (abortExecution)
{ {
_stp.CancelAbortWorkItemsGroup(this); _stp.CancelAbortWorkItemsGroup(this);
} }
} }
/// <summary> /// <summary>
/// Wait for the thread pool to be idle /// Wait for the thread pool to be idle
/// </summary> /// </summary>
public override bool WaitForIdle(int millisecondsTimeout) public override bool WaitForIdle(int millisecondsTimeout)
{ {
SmartThreadPool.ValidateWorkItemsGroupWaitForIdle(this); SmartThreadPool.ValidateWorkItemsGroupWaitForIdle(this);
return STPEventWaitHandle.WaitOne(_isIdleWaitHandle, millisecondsTimeout, false); return STPEventWaitHandle.WaitOne(_isIdleWaitHandle, millisecondsTimeout, false);
} }
public override event WorkItemsGroupIdleHandler OnIdle public override event WorkItemsGroupIdleHandler OnIdle
{ {
add { _onIdle += value; } add { _onIdle += value; }
remove { _onIdle -= value; } remove { _onIdle -= value; }
} }
#endregion #endregion
#region Private methods #region Private methods
private void RegisterToWorkItemCompletion(IWorkItemResult wir) private void RegisterToWorkItemCompletion(IWorkItemResult wir)
{ {
IInternalWorkItemResult iwir = (IInternalWorkItemResult)wir; IInternalWorkItemResult iwir = (IInternalWorkItemResult)wir;
iwir.OnWorkItemStarted += OnWorkItemStartedCallback; iwir.OnWorkItemStarted += OnWorkItemStartedCallback;
iwir.OnWorkItemCompleted += OnWorkItemCompletedCallback; iwir.OnWorkItemCompleted += OnWorkItemCompletedCallback;
} }
public void OnSTPIsStarting() public void OnSTPIsStarting()
{ {
if (_isSuspended) if (_isSuspended)
{ {
return; return;
} }
EnqueueToSTPNextNWorkItem(_concurrency); EnqueueToSTPNextNWorkItem(_concurrency);
} }
public void EnqueueToSTPNextNWorkItem(int count) public void EnqueueToSTPNextNWorkItem(int count)
{ {
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i)
{ {
EnqueueToSTPNextWorkItem(null, false); EnqueueToSTPNextWorkItem(null, false);
} }
} }
private object FireOnIdle(object state) private object FireOnIdle(object state)
{ {
FireOnIdleImpl(_onIdle); FireOnIdleImpl(_onIdle);
return null; return null;
} }
[MethodImpl(MethodImplOptions.NoInlining)] [MethodImpl(MethodImplOptions.NoInlining)]
private void FireOnIdleImpl(WorkItemsGroupIdleHandler onIdle) private void FireOnIdleImpl(WorkItemsGroupIdleHandler onIdle)
{ {
if(null == onIdle) if(null == onIdle)
{ {
return; return;
} }
Delegate[] delegates = onIdle.GetInvocationList(); Delegate[] delegates = onIdle.GetInvocationList();
foreach(WorkItemsGroupIdleHandler eh in delegates) foreach(WorkItemsGroupIdleHandler eh in delegates)
{ {
try try
{ {
eh(this); eh(this);
} }
catch { } // Suppress exceptions catch { } // Suppress exceptions
} }
} }
private void OnWorkItemStartedCallback(WorkItem workItem) private void OnWorkItemStartedCallback(WorkItem workItem)
{ {
lock(_lock) lock(_lock)
{ {
++_workItemsExecutingInStp; ++_workItemsExecutingInStp;
} }
} }
private void OnWorkItemCompletedCallback(WorkItem workItem) private void OnWorkItemCompletedCallback(WorkItem workItem)
{ {
EnqueueToSTPNextWorkItem(null, true); EnqueueToSTPNextWorkItem(null, true);
} }
internal override void Enqueue(WorkItem workItem) internal override void Enqueue(WorkItem workItem)
{ {
EnqueueToSTPNextWorkItem(workItem); EnqueueToSTPNextWorkItem(workItem);
} }
private void EnqueueToSTPNextWorkItem(WorkItem workItem) private void EnqueueToSTPNextWorkItem(WorkItem workItem)
{ {
EnqueueToSTPNextWorkItem(workItem, false); EnqueueToSTPNextWorkItem(workItem, false);
} }
private void EnqueueToSTPNextWorkItem(WorkItem workItem, bool decrementWorkItemsInStpQueue) private void EnqueueToSTPNextWorkItem(WorkItem workItem, bool decrementWorkItemsInStpQueue)
{ {
lock(_lock) lock(_lock)
{ {
// Got here from OnWorkItemCompletedCallback() // Got here from OnWorkItemCompletedCallback()
if (decrementWorkItemsInStpQueue) if (decrementWorkItemsInStpQueue)
{ {
--_workItemsInStpQueue; --_workItemsInStpQueue;
if(_workItemsInStpQueue < 0) if(_workItemsInStpQueue < 0)
{ {
_workItemsInStpQueue = 0; _workItemsInStpQueue = 0;
} }
--_workItemsExecutingInStp; --_workItemsExecutingInStp;
if(_workItemsExecutingInStp < 0) if(_workItemsExecutingInStp < 0)
{ {
_workItemsExecutingInStp = 0; _workItemsExecutingInStp = 0;
} }
} }
// If the work item is not null then enqueue it // If the work item is not null then enqueue it
if (null != workItem) if (null != workItem)
{ {
workItem.CanceledWorkItemsGroup = _canceledWorkItemsGroup; workItem.CanceledWorkItemsGroup = _canceledWorkItemsGroup;
RegisterToWorkItemCompletion(workItem.GetWorkItemResult()); RegisterToWorkItemCompletion(workItem.GetWorkItemResult());
_workItemsQueue.Enqueue(workItem); _workItemsQueue.Enqueue(workItem);
//_stp.IncrementWorkItemsCount(); //_stp.IncrementWorkItemsCount();
if ((1 == _workItemsQueue.Count) && if ((1 == _workItemsQueue.Count) &&
(0 == _workItemsInStpQueue)) (0 == _workItemsInStpQueue))
{ {
_stp.RegisterWorkItemsGroup(this); _stp.RegisterWorkItemsGroup(this);
IsIdle = false; IsIdle = false;
_isIdleWaitHandle.Reset(); _isIdleWaitHandle.Reset();
} }
} }
// If the work items queue of the group is empty than quit // If the work items queue of the group is empty than quit
if (0 == _workItemsQueue.Count) if (0 == _workItemsQueue.Count)
{ {
if (0 == _workItemsInStpQueue) if (0 == _workItemsInStpQueue)
{ {
_stp.UnregisterWorkItemsGroup(this); _stp.UnregisterWorkItemsGroup(this);
IsIdle = true; IsIdle = true;
_isIdleWaitHandle.Set(); _isIdleWaitHandle.Set();
if (decrementWorkItemsInStpQueue && _onIdle != null && _onIdle.GetInvocationList().Length > 0) if (decrementWorkItemsInStpQueue && _onIdle != null && _onIdle.GetInvocationList().Length > 0)
{ {
_stp.QueueWorkItem(new WorkItemCallback(FireOnIdle)); _stp.QueueWorkItem(new WorkItemCallback(FireOnIdle));
} }
} }
return; return;
} }
if (!_isSuspended) if (!_isSuspended)
{ {
if (_workItemsInStpQueue < _concurrency) if (_workItemsInStpQueue < _concurrency)
{ {
WorkItem nextWorkItem = _workItemsQueue.Dequeue() as WorkItem; WorkItem nextWorkItem = _workItemsQueue.Dequeue() as WorkItem;
try try
{ {
_stp.Enqueue(nextWorkItem); _stp.Enqueue(nextWorkItem);
} }
catch (ObjectDisposedException e) catch (ObjectDisposedException e)
{ {
e.GetHashCode(); e.GetHashCode();
// The STP has been shutdown // The STP has been shutdown
} }
++_workItemsInStpQueue; ++_workItemsInStpQueue;
} }
} }
} }
} }
#endregion #endregion
} }
#endregion #endregion
} }

View File

@ -1,471 +1,471 @@
using System; using System;
using System.Threading; using System.Threading;
namespace Amib.Threading.Internal namespace Amib.Threading.Internal
{ {
public abstract class WorkItemsGroupBase : IWorkItemsGroup public abstract class WorkItemsGroupBase : IWorkItemsGroup
{ {
#region Private Fields #region Private Fields
/// <summary> /// <summary>
/// Contains the name of this instance of SmartThreadPool. /// Contains the name of this instance of SmartThreadPool.
/// Can be changed by the user. /// Can be changed by the user.
/// </summary> /// </summary>
private string _name = "WorkItemsGroupBase"; private string _name = "WorkItemsGroupBase";
public WorkItemsGroupBase() public WorkItemsGroupBase()
{ {
IsIdle = true; IsIdle = true;
} }
#endregion #endregion
#region IWorkItemsGroup Members #region IWorkItemsGroup Members
#region Public Methods #region Public Methods
/// <summary> /// <summary>
/// Get/Set the name of the SmartThreadPool/WorkItemsGroup instance /// Get/Set the name of the SmartThreadPool/WorkItemsGroup instance
/// </summary> /// </summary>
public string Name public string Name
{ {
get { return _name; } get { return _name; }
set { _name = value; } set { _name = value; }
} }
#endregion #endregion
#region Abstract Methods #region Abstract Methods
public abstract int Concurrency { get; set; } public abstract int Concurrency { get; set; }
public abstract int WaitingCallbacks { get; } public abstract int WaitingCallbacks { get; }
public abstract object[] GetStates(); public abstract object[] GetStates();
public abstract WIGStartInfo WIGStartInfo { get; } public abstract WIGStartInfo WIGStartInfo { get; }
public abstract void Start(); public abstract void Start();
public abstract void Cancel(bool abortExecution); public abstract void Cancel(bool abortExecution);
public abstract bool WaitForIdle(int millisecondsTimeout); public abstract bool WaitForIdle(int millisecondsTimeout);
public abstract event WorkItemsGroupIdleHandler OnIdle; public abstract event WorkItemsGroupIdleHandler OnIdle;
internal abstract void Enqueue(WorkItem workItem); internal abstract void Enqueue(WorkItem workItem);
internal virtual void PreQueueWorkItem() { } internal virtual void PreQueueWorkItem() { }
#endregion #endregion
#region Common Base Methods #region Common Base Methods
/// <summary> /// <summary>
/// Cancel all the work items. /// Cancel all the work items.
/// Same as Cancel(false) /// Same as Cancel(false)
/// </summary> /// </summary>
public virtual void Cancel() public virtual void Cancel()
{ {
Cancel(false); Cancel(false);
} }
/// <summary> /// <summary>
/// Wait for the SmartThreadPool/WorkItemsGroup to be idle /// Wait for the SmartThreadPool/WorkItemsGroup to be idle
/// </summary> /// </summary>
public void WaitForIdle() public void WaitForIdle()
{ {
WaitForIdle(Timeout.Infinite); WaitForIdle(Timeout.Infinite);
} }
/// <summary> /// <summary>
/// Wait for the SmartThreadPool/WorkItemsGroup to be idle /// Wait for the SmartThreadPool/WorkItemsGroup to be idle
/// </summary> /// </summary>
public bool WaitForIdle(TimeSpan timeout) public bool WaitForIdle(TimeSpan timeout)
{ {
return WaitForIdle((int)timeout.TotalMilliseconds); return WaitForIdle((int)timeout.TotalMilliseconds);
} }
/// <summary> /// <summary>
/// IsIdle is true when there are no work items running or queued. /// IsIdle is true when there are no work items running or queued.
/// </summary> /// </summary>
public bool IsIdle { get; protected set; } public bool IsIdle { get; protected set; }
#endregion #endregion
#region QueueWorkItem #region QueueWorkItem
/// <summary> /// <summary>
/// Queue a work item /// Queue a work item
/// </summary> /// </summary>
/// <param name="callback">A callback to execute</param> /// <param name="callback">A callback to execute</param>
/// <returns>Returns a work item result</returns> /// <returns>Returns a work item result</returns>
public IWorkItemResult QueueWorkItem(WorkItemCallback callback) public IWorkItemResult QueueWorkItem(WorkItemCallback callback)
{ {
WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback); WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback);
Enqueue(workItem); Enqueue(workItem);
return workItem.GetWorkItemResult(); return workItem.GetWorkItemResult();
} }
/// <summary> /// <summary>
/// Queue a work item /// Queue a work item
/// </summary> /// </summary>
/// <param name="callback">A callback to execute</param> /// <param name="callback">A callback to execute</param>
/// <param name="workItemPriority">The priority of the work item</param> /// <param name="workItemPriority">The priority of the work item</param>
/// <returns>Returns a work item result</returns> /// <returns>Returns a work item result</returns>
public IWorkItemResult QueueWorkItem(WorkItemCallback callback, WorkItemPriority workItemPriority) public IWorkItemResult QueueWorkItem(WorkItemCallback callback, WorkItemPriority workItemPriority)
{ {
PreQueueWorkItem(); PreQueueWorkItem();
WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, workItemPriority); WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, workItemPriority);
Enqueue(workItem); Enqueue(workItem);
return workItem.GetWorkItemResult(); return workItem.GetWorkItemResult();
} }
/// <summary> /// <summary>
/// Queue a work item /// Queue a work item
/// </summary> /// </summary>
/// <param name="workItemInfo">Work item info</param> /// <param name="workItemInfo">Work item info</param>
/// <param name="callback">A callback to execute</param> /// <param name="callback">A callback to execute</param>
/// <returns>Returns a work item result</returns> /// <returns>Returns a work item result</returns>
public IWorkItemResult QueueWorkItem(WorkItemInfo workItemInfo, WorkItemCallback callback) public IWorkItemResult QueueWorkItem(WorkItemInfo workItemInfo, WorkItemCallback callback)
{ {
PreQueueWorkItem(); PreQueueWorkItem();
WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, workItemInfo, callback); WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, workItemInfo, callback);
Enqueue(workItem); Enqueue(workItem);
return workItem.GetWorkItemResult(); return workItem.GetWorkItemResult();
} }
/// <summary> /// <summary>
/// Queue a work item /// Queue a work item
/// </summary> /// </summary>
/// <param name="callback">A callback to execute</param> /// <param name="callback">A callback to execute</param>
/// <param name="state"> /// <param name="state">
/// 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.
/// </param> /// </param>
/// <returns>Returns a work item result</returns> /// <returns>Returns a work item result</returns>
public IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state) public IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state)
{ {
WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state); WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state);
Enqueue(workItem); Enqueue(workItem);
return workItem.GetWorkItemResult(); return workItem.GetWorkItemResult();
} }
/// <summary> /// <summary>
/// Queue a work item /// Queue a work item
/// </summary> /// </summary>
/// <param name="callback">A callback to execute</param> /// <param name="callback">A callback to execute</param>
/// <param name="state"> /// <param name="state">
/// 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.
/// </param> /// </param>
/// <param name="workItemPriority">The work item priority</param> /// <param name="workItemPriority">The work item priority</param>
/// <returns>Returns a work item result</returns> /// <returns>Returns a work item result</returns>
public IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state, WorkItemPriority workItemPriority) public IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state, WorkItemPriority workItemPriority)
{ {
PreQueueWorkItem(); PreQueueWorkItem();
WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, workItemPriority); WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, workItemPriority);
Enqueue(workItem); Enqueue(workItem);
return workItem.GetWorkItemResult(); return workItem.GetWorkItemResult();
} }
/// <summary> /// <summary>
/// Queue a work item /// Queue a work item
/// </summary> /// </summary>
/// <param name="workItemInfo">Work item information</param> /// <param name="workItemInfo">Work item information</param>
/// <param name="callback">A callback to execute</param> /// <param name="callback">A callback to execute</param>
/// <param name="state"> /// <param name="state">
/// 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.
/// </param> /// </param>
/// <returns>Returns a work item result</returns> /// <returns>Returns a work item result</returns>
public IWorkItemResult QueueWorkItem(WorkItemInfo workItemInfo, WorkItemCallback callback, object state) public IWorkItemResult QueueWorkItem(WorkItemInfo workItemInfo, WorkItemCallback callback, object state)
{ {
PreQueueWorkItem(); PreQueueWorkItem();
WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, workItemInfo, callback, state); WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, workItemInfo, callback, state);
Enqueue(workItem); Enqueue(workItem);
return workItem.GetWorkItemResult(); return workItem.GetWorkItemResult();
} }
/// <summary> /// <summary>
/// Queue a work item /// Queue a work item
/// </summary> /// </summary>
/// <param name="callback">A callback to execute</param> /// <param name="callback">A callback to execute</param>
/// <param name="state"> /// <param name="state">
/// 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.
/// </param> /// </param>
/// <param name="postExecuteWorkItemCallback"> /// <param name="postExecuteWorkItemCallback">
/// A delegate to call after the callback completion /// A delegate to call after the callback completion
/// </param> /// </param>
/// <returns>Returns a work item result</returns> /// <returns>Returns a work item result</returns>
public IWorkItemResult QueueWorkItem( public IWorkItemResult QueueWorkItem(
WorkItemCallback callback, WorkItemCallback callback,
object state, object state,
PostExecuteWorkItemCallback postExecuteWorkItemCallback) PostExecuteWorkItemCallback postExecuteWorkItemCallback)
{ {
PreQueueWorkItem(); PreQueueWorkItem();
WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback); WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback);
Enqueue(workItem); Enqueue(workItem);
return workItem.GetWorkItemResult(); return workItem.GetWorkItemResult();
} }
/// <summary> /// <summary>
/// Queue a work item /// Queue a work item
/// </summary> /// </summary>
/// <param name="callback">A callback to execute</param> /// <param name="callback">A callback to execute</param>
/// <param name="state"> /// <param name="state">
/// 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.
/// </param> /// </param>
/// <param name="postExecuteWorkItemCallback"> /// <param name="postExecuteWorkItemCallback">
/// A delegate to call after the callback completion /// A delegate to call after the callback completion
/// </param> /// </param>
/// <param name="workItemPriority">The work item priority</param> /// <param name="workItemPriority">The work item priority</param>
/// <returns>Returns a work item result</returns> /// <returns>Returns a work item result</returns>
public IWorkItemResult QueueWorkItem( public IWorkItemResult QueueWorkItem(
WorkItemCallback callback, WorkItemCallback callback,
object state, object state,
PostExecuteWorkItemCallback postExecuteWorkItemCallback, PostExecuteWorkItemCallback postExecuteWorkItemCallback,
WorkItemPriority workItemPriority) WorkItemPriority workItemPriority)
{ {
PreQueueWorkItem(); PreQueueWorkItem();
WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback, workItemPriority); WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback, workItemPriority);
Enqueue(workItem); Enqueue(workItem);
return workItem.GetWorkItemResult(); return workItem.GetWorkItemResult();
} }
/// <summary> /// <summary>
/// Queue a work item /// Queue a work item
/// </summary> /// </summary>
/// <param name="callback">A callback to execute</param> /// <param name="callback">A callback to execute</param>
/// <param name="state"> /// <param name="state">
/// 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.
/// </param> /// </param>
/// <param name="postExecuteWorkItemCallback"> /// <param name="postExecuteWorkItemCallback">
/// A delegate to call after the callback completion /// A delegate to call after the callback completion
/// </param> /// </param>
/// <param name="callToPostExecute">Indicates on which cases to call to the post execute callback</param> /// <param name="callToPostExecute">Indicates on which cases to call to the post execute callback</param>
/// <returns>Returns a work item result</returns> /// <returns>Returns a work item result</returns>
public IWorkItemResult QueueWorkItem( public IWorkItemResult QueueWorkItem(
WorkItemCallback callback, WorkItemCallback callback,
object state, object state,
PostExecuteWorkItemCallback postExecuteWorkItemCallback, PostExecuteWorkItemCallback postExecuteWorkItemCallback,
CallToPostExecute callToPostExecute) CallToPostExecute callToPostExecute)
{ {
PreQueueWorkItem(); PreQueueWorkItem();
WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback, callToPostExecute); WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback, callToPostExecute);
Enqueue(workItem); Enqueue(workItem);
return workItem.GetWorkItemResult(); return workItem.GetWorkItemResult();
} }
/// <summary> /// <summary>
/// Queue a work item /// Queue a work item
/// </summary> /// </summary>
/// <param name="callback">A callback to execute</param> /// <param name="callback">A callback to execute</param>
/// <param name="state"> /// <param name="state">
/// 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.
/// </param> /// </param>
/// <param name="postExecuteWorkItemCallback"> /// <param name="postExecuteWorkItemCallback">
/// A delegate to call after the callback completion /// A delegate to call after the callback completion
/// </param> /// </param>
/// <param name="callToPostExecute">Indicates on which cases to call to the post execute callback</param> /// <param name="callToPostExecute">Indicates on which cases to call to the post execute callback</param>
/// <param name="workItemPriority">The work item priority</param> /// <param name="workItemPriority">The work item priority</param>
/// <returns>Returns a work item result</returns> /// <returns>Returns a work item result</returns>
public IWorkItemResult QueueWorkItem( public IWorkItemResult QueueWorkItem(
WorkItemCallback callback, WorkItemCallback callback,
object state, object state,
PostExecuteWorkItemCallback postExecuteWorkItemCallback, PostExecuteWorkItemCallback postExecuteWorkItemCallback,
CallToPostExecute callToPostExecute, CallToPostExecute callToPostExecute,
WorkItemPriority workItemPriority) WorkItemPriority workItemPriority)
{ {
PreQueueWorkItem(); PreQueueWorkItem();
WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback, callToPostExecute, workItemPriority); WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback, callToPostExecute, workItemPriority);
Enqueue(workItem); Enqueue(workItem);
return workItem.GetWorkItemResult(); return workItem.GetWorkItemResult();
} }
#endregion #endregion
#region QueueWorkItem(Action<...>) #region QueueWorkItem(Action<...>)
public IWorkItemResult QueueWorkItem(Action action) public IWorkItemResult QueueWorkItem(Action action)
{ {
return QueueWorkItem (action, SmartThreadPool.DefaultWorkItemPriority); return QueueWorkItem (action, SmartThreadPool.DefaultWorkItemPriority);
} }
public IWorkItemResult QueueWorkItem (Action action, WorkItemPriority priority) public IWorkItemResult QueueWorkItem (Action action, WorkItemPriority priority)
{ {
PreQueueWorkItem (); PreQueueWorkItem ();
WorkItem workItem = WorkItemFactory.CreateWorkItem ( WorkItem workItem = WorkItemFactory.CreateWorkItem (
this, this,
WIGStartInfo, WIGStartInfo,
delegate delegate
{ {
action.Invoke (); action.Invoke ();
return null; return null;
}, priority); }, priority);
Enqueue (workItem); Enqueue (workItem);
return workItem.GetWorkItemResult (); return workItem.GetWorkItemResult ();
} }
public IWorkItemResult QueueWorkItem<T>(Action<T> action, T arg) public IWorkItemResult QueueWorkItem<T>(Action<T> action, T arg)
{ {
return QueueWorkItem<T> (action, arg, SmartThreadPool.DefaultWorkItemPriority); return QueueWorkItem<T> (action, arg, SmartThreadPool.DefaultWorkItemPriority);
} }
public IWorkItemResult QueueWorkItem<T> (Action<T> action, T arg, WorkItemPriority priority) public IWorkItemResult QueueWorkItem<T> (Action<T> action, T arg, WorkItemPriority priority)
{ {
PreQueueWorkItem (); PreQueueWorkItem ();
WorkItem workItem = WorkItemFactory.CreateWorkItem ( WorkItem workItem = WorkItemFactory.CreateWorkItem (
this, this,
WIGStartInfo, WIGStartInfo,
state => state =>
{ {
action.Invoke (arg); action.Invoke (arg);
return null; return null;
}, },
WIGStartInfo.FillStateWithArgs ? new object[] { arg } : null, priority); WIGStartInfo.FillStateWithArgs ? new object[] { arg } : null, priority);
Enqueue (workItem); Enqueue (workItem);
return workItem.GetWorkItemResult (); return workItem.GetWorkItemResult ();
} }
public IWorkItemResult QueueWorkItem<T1, T2>(Action<T1, T2> action, T1 arg1, T2 arg2) public IWorkItemResult QueueWorkItem<T1, T2>(Action<T1, T2> action, T1 arg1, T2 arg2)
{ {
return QueueWorkItem<T1, T2> (action, arg1, arg2, SmartThreadPool.DefaultWorkItemPriority); return QueueWorkItem<T1, T2> (action, arg1, arg2, SmartThreadPool.DefaultWorkItemPriority);
} }
public IWorkItemResult QueueWorkItem<T1, T2> (Action<T1, T2> action, T1 arg1, T2 arg2, WorkItemPriority priority) public IWorkItemResult QueueWorkItem<T1, T2> (Action<T1, T2> action, T1 arg1, T2 arg2, WorkItemPriority priority)
{ {
PreQueueWorkItem (); PreQueueWorkItem ();
WorkItem workItem = WorkItemFactory.CreateWorkItem ( WorkItem workItem = WorkItemFactory.CreateWorkItem (
this, this,
WIGStartInfo, WIGStartInfo,
state => state =>
{ {
action.Invoke (arg1, arg2); action.Invoke (arg1, arg2);
return null; return null;
}, },
WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2 } : null, priority); WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2 } : null, priority);
Enqueue (workItem); Enqueue (workItem);
return workItem.GetWorkItemResult (); return workItem.GetWorkItemResult ();
} }
public IWorkItemResult QueueWorkItem<T1, T2, T3>(Action<T1, T2, T3> action, T1 arg1, T2 arg2, T3 arg3) public IWorkItemResult QueueWorkItem<T1, T2, T3>(Action<T1, T2, T3> action, T1 arg1, T2 arg2, T3 arg3)
{ {
return QueueWorkItem<T1, T2, T3> (action, arg1, arg2, arg3, SmartThreadPool.DefaultWorkItemPriority); return QueueWorkItem<T1, T2, T3> (action, arg1, arg2, arg3, SmartThreadPool.DefaultWorkItemPriority);
; ;
} }
public IWorkItemResult QueueWorkItem<T1, T2, T3> (Action<T1, T2, T3> action, T1 arg1, T2 arg2, T3 arg3, WorkItemPriority priority) public IWorkItemResult QueueWorkItem<T1, T2, T3> (Action<T1, T2, T3> action, T1 arg1, T2 arg2, T3 arg3, WorkItemPriority priority)
{ {
PreQueueWorkItem (); PreQueueWorkItem ();
WorkItem workItem = WorkItemFactory.CreateWorkItem ( WorkItem workItem = WorkItemFactory.CreateWorkItem (
this, this,
WIGStartInfo, WIGStartInfo,
state => state =>
{ {
action.Invoke (arg1, arg2, arg3); action.Invoke (arg1, arg2, arg3);
return null; return null;
}, },
WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2, arg3 } : null, priority); WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2, arg3 } : null, priority);
Enqueue (workItem); Enqueue (workItem);
return workItem.GetWorkItemResult (); return workItem.GetWorkItemResult ();
} }
public IWorkItemResult QueueWorkItem<T1, T2, T3, T4>( public IWorkItemResult QueueWorkItem<T1, T2, T3, T4>(
Action<T1, T2, T3, T4> action, T1 arg1, T2 arg2, T3 arg3, T4 arg4) Action<T1, T2, T3, T4> action, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
{ {
return QueueWorkItem<T1, T2, T3, T4> (action, arg1, arg2, arg3, arg4, return QueueWorkItem<T1, T2, T3, T4> (action, arg1, arg2, arg3, arg4,
SmartThreadPool.DefaultWorkItemPriority); SmartThreadPool.DefaultWorkItemPriority);
} }
public IWorkItemResult QueueWorkItem<T1, T2, T3, T4> ( public IWorkItemResult QueueWorkItem<T1, T2, T3, T4> (
Action<T1, T2, T3, T4> action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, WorkItemPriority priority) Action<T1, T2, T3, T4> action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, WorkItemPriority priority)
{ {
PreQueueWorkItem (); PreQueueWorkItem ();
WorkItem workItem = WorkItemFactory.CreateWorkItem ( WorkItem workItem = WorkItemFactory.CreateWorkItem (
this, this,
WIGStartInfo, WIGStartInfo,
state => state =>
{ {
action.Invoke (arg1, arg2, arg3, arg4); action.Invoke (arg1, arg2, arg3, arg4);
return null; return null;
}, },
WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2, arg3, arg4 } : null, priority); WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2, arg3, arg4 } : null, priority);
Enqueue (workItem); Enqueue (workItem);
return workItem.GetWorkItemResult (); return workItem.GetWorkItemResult ();
} }
#endregion #endregion
#region QueueWorkItem(Func<...>) #region QueueWorkItem(Func<...>)
public IWorkItemResult<TResult> QueueWorkItem<TResult>(Func<TResult> func) public IWorkItemResult<TResult> QueueWorkItem<TResult>(Func<TResult> func)
{ {
PreQueueWorkItem(); PreQueueWorkItem();
WorkItem workItem = WorkItemFactory.CreateWorkItem( WorkItem workItem = WorkItemFactory.CreateWorkItem(
this, this,
WIGStartInfo, WIGStartInfo,
state => state =>
{ {
return func.Invoke(); return func.Invoke();
}); });
Enqueue(workItem); Enqueue(workItem);
return new WorkItemResultTWrapper<TResult>(workItem.GetWorkItemResult()); return new WorkItemResultTWrapper<TResult>(workItem.GetWorkItemResult());
} }
public IWorkItemResult<TResult> QueueWorkItem<T, TResult>(Func<T, TResult> func, T arg) public IWorkItemResult<TResult> QueueWorkItem<T, TResult>(Func<T, TResult> func, T arg)
{ {
PreQueueWorkItem(); PreQueueWorkItem();
WorkItem workItem = WorkItemFactory.CreateWorkItem( WorkItem workItem = WorkItemFactory.CreateWorkItem(
this, this,
WIGStartInfo, WIGStartInfo,
state => state =>
{ {
return func.Invoke(arg); return func.Invoke(arg);
}, },
WIGStartInfo.FillStateWithArgs ? new object[] { arg } : null); WIGStartInfo.FillStateWithArgs ? new object[] { arg } : null);
Enqueue(workItem); Enqueue(workItem);
return new WorkItemResultTWrapper<TResult>(workItem.GetWorkItemResult()); return new WorkItemResultTWrapper<TResult>(workItem.GetWorkItemResult());
} }
public IWorkItemResult<TResult> QueueWorkItem<T1, T2, TResult>(Func<T1, T2, TResult> func, T1 arg1, T2 arg2) public IWorkItemResult<TResult> QueueWorkItem<T1, T2, TResult>(Func<T1, T2, TResult> func, T1 arg1, T2 arg2)
{ {
PreQueueWorkItem(); PreQueueWorkItem();
WorkItem workItem = WorkItemFactory.CreateWorkItem( WorkItem workItem = WorkItemFactory.CreateWorkItem(
this, this,
WIGStartInfo, WIGStartInfo,
state => state =>
{ {
return func.Invoke(arg1, arg2); return func.Invoke(arg1, arg2);
}, },
WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2 } : null); WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2 } : null);
Enqueue(workItem); Enqueue(workItem);
return new WorkItemResultTWrapper<TResult>(workItem.GetWorkItemResult()); return new WorkItemResultTWrapper<TResult>(workItem.GetWorkItemResult());
} }
public IWorkItemResult<TResult> QueueWorkItem<T1, T2, T3, TResult>( public IWorkItemResult<TResult> QueueWorkItem<T1, T2, T3, TResult>(
Func<T1, T2, T3, TResult> func, T1 arg1, T2 arg2, T3 arg3) Func<T1, T2, T3, TResult> func, T1 arg1, T2 arg2, T3 arg3)
{ {
PreQueueWorkItem(); PreQueueWorkItem();
WorkItem workItem = WorkItemFactory.CreateWorkItem( WorkItem workItem = WorkItemFactory.CreateWorkItem(
this, this,
WIGStartInfo, WIGStartInfo,
state => state =>
{ {
return func.Invoke(arg1, arg2, arg3); return func.Invoke(arg1, arg2, arg3);
}, },
WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2, arg3 } : null); WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2, arg3 } : null);
Enqueue(workItem); Enqueue(workItem);
return new WorkItemResultTWrapper<TResult>(workItem.GetWorkItemResult()); return new WorkItemResultTWrapper<TResult>(workItem.GetWorkItemResult());
} }
public IWorkItemResult<TResult> QueueWorkItem<T1, T2, T3, T4, TResult>( public IWorkItemResult<TResult> QueueWorkItem<T1, T2, T3, T4, TResult>(
Func<T1, T2, T3, T4, TResult> func, T1 arg1, T2 arg2, T3 arg3, T4 arg4) Func<T1, T2, T3, T4, TResult> func, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
{ {
PreQueueWorkItem(); PreQueueWorkItem();
WorkItem workItem = WorkItemFactory.CreateWorkItem( WorkItem workItem = WorkItemFactory.CreateWorkItem(
this, this,
WIGStartInfo, WIGStartInfo,
state => state =>
{ {
return func.Invoke(arg1, arg2, arg3, arg4); return func.Invoke(arg1, arg2, arg3, arg4);
}, },
WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2, arg3, arg4 } : null); WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2, arg3, arg4 } : null);
Enqueue(workItem); Enqueue(workItem);
return new WorkItemResultTWrapper<TResult>(workItem.GetWorkItemResult()); return new WorkItemResultTWrapper<TResult>(workItem.GetWorkItemResult());
} }
#endregion #endregion
#endregion #endregion
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -35,7 +35,7 @@
; Modular configurations ; Modular configurations
; Set path to directory for modular ini files... ; Set path to directory for modular ini files...
; The Robust.exe process must have R/W access to the location ; The Robust.exe process must have R/W access to the location
ConfigDirectory = "/home/opensim/etc/Configs" ConfigDirectory = "."
[ServiceList] [ServiceList]

View File

@ -27,7 +27,7 @@
; Modular configurations ; Modular configurations
; Set path to directory for modular ini files... ; Set path to directory for modular ini files...
; The Robust.exe process must have R/W access to the location ; The Robust.exe process must have R/W access to the location
ConfigDirectory = "/home/opensim/etc/Configs" ConfigDirectory = "."
[ServiceList] [ServiceList]
AssetServiceConnector = "8003/OpenSim.Server.Handlers.dll:AssetServiceConnector" AssetServiceConnector = "8003/OpenSim.Server.Handlers.dll:AssetServiceConnector"