From 206fb306a7820cf593570e35ddfa8e7c5a10e449 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Wed, 1 May 2013 19:01:43 +0100
Subject: Update SmartThreadPool to latest version 2.2.3 with a major and minor
change.
SmartThreadPool code comes from http://www.codeproject.com/Articles/7933/Smart-Thread-Pool
This version implements thread abort (via WorkItem.Cancel(true)), threadpool naming, max thread stack, etc. so we no longer need to manually patch those.
However, two changes have been made to stock 2.2.3.
Major change: WorkItem.Cancel(bool abortExecution) in our version does not succeed if the work item was in progress and thread abort was not specified.
This is to match previous behaviour where we handle co-operative termination via another mechanism rather than checking WorkItem.IsCanceled.
Minor change: Did not add STP's StopWatch implementation as this is only used WinCE and Silverlight and causes a build clash with System.Diagnostics.StopWatch
The reason for updating is to see if this improves http://opensimulator.org/mantis/view.php?id=6557 and http://opensimulator.org/mantis/view.php?id=6586
---
ThirdParty/SmartThreadPool/WorkItemFactory.cs | 676 +++++++++++++-------------
1 file changed, 343 insertions(+), 333 deletions(-)
(limited to 'ThirdParty/SmartThreadPool/WorkItemFactory.cs')
diff --git a/ThirdParty/SmartThreadPool/WorkItemFactory.cs b/ThirdParty/SmartThreadPool/WorkItemFactory.cs
index dfcb54f..2d6601e 100644
--- a/ThirdParty/SmartThreadPool/WorkItemFactory.cs
+++ b/ThirdParty/SmartThreadPool/WorkItemFactory.cs
@@ -1,333 +1,343 @@
-// Ami Bar
-// amibar@gmail.com
-
-using System;
-
-namespace Amib.Threading.Internal
-{
- #region WorkItemFactory class
-
- public class WorkItemFactory
- {
- ///
- /// Create a new work item
- ///
- /// Work item group start information
- /// A callback to execute
- /// Returns a work item
- public static WorkItem CreateWorkItem(
- IWorkItemsGroup workItemsGroup,
- WIGStartInfo wigStartInfo,
- WorkItemCallback callback)
- {
- return CreateWorkItem(workItemsGroup, wigStartInfo, callback, null);
- }
-
- ///
- /// Create a new work item
- ///
- /// Work item group start information
- /// A callback to execute
- /// The priority of the work item
- /// Returns a work item
- public static WorkItem CreateWorkItem(
- IWorkItemsGroup workItemsGroup,
- WIGStartInfo wigStartInfo,
- WorkItemCallback callback,
- WorkItemPriority workItemPriority)
- {
- return CreateWorkItem(workItemsGroup, wigStartInfo, callback, null, workItemPriority);
- }
-
- ///
- /// Create a new work item
- ///
- /// Work item group start information
- /// Work item info
- /// A callback to execute
- /// Returns a work item
- public static WorkItem CreateWorkItem(
- IWorkItemsGroup workItemsGroup,
- WIGStartInfo wigStartInfo,
- WorkItemInfo workItemInfo,
- WorkItemCallback callback)
- {
- return CreateWorkItem(
- workItemsGroup,
- wigStartInfo,
- workItemInfo,
- callback,
- null);
- }
-
- ///
- /// Create a new work item
- ///
- /// Work item group start information
- /// A callback to execute
- ///
- /// The context object of the work item. Used for passing arguments to the work item.
- ///
- /// Returns a work item
- public static WorkItem CreateWorkItem(
- IWorkItemsGroup workItemsGroup,
- WIGStartInfo wigStartInfo,
- WorkItemCallback callback,
- object state)
- {
- ValidateCallback(callback);
-
- WorkItemInfo workItemInfo = new WorkItemInfo();
- workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext;
- workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext;
- workItemInfo.PostExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback;
- workItemInfo.CallToPostExecute = wigStartInfo.CallToPostExecute;
- workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;
-
- WorkItem workItem = new WorkItem(
- workItemsGroup,
- workItemInfo,
- callback,
- state);
- return workItem;
- }
-
- ///
- /// Create a new work item
- ///
- /// Work item group start information
- /// A callback to execute
- ///
- /// The context object of the work item. Used for passing arguments to the work item.
- ///
- /// The work item priority
- /// Returns a work item
- 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.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext;
- 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;
- }
-
- ///
- /// Create a new work item
- ///
- /// Work item group start information
- /// Work item information
- /// A callback to execute
- ///
- /// The context object of the work item. Used for passing arguments to the work item.
- ///
- /// Returns a work item
- public static WorkItem CreateWorkItem(
- IWorkItemsGroup workItemsGroup,
- WIGStartInfo wigStartInfo,
- WorkItemInfo workItemInfo,
- WorkItemCallback callback,
- object state)
- {
- ValidateCallback(callback);
- ValidateCallback(workItemInfo.PostExecuteWorkItemCallback);
-
- WorkItem workItem = new WorkItem(
- workItemsGroup,
- new WorkItemInfo(workItemInfo),
- callback,
- state);
-
- return workItem;
- }
-
- ///
- /// Create a new work item
- ///
- /// Work item group start information
- /// A callback to execute
- ///
- /// The context object of the work item. Used for passing arguments to the work item.
- ///
- ///
- /// A delegate to call after the callback completion
- ///
- /// Returns a work item
- public static WorkItem CreateWorkItem(
- IWorkItemsGroup workItemsGroup,
- WIGStartInfo wigStartInfo,
- WorkItemCallback callback,
- object state,
- PostExecuteWorkItemCallback postExecuteWorkItemCallback)
- {
- ValidateCallback(callback);
- ValidateCallback(postExecuteWorkItemCallback);
-
- WorkItemInfo workItemInfo = new WorkItemInfo();
- workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext;
- workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext;
- workItemInfo.PostExecuteWorkItemCallback = postExecuteWorkItemCallback;
- workItemInfo.CallToPostExecute = wigStartInfo.CallToPostExecute;
- workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;
-
- WorkItem workItem = new WorkItem(
- workItemsGroup,
- workItemInfo,
- callback,
- state);
-
- return workItem;
- }
-
- ///
- /// Create a new work item
- ///
- /// Work item group start information
- /// A callback to execute
- ///
- /// The context object of the work item. Used for passing arguments to the work item.
- ///
- ///
- /// A delegate to call after the callback completion
- ///
- /// The work item priority
- /// Returns a work item
- 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.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext;
- workItemInfo.PostExecuteWorkItemCallback = postExecuteWorkItemCallback;
- workItemInfo.CallToPostExecute = wigStartInfo.CallToPostExecute;
- workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;
- workItemInfo.WorkItemPriority = workItemPriority;
-
- WorkItem workItem = new WorkItem(
- workItemsGroup,
- workItemInfo,
- callback,
- state);
-
- return workItem;
- }
-
- ///
- /// Create a new work item
- ///
- /// Work item group start information
- /// A callback to execute
- ///
- /// The context object of the work item. Used for passing arguments to the work item.
- ///
- ///
- /// A delegate to call after the callback completion
- ///
- /// Indicates on which cases to call to the post execute callback
- /// Returns a work item
- public static WorkItem CreateWorkItem(
- IWorkItemsGroup workItemsGroup,
- WIGStartInfo wigStartInfo,
- WorkItemCallback callback,
- object state,
- PostExecuteWorkItemCallback postExecuteWorkItemCallback,
- CallToPostExecute callToPostExecute)
- {
- ValidateCallback(callback);
- ValidateCallback(postExecuteWorkItemCallback);
-
- WorkItemInfo workItemInfo = new WorkItemInfo();
- workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext;
- workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext;
- workItemInfo.PostExecuteWorkItemCallback = postExecuteWorkItemCallback;
- workItemInfo.CallToPostExecute = callToPostExecute;
- workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;
-
- WorkItem workItem = new WorkItem(
- workItemsGroup,
- workItemInfo,
- callback,
- state);
-
- return workItem;
- }
-
- ///
- /// Create a new work item
- ///
- /// Work item group start information
- /// A callback to execute
- ///
- /// The context object of the work item. Used for passing arguments to the work item.
- ///
- ///
- /// A delegate to call after the callback completion
- ///
- /// Indicates on which cases to call to the post execute callback
- /// The work item priority
- /// Returns a work item
- 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.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext;
- 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)
- {
- if(callback.GetInvocationList().Length > 1)
- {
- throw new NotSupportedException("SmartThreadPool doesn't support delegates chains");
- }
- }
- }
-
- #endregion
-}
+using System;
+
+namespace Amib.Threading.Internal
+{
+ #region WorkItemFactory class
+
+ public class WorkItemFactory
+ {
+ ///
+ /// Create a new work item
+ ///
+ /// The WorkItemsGroup of this workitem
+ /// Work item group start information
+ /// A callback to execute
+ /// Returns a work item
+ public static WorkItem CreateWorkItem(
+ IWorkItemsGroup workItemsGroup,
+ WIGStartInfo wigStartInfo,
+ WorkItemCallback callback)
+ {
+ return CreateWorkItem(workItemsGroup, wigStartInfo, callback, null);
+ }
+
+ ///
+ /// Create a new work item
+ ///
+ /// The WorkItemsGroup of this workitem
+ /// Work item group start information
+ /// A callback to execute
+ /// The priority of the work item
+ /// Returns a work item
+ public static WorkItem CreateWorkItem(
+ IWorkItemsGroup workItemsGroup,
+ WIGStartInfo wigStartInfo,
+ WorkItemCallback callback,
+ WorkItemPriority workItemPriority)
+ {
+ return CreateWorkItem(workItemsGroup, wigStartInfo, callback, null, workItemPriority);
+ }
+
+ ///
+ /// Create a new work item
+ ///
+ /// The WorkItemsGroup of this workitem
+ /// Work item group start information
+ /// Work item info
+ /// A callback to execute
+ /// Returns a work item
+ public static WorkItem CreateWorkItem(
+ IWorkItemsGroup workItemsGroup,
+ WIGStartInfo wigStartInfo,
+ WorkItemInfo workItemInfo,
+ WorkItemCallback callback)
+ {
+ return CreateWorkItem(
+ workItemsGroup,
+ wigStartInfo,
+ workItemInfo,
+ callback,
+ null);
+ }
+
+ ///
+ /// Create a new work item
+ ///
+ /// The WorkItemsGroup of this workitem
+ /// Work item group start information
+ /// A callback to execute
+ ///
+ /// The context object of the work item. Used for passing arguments to the work item.
+ ///
+ /// Returns a work item
+ public static WorkItem CreateWorkItem(
+ IWorkItemsGroup workItemsGroup,
+ WIGStartInfo wigStartInfo,
+ WorkItemCallback callback,
+ object state)
+ {
+ ValidateCallback(callback);
+
+ WorkItemInfo workItemInfo = new WorkItemInfo();
+ workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext;
+ workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext;
+ workItemInfo.PostExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback;
+ workItemInfo.CallToPostExecute = wigStartInfo.CallToPostExecute;
+ workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;
+ workItemInfo.WorkItemPriority = wigStartInfo.WorkItemPriority;
+
+ WorkItem workItem = new WorkItem(
+ workItemsGroup,
+ workItemInfo,
+ callback,
+ state);
+ return workItem;
+ }
+
+ ///
+ /// Create a new work item
+ ///
+ /// The work items group
+ /// Work item group start information
+ /// A callback to execute
+ ///
+ /// The context object of the work item. Used for passing arguments to the work item.
+ ///
+ /// The work item priority
+ /// Returns a work item
+ 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.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext;
+ 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;
+ }
+
+ ///
+ /// Create a new work item
+ ///
+ /// The work items group
+ /// Work item group start information
+ /// Work item information
+ /// A callback to execute
+ ///
+ /// The context object of the work item. Used for passing arguments to the work item.
+ ///
+ /// Returns a work item
+ public static WorkItem CreateWorkItem(
+ IWorkItemsGroup workItemsGroup,
+ WIGStartInfo wigStartInfo,
+ WorkItemInfo workItemInfo,
+ WorkItemCallback callback,
+ object state)
+ {
+ ValidateCallback(callback);
+ ValidateCallback(workItemInfo.PostExecuteWorkItemCallback);
+
+ WorkItem workItem = new WorkItem(
+ workItemsGroup,
+ new WorkItemInfo(workItemInfo),
+ callback,
+ state);
+
+ return workItem;
+ }
+
+ ///
+ /// Create a new work item
+ ///
+ /// The work items group
+ /// Work item group start information
+ /// A callback to execute
+ ///
+ /// The context object of the work item. Used for passing arguments to the work item.
+ ///
+ ///
+ /// A delegate to call after the callback completion
+ ///
+ /// Returns a work item
+ public static WorkItem CreateWorkItem(
+ IWorkItemsGroup workItemsGroup,
+ WIGStartInfo wigStartInfo,
+ WorkItemCallback callback,
+ object state,
+ PostExecuteWorkItemCallback postExecuteWorkItemCallback)
+ {
+ ValidateCallback(callback);
+ ValidateCallback(postExecuteWorkItemCallback);
+
+ WorkItemInfo workItemInfo = new WorkItemInfo();
+ workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext;
+ workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext;
+ workItemInfo.PostExecuteWorkItemCallback = postExecuteWorkItemCallback;
+ workItemInfo.CallToPostExecute = wigStartInfo.CallToPostExecute;
+ workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;
+ workItemInfo.WorkItemPriority = wigStartInfo.WorkItemPriority;
+
+ WorkItem workItem = new WorkItem(
+ workItemsGroup,
+ workItemInfo,
+ callback,
+ state);
+
+ return workItem;
+ }
+
+ ///
+ /// Create a new work item
+ ///
+ /// The work items group
+ /// Work item group start information
+ /// A callback to execute
+ ///
+ /// The context object of the work item. Used for passing arguments to the work item.
+ ///
+ ///
+ /// A delegate to call after the callback completion
+ ///
+ /// The work item priority
+ /// Returns a work item
+ 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.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext;
+ workItemInfo.PostExecuteWorkItemCallback = postExecuteWorkItemCallback;
+ workItemInfo.CallToPostExecute = wigStartInfo.CallToPostExecute;
+ workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;
+ workItemInfo.WorkItemPriority = workItemPriority;
+
+ WorkItem workItem = new WorkItem(
+ workItemsGroup,
+ workItemInfo,
+ callback,
+ state);
+
+ return workItem;
+ }
+
+ ///
+ /// Create a new work item
+ ///
+ /// The work items group
+ /// Work item group start information
+ /// A callback to execute
+ ///
+ /// The context object of the work item. Used for passing arguments to the work item.
+ ///
+ ///
+ /// A delegate to call after the callback completion
+ ///
+ /// Indicates on which cases to call to the post execute callback
+ /// Returns a work item
+ public static WorkItem CreateWorkItem(
+ IWorkItemsGroup workItemsGroup,
+ WIGStartInfo wigStartInfo,
+ WorkItemCallback callback,
+ object state,
+ PostExecuteWorkItemCallback postExecuteWorkItemCallback,
+ CallToPostExecute callToPostExecute)
+ {
+ ValidateCallback(callback);
+ ValidateCallback(postExecuteWorkItemCallback);
+
+ WorkItemInfo workItemInfo = new WorkItemInfo();
+ workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext;
+ workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext;
+ workItemInfo.PostExecuteWorkItemCallback = postExecuteWorkItemCallback;
+ workItemInfo.CallToPostExecute = callToPostExecute;
+ workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;
+ workItemInfo.WorkItemPriority = wigStartInfo.WorkItemPriority;
+
+ WorkItem workItem = new WorkItem(
+ workItemsGroup,
+ workItemInfo,
+ callback,
+ state);
+
+ return workItem;
+ }
+
+ ///
+ /// Create a new work item
+ ///
+ /// The work items group
+ /// Work item group start information
+ /// A callback to execute
+ ///
+ /// The context object of the work item. Used for passing arguments to the work item.
+ ///
+ ///
+ /// A delegate to call after the callback completion
+ ///
+ /// Indicates on which cases to call to the post execute callback
+ /// The work item priority
+ /// Returns a work item
+ 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.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext;
+ 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)
+ {
+ if (callback != null && callback.GetInvocationList().Length > 1)
+ {
+ throw new NotSupportedException("SmartThreadPool doesn't support delegates chains");
+ }
+ }
+ }
+
+ #endregion
+}
--
cgit v1.1