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/WIGStartInfo.cs | 270 ++++++++++++++++++-----------
1 file changed, 171 insertions(+), 99 deletions(-)
(limited to 'ThirdParty/SmartThreadPool/WIGStartInfo.cs')
diff --git a/ThirdParty/SmartThreadPool/WIGStartInfo.cs b/ThirdParty/SmartThreadPool/WIGStartInfo.cs
index 150317f..e5ff150 100644
--- a/ThirdParty/SmartThreadPool/WIGStartInfo.cs
+++ b/ThirdParty/SmartThreadPool/WIGStartInfo.cs
@@ -1,99 +1,171 @@
-// Ami Bar
-// amibar@gmail.com
-
-namespace Amib.Threading
-{
- ///
- /// Summary description for WIGStartInfo.
- ///
- public class WIGStartInfo
- {
- ///
- /// Use the caller's security context
- ///
- private bool _useCallerCallContext;
-
- ///
- /// Use the caller's HTTP context
- ///
- private bool _useCallerHttpContext;
-
- ///
- /// Dispose of the state object of a work item
- ///
- private bool _disposeOfStateObjects;
-
- ///
- /// The option to run the post execute
- ///
- private CallToPostExecute _callToPostExecute;
-
- ///
- /// A post execute callback to call when none is provided in
- /// the QueueWorkItem method.
- ///
- private PostExecuteWorkItemCallback _postExecuteWorkItemCallback;
-
- ///
- /// Indicate the WorkItemsGroup to suspend the handling of the work items
- /// until the Start() method is called.
- ///
- private bool _startSuspended;
-
- public WIGStartInfo()
- {
- _useCallerCallContext = SmartThreadPool.DefaultUseCallerCallContext;
- _useCallerHttpContext = SmartThreadPool.DefaultUseCallerHttpContext;
- _disposeOfStateObjects = SmartThreadPool.DefaultDisposeOfStateObjects;
- _callToPostExecute = SmartThreadPool.DefaultCallToPostExecute;
- _postExecuteWorkItemCallback = SmartThreadPool.DefaultPostExecuteWorkItemCallback;
- _startSuspended = SmartThreadPool.DefaultStartSuspended;
- }
-
- public WIGStartInfo(WIGStartInfo wigStartInfo)
- {
- _useCallerCallContext = wigStartInfo._useCallerCallContext;
- _useCallerHttpContext = wigStartInfo._useCallerHttpContext;
- _disposeOfStateObjects = wigStartInfo._disposeOfStateObjects;
- _callToPostExecute = wigStartInfo._callToPostExecute;
- _postExecuteWorkItemCallback = wigStartInfo._postExecuteWorkItemCallback;
- _startSuspended = wigStartInfo._startSuspended;
- }
-
- public bool UseCallerCallContext
- {
- get { return _useCallerCallContext; }
- set { _useCallerCallContext = value; }
- }
-
- public bool UseCallerHttpContext
- {
- get { return _useCallerHttpContext; }
- set { _useCallerHttpContext = value; }
- }
-
- public bool DisposeOfStateObjects
- {
- get { return _disposeOfStateObjects; }
- set { _disposeOfStateObjects = value; }
- }
-
- public CallToPostExecute CallToPostExecute
- {
- get { return _callToPostExecute; }
- set { _callToPostExecute = value; }
- }
-
- public PostExecuteWorkItemCallback PostExecuteWorkItemCallback
- {
- get { return _postExecuteWorkItemCallback; }
- set { _postExecuteWorkItemCallback = value; }
- }
-
- public bool StartSuspended
- {
- get { return _startSuspended; }
- set { _startSuspended = value; }
- }
- }
-}
+using System;
+
+namespace Amib.Threading
+{
+ ///
+ /// Summary description for WIGStartInfo.
+ ///
+ public class WIGStartInfo
+ {
+ private bool _useCallerCallContext;
+ private bool _useCallerHttpContext;
+ private bool _disposeOfStateObjects;
+ private CallToPostExecute _callToPostExecute;
+ private PostExecuteWorkItemCallback _postExecuteWorkItemCallback;
+ private bool _startSuspended;
+ private WorkItemPriority _workItemPriority;
+ private bool _fillStateWithArgs;
+
+ protected bool _readOnly;
+
+ public WIGStartInfo()
+ {
+ _fillStateWithArgs = SmartThreadPool.DefaultFillStateWithArgs;
+ _workItemPriority = SmartThreadPool.DefaultWorkItemPriority;
+ _startSuspended = SmartThreadPool.DefaultStartSuspended;
+ _postExecuteWorkItemCallback = SmartThreadPool.DefaultPostExecuteWorkItemCallback;
+ _callToPostExecute = SmartThreadPool.DefaultCallToPostExecute;
+ _disposeOfStateObjects = SmartThreadPool.DefaultDisposeOfStateObjects;
+ _useCallerHttpContext = SmartThreadPool.DefaultUseCallerHttpContext;
+ _useCallerCallContext = SmartThreadPool.DefaultUseCallerCallContext;
+ }
+
+ public WIGStartInfo(WIGStartInfo wigStartInfo)
+ {
+ _useCallerCallContext = wigStartInfo.UseCallerCallContext;
+ _useCallerHttpContext = wigStartInfo.UseCallerHttpContext;
+ _disposeOfStateObjects = wigStartInfo.DisposeOfStateObjects;
+ _callToPostExecute = wigStartInfo.CallToPostExecute;
+ _postExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback;
+ _workItemPriority = wigStartInfo.WorkItemPriority;
+ _startSuspended = wigStartInfo.StartSuspended;
+ _fillStateWithArgs = wigStartInfo.FillStateWithArgs;
+ }
+
+ protected void ThrowIfReadOnly()
+ {
+ if (_readOnly)
+ {
+ throw new NotSupportedException("This is a readonly instance and set is not supported");
+ }
+ }
+
+ ///
+ /// Get/Set if to use the caller's security context
+ ///
+ public virtual bool UseCallerCallContext
+ {
+ get { return _useCallerCallContext; }
+ set
+ {
+ ThrowIfReadOnly();
+ _useCallerCallContext = value;
+ }
+ }
+
+
+ ///
+ /// Get/Set if to use the caller's HTTP context
+ ///
+ public virtual bool UseCallerHttpContext
+ {
+ get { return _useCallerHttpContext; }
+ set
+ {
+ ThrowIfReadOnly();
+ _useCallerHttpContext = value;
+ }
+ }
+
+
+ ///
+ /// Get/Set if to dispose of the state object of a work item
+ ///
+ public virtual bool DisposeOfStateObjects
+ {
+ get { return _disposeOfStateObjects; }
+ set
+ {
+ ThrowIfReadOnly();
+ _disposeOfStateObjects = value;
+ }
+ }
+
+
+ ///
+ /// Get/Set the run the post execute options
+ ///
+ public virtual CallToPostExecute CallToPostExecute
+ {
+ get { return _callToPostExecute; }
+ set
+ {
+ ThrowIfReadOnly();
+ _callToPostExecute = value;
+ }
+ }
+
+
+ ///
+ /// Get/Set the default post execute callback
+ ///
+ public virtual PostExecuteWorkItemCallback PostExecuteWorkItemCallback
+ {
+ get { return _postExecuteWorkItemCallback; }
+ set
+ {
+ ThrowIfReadOnly();
+ _postExecuteWorkItemCallback = value;
+ }
+ }
+
+
+ ///
+ /// Get/Set if the work items execution should be suspended until the Start()
+ /// method is called.
+ ///
+ public virtual bool StartSuspended
+ {
+ get { return _startSuspended; }
+ set
+ {
+ ThrowIfReadOnly();
+ _startSuspended = value;
+ }
+ }
+
+
+ ///
+ /// Get/Set the default priority that a work item gets when it is enqueued
+ ///
+ public virtual WorkItemPriority WorkItemPriority
+ {
+ get { return _workItemPriority; }
+ set { _workItemPriority = value; }
+ }
+
+ ///
+ /// Get/Set the if QueueWorkItem of Action<...>/Func<...> fill the
+ /// arguments as an object array into the state of the work item.
+ /// The arguments can be access later by IWorkItemResult.State.
+ ///
+ public virtual bool FillStateWithArgs
+ {
+ get { return _fillStateWithArgs; }
+ set
+ {
+ ThrowIfReadOnly();
+ _fillStateWithArgs = value;
+ }
+ }
+
+ ///
+ /// Get a readonly version of this WIGStartInfo
+ ///
+ /// Returns a readonly reference to this WIGStartInfoRO
+ public WIGStartInfo AsReadOnly()
+ {
+ return new WIGStartInfo(this) { _readOnly = true };
+ }
+ }
+}
--
cgit v1.1