diff options
author | Justin Clark-Casey (justincc) | 2013-05-01 19:01:43 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2013-05-01 19:01:43 +0100 |
commit | 206fb306a7820cf593570e35ddfa8e7c5a10e449 (patch) | |
tree | 0ef0fdf42ddc0b63224af52b62b0bad42f62e352 /ThirdParty/SmartThreadPool/WorkItem.WorkItemResult.cs | |
parent | Fix CAPS to work like they should - do not send caps to the viewer if they're... (diff) | |
download | opensim-SC-206fb306a7820cf593570e35ddfa8e7c5a10e449.zip opensim-SC-206fb306a7820cf593570e35ddfa8e7c5a10e449.tar.gz opensim-SC-206fb306a7820cf593570e35ddfa8e7c5a10e449.tar.bz2 opensim-SC-206fb306a7820cf593570e35ddfa8e7c5a10e449.tar.xz |
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
Diffstat (limited to 'ThirdParty/SmartThreadPool/WorkItem.WorkItemResult.cs')
-rw-r--r-- | ThirdParty/SmartThreadPool/WorkItem.WorkItemResult.cs | 190 |
1 files changed, 190 insertions, 0 deletions
diff --git a/ThirdParty/SmartThreadPool/WorkItem.WorkItemResult.cs b/ThirdParty/SmartThreadPool/WorkItem.WorkItemResult.cs new file mode 100644 index 0000000..5745c15 --- /dev/null +++ b/ThirdParty/SmartThreadPool/WorkItem.WorkItemResult.cs | |||
@@ -0,0 +1,190 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using System.Threading; | ||
5 | |||
6 | namespace Amib.Threading.Internal | ||
7 | { | ||
8 | public partial class WorkItem | ||
9 | { | ||
10 | #region WorkItemResult class | ||
11 | |||
12 | private class WorkItemResult : IWorkItemResult, IInternalWorkItemResult, IInternalWaitableResult | ||
13 | { | ||
14 | /// <summary> | ||
15 | /// A back reference to the work item | ||
16 | /// </summary> | ||
17 | private readonly WorkItem _workItem; | ||
18 | |||
19 | public WorkItemResult(WorkItem workItem) | ||
20 | { | ||
21 | _workItem = workItem; | ||
22 | } | ||
23 | |||
24 | internal WorkItem GetWorkItem() | ||
25 | { | ||
26 | return _workItem; | ||
27 | } | ||
28 | |||
29 | #region IWorkItemResult Members | ||
30 | |||
31 | public bool IsCompleted | ||
32 | { | ||
33 | get | ||
34 | { | ||
35 | return _workItem.IsCompleted; | ||
36 | } | ||
37 | } | ||
38 | |||
39 | public bool IsCanceled | ||
40 | { | ||
41 | get | ||
42 | { | ||
43 | return _workItem.IsCanceled; | ||
44 | } | ||
45 | } | ||
46 | |||
47 | public object GetResult() | ||
48 | { | ||
49 | return _workItem.GetResult(Timeout.Infinite, true, null); | ||
50 | } | ||
51 | |||
52 | public object GetResult(int millisecondsTimeout, bool exitContext) | ||
53 | { | ||
54 | return _workItem.GetResult(millisecondsTimeout, exitContext, null); | ||
55 | } | ||
56 | |||
57 | public object GetResult(TimeSpan timeout, bool exitContext) | ||
58 | { | ||
59 | return _workItem.GetResult((int)timeout.TotalMilliseconds, exitContext, null); | ||
60 | } | ||
61 | |||
62 | public object GetResult(int millisecondsTimeout, bool exitContext, WaitHandle cancelWaitHandle) | ||
63 | { | ||
64 | return _workItem.GetResult(millisecondsTimeout, exitContext, cancelWaitHandle); | ||
65 | } | ||
66 | |||
67 | public object GetResult(TimeSpan timeout, bool exitContext, WaitHandle cancelWaitHandle) | ||
68 | { | ||
69 | return _workItem.GetResult((int)timeout.TotalMilliseconds, exitContext, cancelWaitHandle); | ||
70 | } | ||
71 | |||
72 | public object GetResult(out Exception e) | ||
73 | { | ||
74 | return _workItem.GetResult(Timeout.Infinite, true, null, out e); | ||
75 | } | ||
76 | |||
77 | public object GetResult(int millisecondsTimeout, bool exitContext, out Exception e) | ||
78 | { | ||
79 | return _workItem.GetResult(millisecondsTimeout, exitContext, null, out e); | ||
80 | } | ||
81 | |||
82 | public object GetResult(TimeSpan timeout, bool exitContext, out Exception e) | ||
83 | { | ||
84 | return _workItem.GetResult((int)timeout.TotalMilliseconds, exitContext, null, out e); | ||
85 | } | ||
86 | |||
87 | public object GetResult(int millisecondsTimeout, bool exitContext, WaitHandle cancelWaitHandle, out Exception e) | ||
88 | { | ||
89 | return _workItem.GetResult(millisecondsTimeout, exitContext, cancelWaitHandle, out e); | ||
90 | } | ||
91 | |||
92 | public object GetResult(TimeSpan timeout, bool exitContext, WaitHandle cancelWaitHandle, out Exception e) | ||
93 | { | ||
94 | return _workItem.GetResult((int)timeout.TotalMilliseconds, exitContext, cancelWaitHandle, out e); | ||
95 | } | ||
96 | |||
97 | public bool Cancel() | ||
98 | { | ||
99 | return Cancel(false); | ||
100 | } | ||
101 | |||
102 | public bool Cancel(bool abortExecution) | ||
103 | { | ||
104 | return _workItem.Cancel(abortExecution); | ||
105 | } | ||
106 | |||
107 | public object State | ||
108 | { | ||
109 | get | ||
110 | { | ||
111 | return _workItem._state; | ||
112 | } | ||
113 | } | ||
114 | |||
115 | public WorkItemPriority WorkItemPriority | ||
116 | { | ||
117 | get | ||
118 | { | ||
119 | return _workItem._workItemInfo.WorkItemPriority; | ||
120 | } | ||
121 | } | ||
122 | |||
123 | /// <summary> | ||
124 | /// Return the result, same as GetResult() | ||
125 | /// </summary> | ||
126 | public object Result | ||
127 | { | ||
128 | get { return GetResult(); } | ||
129 | } | ||
130 | |||
131 | /// <summary> | ||
132 | /// Returns the exception if occured otherwise returns null. | ||
133 | /// This value is valid only after the work item completed, | ||
134 | /// before that it is always null. | ||
135 | /// </summary> | ||
136 | public object Exception | ||
137 | { | ||
138 | get { return _workItem._exception; } | ||
139 | } | ||
140 | |||
141 | #endregion | ||
142 | |||
143 | #region IInternalWorkItemResult Members | ||
144 | |||
145 | public event WorkItemStateCallback OnWorkItemStarted | ||
146 | { | ||
147 | add | ||
148 | { | ||
149 | _workItem.OnWorkItemStarted += value; | ||
150 | } | ||
151 | remove | ||
152 | { | ||
153 | _workItem.OnWorkItemStarted -= value; | ||
154 | } | ||
155 | } | ||
156 | |||
157 | |||
158 | public event WorkItemStateCallback OnWorkItemCompleted | ||
159 | { | ||
160 | add | ||
161 | { | ||
162 | _workItem.OnWorkItemCompleted += value; | ||
163 | } | ||
164 | remove | ||
165 | { | ||
166 | _workItem.OnWorkItemCompleted -= value; | ||
167 | } | ||
168 | } | ||
169 | |||
170 | #endregion | ||
171 | |||
172 | #region IInternalWorkItemResult Members | ||
173 | |||
174 | public IWorkItemResult GetWorkItemResult() | ||
175 | { | ||
176 | return this; | ||
177 | } | ||
178 | |||
179 | public IWorkItemResult<TResult> GetWorkItemResultT<TResult>() | ||
180 | { | ||
181 | return new WorkItemResultTWrapper<TResult>(this); | ||
182 | } | ||
183 | |||
184 | #endregion | ||
185 | } | ||
186 | |||
187 | #endregion | ||
188 | |||
189 | } | ||
190 | } | ||