smartthreadpool: remove workitems priority. Its lack of fairness could cause issues hard to debug if we tried to use it (we don't) (runprebuild)
This commit is contained in:
105
ThirdParty/SmartThreadPool/Interfaces.cs
vendored
105
ThirdParty/SmartThreadPool/Interfaces.cs
vendored
@@ -43,24 +43,6 @@ namespace Amib.Threading
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region WorkItem Priority
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Defines the availeable priorities of a work item.
|
|
||||||
/// The higher the priority a work item has, the sooner
|
|
||||||
/// it will be executed.
|
|
||||||
/// </summary>
|
|
||||||
public enum WorkItemPriority
|
|
||||||
{
|
|
||||||
Lowest,
|
|
||||||
BelowNormal,
|
|
||||||
Normal,
|
|
||||||
AboveNormal,
|
|
||||||
Highest,
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IWorkItemsGroup interface
|
#region IWorkItemsGroup interface
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -146,6 +128,11 @@ namespace Amib.Threading
|
|||||||
|
|
||||||
#region QueueWorkItem
|
#region QueueWorkItem
|
||||||
|
|
||||||
|
IWorkItemResult QueueWorkItem(WaitCallback callback);
|
||||||
|
IWorkItemResult QueueWorkItem(WaitCallback callback, object state);
|
||||||
|
IWorkItemResult QueueWorkItem(WorkItemInfo workItemInfo, WaitCallback callback);
|
||||||
|
IWorkItemResult QueueWorkItem(WorkItemInfo workItemInfo, WaitCallback callback, object state);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queue a work item
|
/// Queue a work item
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -153,14 +140,6 @@ namespace Amib.Threading
|
|||||||
/// <returns>Returns a work item result</returns>
|
/// <returns>Returns a work item result</returns>
|
||||||
IWorkItemResult QueueWorkItem(WorkItemCallback callback);
|
IWorkItemResult QueueWorkItem(WorkItemCallback callback);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Queue a work item
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="callback">A callback to execute</param>
|
|
||||||
/// <param name="workItemPriority">The priority of the work item</param>
|
|
||||||
/// <returns>Returns a work item result</returns>
|
|
||||||
IWorkItemResult QueueWorkItem(WorkItemCallback callback, WorkItemPriority workItemPriority);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queue a work item
|
/// Queue a work item
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -171,17 +150,6 @@ namespace Amib.Threading
|
|||||||
/// <returns>Returns a work item result</returns>
|
/// <returns>Returns a work item result</returns>
|
||||||
IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state);
|
IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Queue a work item
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="callback">A callback to execute</param>
|
|
||||||
/// <param name="state">
|
|
||||||
/// The context object of the work item. Used for passing arguments to the work item.
|
|
||||||
/// </param>
|
|
||||||
/// <param name="workItemPriority">The work item priority</param>
|
|
||||||
/// <returns>Returns a work item result</returns>
|
|
||||||
IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state, WorkItemPriority workItemPriority);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queue a work item
|
/// Queue a work item
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -195,19 +163,6 @@ namespace Amib.Threading
|
|||||||
/// <returns>Returns a work item result</returns>
|
/// <returns>Returns a work item result</returns>
|
||||||
IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state, PostExecuteWorkItemCallback postExecuteWorkItemCallback);
|
IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state, PostExecuteWorkItemCallback postExecuteWorkItemCallback);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Queue a work item
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="callback">A callback to execute</param>
|
|
||||||
/// <param name="state">
|
|
||||||
/// The context object of the work item. Used for passing arguments to the work item.
|
|
||||||
/// </param>
|
|
||||||
/// <param name="postExecuteWorkItemCallback">
|
|
||||||
/// A delegate to call after the callback completion
|
|
||||||
/// </param>
|
|
||||||
/// <param name="workItemPriority">The work item priority</param>
|
|
||||||
/// <returns>Returns a work item result</returns>
|
|
||||||
IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state, PostExecuteWorkItemCallback postExecuteWorkItemCallback, WorkItemPriority workItemPriority);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queue a work item
|
/// Queue a work item
|
||||||
@@ -223,21 +178,6 @@ namespace Amib.Threading
|
|||||||
/// <returns>Returns a work item result</returns>
|
/// <returns>Returns a work item result</returns>
|
||||||
IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state, PostExecuteWorkItemCallback postExecuteWorkItemCallback, CallToPostExecute callToPostExecute);
|
IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state, PostExecuteWorkItemCallback postExecuteWorkItemCallback, CallToPostExecute callToPostExecute);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Queue a work item
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="callback">A callback to execute</param>
|
|
||||||
/// <param name="state">
|
|
||||||
/// The context object of the work item. Used for passing arguments to the work item.
|
|
||||||
/// </param>
|
|
||||||
/// <param name="postExecuteWorkItemCallback">
|
|
||||||
/// A delegate to call after the callback completion
|
|
||||||
/// </param>
|
|
||||||
/// <param name="callToPostExecute">Indicates on which cases to call to the post execute callback</param>
|
|
||||||
/// <param name="workItemPriority">The work item priority</param>
|
|
||||||
/// <returns>Returns a work item result</returns>
|
|
||||||
IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state, PostExecuteWorkItemCallback postExecuteWorkItemCallback, CallToPostExecute callToPostExecute, WorkItemPriority workItemPriority);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queue a work item
|
/// Queue a work item
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -267,18 +207,6 @@ namespace Amib.Threading
|
|||||||
/// <returns>Returns a IWorkItemResult object, but its GetResult() will always return null</returns>
|
/// <returns>Returns a IWorkItemResult object, but its GetResult() will always return null</returns>
|
||||||
IWorkItemResult QueueWorkItem(Action action);
|
IWorkItemResult QueueWorkItem(Action action);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Queue a work item.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Returns a IWorkItemResult object, but its GetResult() will always return null</returns>
|
|
||||||
IWorkItemResult QueueWorkItem(Action action, WorkItemPriority priority);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Queue a work item.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Returns a IWorkItemResult object, but its GetResult() will always return null</returns>
|
|
||||||
IWorkItemResult QueueWorkItem<T>(Action<T> action, T arg, WorkItemPriority priority);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queue a work item.
|
/// Queue a work item.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -291,36 +219,18 @@ namespace Amib.Threading
|
|||||||
/// <returns>Returns a IWorkItemResult object, but its GetResult() will always return null</returns>
|
/// <returns>Returns a IWorkItemResult object, but its GetResult() will always return null</returns>
|
||||||
IWorkItemResult QueueWorkItem<T1, T2>(Action<T1, T2> action, T1 arg1, T2 arg2);
|
IWorkItemResult QueueWorkItem<T1, T2>(Action<T1, T2> action, T1 arg1, T2 arg2);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Queue a work item.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Returns a IWorkItemResult object, but its GetResult() will always return null</returns>
|
|
||||||
IWorkItemResult QueueWorkItem<T1, T2>(Action<T1, T2> action, T1 arg1, T2 arg2, WorkItemPriority priority);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queue a work item.
|
/// Queue a work item.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Returns a IWorkItemResult object, but its GetResult() will always return null</returns>
|
/// <returns>Returns a IWorkItemResult object, but its GetResult() will always return null</returns>
|
||||||
IWorkItemResult QueueWorkItem<T1, T2, T3>(Action<T1, T2, T3> action, T1 arg1, T2 arg2, T3 arg3);
|
IWorkItemResult QueueWorkItem<T1, T2, T3>(Action<T1, T2, T3> action, T1 arg1, T2 arg2, T3 arg3);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Queue a work item.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Returns a IWorkItemResult object, but its GetResult() will always return null</returns>
|
|
||||||
IWorkItemResult QueueWorkItem<T1, T2, T3>(Action<T1, T2, T3> action, T1 arg1, T2 arg2, T3 arg3, WorkItemPriority priority);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queue a work item.
|
/// Queue a work item.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Returns a IWorkItemResult object, but its GetResult() will always return null</returns>
|
/// <returns>Returns a IWorkItemResult object, but its GetResult() will always return null</returns>
|
||||||
IWorkItemResult QueueWorkItem<T1, T2, T3, T4>(Action<T1, T2, T3, T4> action, T1 arg1, T2 arg2, T3 arg3, T4 arg4);
|
IWorkItemResult QueueWorkItem<T1, T2, T3, T4>(Action<T1, T2, T3, T4> action, T1 arg1, T2 arg2, T3 arg3, T4 arg4);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Queue a work item.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Returns a IWorkItemResult object, but its GetResult() will always return null</returns>
|
|
||||||
IWorkItemResult QueueWorkItem<T1, T2, T3, T4>(Action<T1, T2, T3, T4> action, T1 arg1, T2 arg2, T3 arg3, T4 arg4, WorkItemPriority priority);
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region QueueWorkItem(Func<...>)
|
#region QueueWorkItem(Func<...>)
|
||||||
@@ -590,11 +500,6 @@ namespace Amib.Threading
|
|||||||
/// <returns>Returns true if the work item was not completed, otherwise false.</returns>
|
/// <returns>Returns true if the work item was not completed, otherwise false.</returns>
|
||||||
bool Cancel(bool abortExecution);
|
bool Cancel(bool abortExecution);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get the work item's priority
|
|
||||||
/// </summary>
|
|
||||||
WorkItemPriority WorkItemPriority { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return the result, same as GetResult()
|
/// Return the result, same as GetResult()
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -19,9 +19,4 @@ namespace Amib.Threading.Internal
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
IWorkItemResult GetWorkItemResult();
|
IWorkItemResult GetWorkItemResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IHasWorkItemPriority
|
|
||||||
{
|
|
||||||
WorkItemPriority WorkItemPriority { get; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
238
ThirdParty/SmartThreadPool/PriorityQueue.cs
vendored
238
ThirdParty/SmartThreadPool/PriorityQueue.cs
vendored
@@ -1,238 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
namespace Amib.Threading.Internal
|
|
||||||
{
|
|
||||||
#region PriorityQueue class
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// PriorityQueue class
|
|
||||||
/// This class is not thread safe because we use external lock
|
|
||||||
/// </summary>
|
|
||||||
public sealed class PriorityQueue : IEnumerable
|
|
||||||
{
|
|
||||||
#region Private members
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The number of queues, there is one for each type of priority
|
|
||||||
/// </summary>
|
|
||||||
private const int _queuesCount = WorkItemPriority.Highest-WorkItemPriority.Lowest+1;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Work items queues. There is one for each type of priority
|
|
||||||
/// </summary>
|
|
||||||
private readonly Queue<IHasWorkItemPriority>[] _queues = new Queue<IHasWorkItemPriority>[_queuesCount];
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The total number of work items within the queues
|
|
||||||
/// </summary>
|
|
||||||
private int _workItemsCount;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Use with IEnumerable interface
|
|
||||||
/// </summary>
|
|
||||||
private int _version;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Contructor
|
|
||||||
|
|
||||||
public PriorityQueue()
|
|
||||||
{
|
|
||||||
for(int i = 0; i < _queues.Length; ++i)
|
|
||||||
{
|
|
||||||
_queues[i] = new Queue<IHasWorkItemPriority>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Methods
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Enqueue a work item.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="workItem">A work item</param>
|
|
||||||
public void Enqueue(IHasWorkItemPriority workItem)
|
|
||||||
{
|
|
||||||
Debug.Assert(null != workItem);
|
|
||||||
|
|
||||||
int queueIndex = _queuesCount-(int)workItem.WorkItemPriority-1;
|
|
||||||
Debug.Assert(queueIndex >= 0);
|
|
||||||
Debug.Assert(queueIndex < _queuesCount);
|
|
||||||
|
|
||||||
_queues[queueIndex].Enqueue(workItem);
|
|
||||||
++_workItemsCount;
|
|
||||||
++_version;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Dequeque a work item.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Returns the next work item</returns>
|
|
||||||
public IHasWorkItemPriority Dequeue()
|
|
||||||
{
|
|
||||||
IHasWorkItemPriority workItem = null;
|
|
||||||
|
|
||||||
if(_workItemsCount > 0)
|
|
||||||
{
|
|
||||||
int queueIndex = GetNextNonEmptyQueue(-1);
|
|
||||||
Debug.Assert(queueIndex >= 0);
|
|
||||||
workItem = _queues[queueIndex].Dequeue();
|
|
||||||
Debug.Assert(null != workItem);
|
|
||||||
--_workItemsCount;
|
|
||||||
++_version;
|
|
||||||
}
|
|
||||||
|
|
||||||
return workItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Find the next non empty queue starting at queue queueIndex+1
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="queueIndex">The index-1 to start from</param>
|
|
||||||
/// <returns>
|
|
||||||
/// The index of the next non empty queue or -1 if all the queues are empty
|
|
||||||
/// </returns>
|
|
||||||
private int GetNextNonEmptyQueue(int queueIndex)
|
|
||||||
{
|
|
||||||
for(int i = queueIndex+1; i < _queuesCount; ++i)
|
|
||||||
{
|
|
||||||
if(_queues[i].Count > 0)
|
|
||||||
{
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The number of work items
|
|
||||||
/// </summary>
|
|
||||||
public int Count
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _workItemsCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clear all the work items
|
|
||||||
/// </summary>
|
|
||||||
public void Clear()
|
|
||||||
{
|
|
||||||
if (_workItemsCount > 0)
|
|
||||||
{
|
|
||||||
foreach(Queue<IHasWorkItemPriority> queue in _queues)
|
|
||||||
{
|
|
||||||
queue.Clear();
|
|
||||||
}
|
|
||||||
_workItemsCount = 0;
|
|
||||||
++_version;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IEnumerable Members
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns an enumerator to iterate over the work items
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Returns an enumerator</returns>
|
|
||||||
public IEnumerator GetEnumerator()
|
|
||||||
{
|
|
||||||
return new PriorityQueueEnumerator(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region PriorityQueueEnumerator
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The class the implements the enumerator
|
|
||||||
/// </summary>
|
|
||||||
private class PriorityQueueEnumerator : IEnumerator
|
|
||||||
{
|
|
||||||
private readonly PriorityQueue _priorityQueue;
|
|
||||||
private int _version;
|
|
||||||
private int _queueIndex;
|
|
||||||
private IEnumerator _enumerator;
|
|
||||||
|
|
||||||
public PriorityQueueEnumerator(PriorityQueue priorityQueue)
|
|
||||||
{
|
|
||||||
_priorityQueue = priorityQueue;
|
|
||||||
_version = _priorityQueue._version;
|
|
||||||
_queueIndex = _priorityQueue.GetNextNonEmptyQueue(-1);
|
|
||||||
if (_queueIndex >= 0)
|
|
||||||
{
|
|
||||||
_enumerator = _priorityQueue._queues[_queueIndex].GetEnumerator();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_enumerator = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#region IEnumerator Members
|
|
||||||
|
|
||||||
public void Reset()
|
|
||||||
{
|
|
||||||
_version = _priorityQueue._version;
|
|
||||||
_queueIndex = _priorityQueue.GetNextNonEmptyQueue(-1);
|
|
||||||
if (_queueIndex >= 0)
|
|
||||||
{
|
|
||||||
_enumerator = _priorityQueue._queues[_queueIndex].GetEnumerator();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_enumerator = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public object Current
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
Debug.Assert(null != _enumerator);
|
|
||||||
return _enumerator.Current;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool MoveNext()
|
|
||||||
{
|
|
||||||
if (null == _enumerator)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(_version != _priorityQueue._version)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("The collection has been modified");
|
|
||||||
|
|
||||||
}
|
|
||||||
if (!_enumerator.MoveNext())
|
|
||||||
{
|
|
||||||
_queueIndex = _priorityQueue.GetNextNonEmptyQueue(_queueIndex);
|
|
||||||
if(-1 == _queueIndex)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
_enumerator = _priorityQueue._queues[_queueIndex].GetEnumerator();
|
|
||||||
_enumerator.MoveNext();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
@@ -151,11 +151,6 @@ namespace Amib.Threading
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly PostExecuteWorkItemCallback DefaultPostExecuteWorkItemCallback;
|
public static readonly PostExecuteWorkItemCallback DefaultPostExecuteWorkItemCallback;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The default work item priority (WorkItemPriority.Normal)
|
|
||||||
/// </summary>
|
|
||||||
public const WorkItemPriority DefaultWorkItemPriority = WorkItemPriority.Normal;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The default is to work on work items as soon as they arrive
|
/// The default is to work on work items as soon as they arrive
|
||||||
/// and not to wait for the start. (false)
|
/// and not to wait for the start. (false)
|
||||||
|
|||||||
13
ThirdParty/SmartThreadPool/WIGStartInfo.cs
vendored
13
ThirdParty/SmartThreadPool/WIGStartInfo.cs
vendored
@@ -12,7 +12,6 @@ namespace Amib.Threading
|
|||||||
private CallToPostExecute _callToPostExecute;
|
private CallToPostExecute _callToPostExecute;
|
||||||
private PostExecuteWorkItemCallback _postExecuteWorkItemCallback;
|
private PostExecuteWorkItemCallback _postExecuteWorkItemCallback;
|
||||||
private bool _startSuspended;
|
private bool _startSuspended;
|
||||||
private WorkItemPriority _workItemPriority;
|
|
||||||
private bool _fillStateWithArgs;
|
private bool _fillStateWithArgs;
|
||||||
|
|
||||||
protected bool _readOnly;
|
protected bool _readOnly;
|
||||||
@@ -20,7 +19,6 @@ namespace Amib.Threading
|
|||||||
public WIGStartInfo()
|
public WIGStartInfo()
|
||||||
{
|
{
|
||||||
_fillStateWithArgs = SmartThreadPool.DefaultFillStateWithArgs;
|
_fillStateWithArgs = SmartThreadPool.DefaultFillStateWithArgs;
|
||||||
_workItemPriority = SmartThreadPool.DefaultWorkItemPriority;
|
|
||||||
_startSuspended = SmartThreadPool.DefaultStartSuspended;
|
_startSuspended = SmartThreadPool.DefaultStartSuspended;
|
||||||
_postExecuteWorkItemCallback = SmartThreadPool.DefaultPostExecuteWorkItemCallback;
|
_postExecuteWorkItemCallback = SmartThreadPool.DefaultPostExecuteWorkItemCallback;
|
||||||
_callToPostExecute = SmartThreadPool.DefaultCallToPostExecute;
|
_callToPostExecute = SmartThreadPool.DefaultCallToPostExecute;
|
||||||
@@ -34,7 +32,6 @@ namespace Amib.Threading
|
|||||||
_disposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;
|
_disposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;
|
||||||
_callToPostExecute = wigStartInfo.CallToPostExecute;
|
_callToPostExecute = wigStartInfo.CallToPostExecute;
|
||||||
_postExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback;
|
_postExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback;
|
||||||
_workItemPriority = wigStartInfo.WorkItemPriority;
|
|
||||||
_startSuspended = wigStartInfo.StartSuspended;
|
_startSuspended = wigStartInfo.StartSuspended;
|
||||||
_fillStateWithArgs = wigStartInfo.FillStateWithArgs;
|
_fillStateWithArgs = wigStartInfo.FillStateWithArgs;
|
||||||
}
|
}
|
||||||
@@ -117,16 +114,6 @@ namespace Amib.Threading
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get/Set the default priority that a work item gets when it is enqueued
|
|
||||||
/// </summary>
|
|
||||||
public virtual WorkItemPriority WorkItemPriority
|
|
||||||
{
|
|
||||||
get { return _workItemPriority; }
|
|
||||||
set { _workItemPriority = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get/Set the if QueueWorkItem of Action<...>/Func<...> fill the
|
/// Get/Set the if QueueWorkItem of Action<...>/Func<...> 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.
|
||||||
|
|||||||
@@ -112,14 +112,6 @@ namespace Amib.Threading.Internal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public WorkItemPriority WorkItemPriority
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _workItem._workItemInfo.WorkItemPriority;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return the result, same as GetResult()
|
/// Return the result, same as GetResult()
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
19
ThirdParty/SmartThreadPool/WorkItem.cs
vendored
19
ThirdParty/SmartThreadPool/WorkItem.cs
vendored
@@ -7,7 +7,7 @@ namespace Amib.Threading.Internal
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Holds a callback delegate and the state for that delegate.
|
/// Holds a callback delegate and the state for that delegate.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class WorkItem : IHasWorkItemPriority
|
public partial class WorkItem
|
||||||
{
|
{
|
||||||
#region WorkItemState enum
|
#region WorkItemState enum
|
||||||
|
|
||||||
@@ -955,22 +955,7 @@ namespace Amib.Threading.Internal
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region IHasWorkItemPriority Members
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the priority of the work item
|
|
||||||
/// </summary>
|
|
||||||
public WorkItemPriority WorkItemPriority
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _workItemInfo.WorkItemPriority;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
internal event WorkItemStateCallback OnWorkItemStarted
|
internal event WorkItemStateCallback OnWorkItemStarted
|
||||||
{
|
{
|
||||||
add
|
add
|
||||||
|
|||||||
139
ThirdParty/SmartThreadPool/WorkItemFactory.cs
vendored
139
ThirdParty/SmartThreadPool/WorkItemFactory.cs
vendored
@@ -34,7 +34,6 @@ namespace Amib.Threading.Internal
|
|||||||
PostExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback,
|
PostExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback,
|
||||||
CallToPostExecute = wigStartInfo.CallToPostExecute,
|
CallToPostExecute = wigStartInfo.CallToPostExecute,
|
||||||
DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects,
|
DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects,
|
||||||
WorkItemPriority = wigStartInfo.WorkItemPriority
|
|
||||||
};
|
};
|
||||||
|
|
||||||
WorkItem workItem = new WorkItem(
|
WorkItem workItem = new WorkItem(
|
||||||
@@ -57,20 +56,6 @@ namespace Amib.Threading.Internal
|
|||||||
return CreateWorkItem(workItemsGroup, wigStartInfo, callback, null);
|
return CreateWorkItem(workItemsGroup, wigStartInfo, callback, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Create a new work item
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="workItemsGroup">The WorkItemsGroup of this workitem</param>
|
|
||||||
/// <param name="wigStartInfo">Work item group start information</param>
|
|
||||||
/// <param name="callback">A callback to execute</param>
|
|
||||||
/// <param name="workItemPriority">The priority of the work item</param>
|
|
||||||
/// <returns>Returns a work item</returns>
|
|
||||||
public static WorkItem CreateWorkItem( IWorkItemsGroup workItemsGroup, WIGStartInfo wigStartInfo,
|
|
||||||
WorkItemCallback callback, WorkItemPriority workItemPriority)
|
|
||||||
{
|
|
||||||
return CreateWorkItem(workItemsGroup, wigStartInfo, callback, null, workItemPriority);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new work item
|
/// Create a new work item
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -111,7 +96,6 @@ namespace Amib.Threading.Internal
|
|||||||
PostExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback,
|
PostExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback,
|
||||||
CallToPostExecute = wigStartInfo.CallToPostExecute,
|
CallToPostExecute = wigStartInfo.CallToPostExecute,
|
||||||
DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects,
|
DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects,
|
||||||
WorkItemPriority = wigStartInfo.WorkItemPriority
|
|
||||||
};
|
};
|
||||||
|
|
||||||
WorkItem workItem = new WorkItem(
|
WorkItem workItem = new WorkItem(
|
||||||
@@ -122,42 +106,6 @@ namespace Amib.Threading.Internal
|
|||||||
return workItem;
|
return workItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Create a new work item
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="workItemsGroup">The work items group</param>
|
|
||||||
/// <param name="wigStartInfo">Work item group start information</param>
|
|
||||||
/// <param name="callback">A callback to execute</param>
|
|
||||||
/// <param name="state">
|
|
||||||
/// The context object of the work item. Used for passing arguments to the work item.
|
|
||||||
/// </param>
|
|
||||||
/// <param name="workItemPriority">The work item priority</param>
|
|
||||||
/// <returns>Returns a work item</returns>
|
|
||||||
public static WorkItem CreateWorkItem(
|
|
||||||
IWorkItemsGroup workItemsGroup,
|
|
||||||
WIGStartInfo wigStartInfo,
|
|
||||||
WorkItemCallback callback,
|
|
||||||
object state,
|
|
||||||
WorkItemPriority workItemPriority)
|
|
||||||
{
|
|
||||||
ValidateCallback(callback);
|
|
||||||
|
|
||||||
WorkItemInfo workItemInfo = new WorkItemInfo();
|
|
||||||
workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext;
|
|
||||||
workItemInfo.PostExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback;
|
|
||||||
workItemInfo.CallToPostExecute = wigStartInfo.CallToPostExecute;
|
|
||||||
workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;
|
|
||||||
workItemInfo.WorkItemPriority = workItemPriority;
|
|
||||||
|
|
||||||
WorkItem workItem = new WorkItem(
|
|
||||||
workItemsGroup,
|
|
||||||
workItemInfo,
|
|
||||||
callback,
|
|
||||||
state);
|
|
||||||
|
|
||||||
return workItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new work item
|
/// Create a new work item
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -212,48 +160,6 @@ namespace Amib.Threading.Internal
|
|||||||
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;
|
|
||||||
|
|
||||||
WorkItem workItem = new WorkItem(
|
|
||||||
workItemsGroup,
|
|
||||||
workItemInfo,
|
|
||||||
callback,
|
|
||||||
state);
|
|
||||||
|
|
||||||
return workItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Create a new work item
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="workItemsGroup">The work items group</param>
|
|
||||||
/// <param name="wigStartInfo">Work item group start information</param>
|
|
||||||
/// <param name="callback">A callback to execute</param>
|
|
||||||
/// <param name="state">
|
|
||||||
/// The context object of the work item. Used for passing arguments to the work item.
|
|
||||||
/// </param>
|
|
||||||
/// <param name="postExecuteWorkItemCallback">
|
|
||||||
/// A delegate to call after the callback completion
|
|
||||||
/// </param>
|
|
||||||
/// <param name="workItemPriority">The work item priority</param>
|
|
||||||
/// <returns>Returns a work item</returns>
|
|
||||||
public static WorkItem CreateWorkItem(
|
|
||||||
IWorkItemsGroup workItemsGroup,
|
|
||||||
WIGStartInfo wigStartInfo,
|
|
||||||
WorkItemCallback callback,
|
|
||||||
object state,
|
|
||||||
PostExecuteWorkItemCallback postExecuteWorkItemCallback,
|
|
||||||
WorkItemPriority workItemPriority)
|
|
||||||
{
|
|
||||||
ValidateCallback(callback);
|
|
||||||
ValidateCallback(postExecuteWorkItemCallback);
|
|
||||||
|
|
||||||
WorkItemInfo workItemInfo = new WorkItemInfo();
|
|
||||||
workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext;
|
|
||||||
workItemInfo.PostExecuteWorkItemCallback = postExecuteWorkItemCallback;
|
|
||||||
workItemInfo.CallToPostExecute = wigStartInfo.CallToPostExecute;
|
|
||||||
workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;
|
|
||||||
workItemInfo.WorkItemPriority = workItemPriority;
|
|
||||||
|
|
||||||
WorkItem workItem = new WorkItem(
|
WorkItem workItem = new WorkItem(
|
||||||
workItemsGroup,
|
workItemsGroup,
|
||||||
@@ -294,7 +200,6 @@ namespace Amib.Threading.Internal
|
|||||||
workItemInfo.PostExecuteWorkItemCallback = postExecuteWorkItemCallback;
|
workItemInfo.PostExecuteWorkItemCallback = postExecuteWorkItemCallback;
|
||||||
workItemInfo.CallToPostExecute = callToPostExecute;
|
workItemInfo.CallToPostExecute = callToPostExecute;
|
||||||
workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;
|
workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;
|
||||||
workItemInfo.WorkItemPriority = wigStartInfo.WorkItemPriority;
|
|
||||||
|
|
||||||
WorkItem workItem = new WorkItem(
|
WorkItem workItem = new WorkItem(
|
||||||
workItemsGroup,
|
workItemsGroup,
|
||||||
@@ -305,50 +210,6 @@ namespace Amib.Threading.Internal
|
|||||||
return workItem;
|
return workItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Create a new work item
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="workItemsGroup">The work items group</param>
|
|
||||||
/// <param name="wigStartInfo">Work item group start information</param>
|
|
||||||
/// <param name="callback">A callback to execute</param>
|
|
||||||
/// <param name="state">
|
|
||||||
/// The context object of the work item. Used for passing arguments to the work item.
|
|
||||||
/// </param>
|
|
||||||
/// <param name="postExecuteWorkItemCallback">
|
|
||||||
/// A delegate to call after the callback completion
|
|
||||||
/// </param>
|
|
||||||
/// <param name="callToPostExecute">Indicates on which cases to call to the post execute callback</param>
|
|
||||||
/// <param name="workItemPriority">The work item priority</param>
|
|
||||||
/// <returns>Returns a work item</returns>
|
|
||||||
public static WorkItem CreateWorkItem(
|
|
||||||
IWorkItemsGroup workItemsGroup,
|
|
||||||
WIGStartInfo wigStartInfo,
|
|
||||||
WorkItemCallback callback,
|
|
||||||
object state,
|
|
||||||
PostExecuteWorkItemCallback postExecuteWorkItemCallback,
|
|
||||||
CallToPostExecute callToPostExecute,
|
|
||||||
WorkItemPriority workItemPriority)
|
|
||||||
{
|
|
||||||
|
|
||||||
ValidateCallback(callback);
|
|
||||||
ValidateCallback(postExecuteWorkItemCallback);
|
|
||||||
|
|
||||||
WorkItemInfo workItemInfo = new WorkItemInfo();
|
|
||||||
workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext;
|
|
||||||
workItemInfo.PostExecuteWorkItemCallback = postExecuteWorkItemCallback;
|
|
||||||
workItemInfo.CallToPostExecute = callToPostExecute;
|
|
||||||
workItemInfo.WorkItemPriority = workItemPriority;
|
|
||||||
workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;
|
|
||||||
|
|
||||||
WorkItem workItem = new WorkItem(
|
|
||||||
workItemsGroup,
|
|
||||||
workItemInfo,
|
|
||||||
callback,
|
|
||||||
state);
|
|
||||||
|
|
||||||
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)
|
||||||
|
|||||||
7
ThirdParty/SmartThreadPool/WorkItemInfo.cs
vendored
7
ThirdParty/SmartThreadPool/WorkItemInfo.cs
vendored
@@ -13,7 +13,6 @@ namespace Amib.Threading
|
|||||||
DisposeOfStateObjects = SmartThreadPool.DefaultDisposeOfStateObjects;
|
DisposeOfStateObjects = SmartThreadPool.DefaultDisposeOfStateObjects;
|
||||||
CallToPostExecute = SmartThreadPool.DefaultCallToPostExecute;
|
CallToPostExecute = SmartThreadPool.DefaultCallToPostExecute;
|
||||||
PostExecuteWorkItemCallback = SmartThreadPool.DefaultPostExecuteWorkItemCallback;
|
PostExecuteWorkItemCallback = SmartThreadPool.DefaultPostExecuteWorkItemCallback;
|
||||||
WorkItemPriority = SmartThreadPool.DefaultWorkItemPriority;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public WorkItemInfo(WorkItemInfo workItemInfo)
|
public WorkItemInfo(WorkItemInfo workItemInfo)
|
||||||
@@ -22,7 +21,6 @@ namespace Amib.Threading
|
|||||||
DisposeOfStateObjects = workItemInfo.DisposeOfStateObjects;
|
DisposeOfStateObjects = workItemInfo.DisposeOfStateObjects;
|
||||||
CallToPostExecute = workItemInfo.CallToPostExecute;
|
CallToPostExecute = workItemInfo.CallToPostExecute;
|
||||||
PostExecuteWorkItemCallback = workItemInfo.PostExecuteWorkItemCallback;
|
PostExecuteWorkItemCallback = workItemInfo.PostExecuteWorkItemCallback;
|
||||||
WorkItemPriority = workItemInfo.WorkItemPriority;
|
|
||||||
Timeout = workItemInfo.Timeout;
|
Timeout = workItemInfo.Timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,11 +44,6 @@ namespace Amib.Threading
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public PostExecuteWorkItemCallback PostExecuteWorkItemCallback { get; set; }
|
public PostExecuteWorkItemCallback PostExecuteWorkItemCallback { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get/Set the work item's priority
|
|
||||||
/// </summary>
|
|
||||||
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!
|
||||||
|
|||||||
@@ -91,11 +91,6 @@ namespace Amib.Threading.Internal
|
|||||||
return _workItemResult.Cancel(abortExecution);
|
return _workItemResult.Cancel(abortExecution);
|
||||||
}
|
}
|
||||||
|
|
||||||
public WorkItemPriority WorkItemPriority
|
|
||||||
{
|
|
||||||
get { return _workItemResult.WorkItemPriority; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public TResult Result
|
public TResult Result
|
||||||
{
|
{
|
||||||
get { return (TResult)_workItemResult.Result; }
|
get { return (TResult)_workItemResult.Result; }
|
||||||
|
|||||||
5
ThirdParty/SmartThreadPool/WorkItemsGroup.cs
vendored
5
ThirdParty/SmartThreadPool/WorkItemsGroup.cs
vendored
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@@ -42,7 +43,7 @@ namespace Amib.Threading.Internal
|
|||||||
/// 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 Queue<WorkItem> _workItemsQueue;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Indicate how many work items are waiting in the SmartThreadPool
|
/// Indicate how many work items are waiting in the SmartThreadPool
|
||||||
@@ -93,7 +94,7 @@ namespace Amib.Threading.Internal
|
|||||||
_stp = stp;
|
_stp = stp;
|
||||||
_concurrency = concurrency;
|
_concurrency = concurrency;
|
||||||
_workItemsGroupStartInfo = new WIGStartInfo(wigStartInfo).AsReadOnly();
|
_workItemsGroupStartInfo = new WIGStartInfo(wigStartInfo).AsReadOnly();
|
||||||
_workItemsQueue = new PriorityQueue();
|
_workItemsQueue = new Queue<WorkItem>();
|
||||||
Name = "WorkItemsGroup";
|
Name = "WorkItemsGroup";
|
||||||
|
|
||||||
// The _workItemsInStpQueue gets the number of currently executing work items,
|
// The _workItemsInStpQueue gets the number of currently executing work items,
|
||||||
|
|||||||
122
ThirdParty/SmartThreadPool/WorkItemsGroupBase.cs
vendored
122
ThirdParty/SmartThreadPool/WorkItemsGroupBase.cs
vendored
@@ -128,20 +128,6 @@ namespace Amib.Threading.Internal
|
|||||||
return workItem.GetWorkItemResult();
|
return workItem.GetWorkItemResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Queue a work item
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="callback">A callback to execute</param>
|
|
||||||
/// <param name="workItemPriority">The priority of the work item</param>
|
|
||||||
/// <returns>Returns a work item result</returns>
|
|
||||||
public IWorkItemResult QueueWorkItem(WorkItemCallback callback, WorkItemPriority workItemPriority)
|
|
||||||
{
|
|
||||||
PreQueueWorkItem();
|
|
||||||
WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, workItemPriority);
|
|
||||||
Enqueue(workItem);
|
|
||||||
return workItem.GetWorkItemResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queue a work item
|
/// Queue a work item
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -171,23 +157,6 @@ namespace Amib.Threading.Internal
|
|||||||
return workItem.GetWorkItemResult();
|
return workItem.GetWorkItemResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Queue a work item
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="callback">A callback to execute</param>
|
|
||||||
/// <param name="state">
|
|
||||||
/// The context object of the work item. Used for passing arguments to the work item.
|
|
||||||
/// </param>
|
|
||||||
/// <param name="workItemPriority">The work item priority</param>
|
|
||||||
/// <returns>Returns a work item result</returns>
|
|
||||||
public IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state, WorkItemPriority workItemPriority)
|
|
||||||
{
|
|
||||||
PreQueueWorkItem();
|
|
||||||
WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, workItemPriority);
|
|
||||||
Enqueue(workItem);
|
|
||||||
return workItem.GetWorkItemResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queue a work item
|
/// Queue a work item
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -225,26 +194,6 @@ namespace Amib.Threading.Internal
|
|||||||
return workItem.GetWorkItemResult();
|
return workItem.GetWorkItemResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Queue a work item
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="callback">A callback to execute</param>
|
|
||||||
/// <param name="state">
|
|
||||||
/// The context object of the work item. Used for passing arguments to the work item.
|
|
||||||
/// </param>
|
|
||||||
/// <param name="postExecuteWorkItemCallback">
|
|
||||||
/// A delegate to call after the callback completion
|
|
||||||
/// </param>
|
|
||||||
/// <param name="workItemPriority">The work item priority</param>
|
|
||||||
/// <returns>Returns a work item result</returns>
|
|
||||||
public IWorkItemResult QueueWorkItem( WorkItemCallback callback, object state, PostExecuteWorkItemCallback postExecuteWorkItemCallback,
|
|
||||||
WorkItemPriority workItemPriority)
|
|
||||||
{
|
|
||||||
PreQueueWorkItem();
|
|
||||||
WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback, workItemPriority);
|
|
||||||
Enqueue(workItem);
|
|
||||||
return workItem.GetWorkItemResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queue a work item
|
/// Queue a work item
|
||||||
@@ -267,39 +216,11 @@ namespace Amib.Threading.Internal
|
|||||||
return workItem.GetWorkItemResult();
|
return workItem.GetWorkItemResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Queue a work item
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="callback">A callback to execute</param>
|
|
||||||
/// <param name="state">
|
|
||||||
/// The context object of the work item. Used for passing arguments to the work item.
|
|
||||||
/// </param>
|
|
||||||
/// <param name="postExecuteWorkItemCallback">
|
|
||||||
/// A delegate to call after the callback completion
|
|
||||||
/// </param>
|
|
||||||
/// <param name="callToPostExecute">Indicates on which cases to call to the post execute callback</param>
|
|
||||||
/// <param name="workItemPriority">The work item priority</param>
|
|
||||||
/// <returns>Returns a work item result</returns>
|
|
||||||
public IWorkItemResult QueueWorkItem( WorkItemCallback callback, object state,
|
|
||||||
PostExecuteWorkItemCallback postExecuteWorkItemCallback, CallToPostExecute callToPostExecute,
|
|
||||||
WorkItemPriority workItemPriority)
|
|
||||||
{
|
|
||||||
PreQueueWorkItem();
|
|
||||||
WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback, callToPostExecute, workItemPriority);
|
|
||||||
Enqueue(workItem);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IWorkItemResult QueueWorkItem (Action action, WorkItemPriority priority)
|
|
||||||
{
|
{
|
||||||
PreQueueWorkItem ();
|
PreQueueWorkItem ();
|
||||||
WorkItem workItem = WorkItemFactory.CreateWorkItem (
|
WorkItem workItem = WorkItemFactory.CreateWorkItem (
|
||||||
@@ -309,17 +230,12 @@ namespace Amib.Threading.Internal
|
|||||||
{
|
{
|
||||||
action.Invoke ();
|
action.Invoke ();
|
||||||
return null;
|
return null;
|
||||||
}, 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IWorkItemResult QueueWorkItem<T> (Action<T> action, T arg, WorkItemPriority priority)
|
|
||||||
{
|
{
|
||||||
PreQueueWorkItem ();
|
PreQueueWorkItem ();
|
||||||
WorkItem workItem = WorkItemFactory.CreateWorkItem (
|
WorkItem workItem = WorkItemFactory.CreateWorkItem (
|
||||||
@@ -330,17 +246,12 @@ namespace Amib.Threading.Internal
|
|||||||
action.Invoke (arg);
|
action.Invoke (arg);
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
WIGStartInfo.FillStateWithArgs ? new object[] { arg } : null, priority);
|
WIGStartInfo.FillStateWithArgs ? new object[] { arg } : null);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 (
|
||||||
@@ -351,18 +262,12 @@ namespace Amib.Threading.Internal
|
|||||||
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);
|
||||||
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);
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 (
|
||||||
@@ -373,20 +278,13 @@ namespace Amib.Threading.Internal
|
|||||||
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);
|
||||||
Enqueue (workItem);
|
Enqueue (workItem);
|
||||||
return workItem.GetWorkItemResult ();
|
return workItem.GetWorkItemResult ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IWorkItemResult QueueWorkItem<T1, T2, T3, T4>(
|
|
||||||
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,
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
PreQueueWorkItem ();
|
PreQueueWorkItem ();
|
||||||
WorkItem workItem = WorkItemFactory.CreateWorkItem (
|
WorkItem workItem = WorkItemFactory.CreateWorkItem (
|
||||||
@@ -397,7 +295,7 @@ namespace Amib.Threading.Internal
|
|||||||
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);
|
||||||
Enqueue (workItem);
|
Enqueue (workItem);
|
||||||
return workItem.GetWorkItemResult ();
|
return workItem.GetWorkItemResult ();
|
||||||
}
|
}
|
||||||
|
|||||||
6
ThirdParty/SmartThreadPool/WorkItemsQueue.cs
vendored
6
ThirdParty/SmartThreadPool/WorkItemsQueue.cs
vendored
@@ -26,7 +26,7 @@ namespace Amib.Threading.Internal
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Work items queue
|
/// Work items queue
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly PriorityQueue _workItems = new PriorityQueue();
|
private readonly Queue<WorkItem> _workItems = new Queue<WorkItem>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Indicate that work items are allowed to be queued
|
/// Indicate that work items are allowed to be queued
|
||||||
@@ -166,7 +166,7 @@ namespace Amib.Threading.Internal
|
|||||||
// If there are waiting work items then take one and return.
|
// If there are waiting work items then take one and return.
|
||||||
if (_workItems.Count > 0)
|
if (_workItems.Count > 0)
|
||||||
{
|
{
|
||||||
workItem = _workItems.Dequeue() as WorkItem;
|
workItem = _workItems.Dequeue();
|
||||||
return workItem;
|
return workItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +224,7 @@ namespace Amib.Threading.Internal
|
|||||||
|
|
||||||
if (null == workItem)
|
if (null == workItem)
|
||||||
{
|
{
|
||||||
workItem = _workItems.Dequeue() as WorkItem;
|
workItem = _workItems.Dequeue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user