aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ThirdParty/SmartThreadPool/STPStartInfo.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ThirdParty/SmartThreadPool/STPStartInfo.cs325
1 files changed, 212 insertions, 113 deletions
diff --git a/ThirdParty/SmartThreadPool/STPStartInfo.cs b/ThirdParty/SmartThreadPool/STPStartInfo.cs
index fa9ceb4..2ec8dc6 100644
--- a/ThirdParty/SmartThreadPool/STPStartInfo.cs
+++ b/ThirdParty/SmartThreadPool/STPStartInfo.cs
@@ -1,113 +1,212 @@
1// Ami Bar 1using System;
2// amibar@gmail.com 2using System.Threading;
3 3
4using System.Threading; 4namespace Amib.Threading
5 5{
6namespace Amib.Threading 6 /// <summary>
7{ 7 /// Summary description for STPStartInfo.
8 /// <summary> 8 /// </summary>
9 /// Summary description for STPStartInfo. 9 public class STPStartInfo : WIGStartInfo
10 /// </summary> 10 {
11 public class STPStartInfo : WIGStartInfo 11 private int _idleTimeout = SmartThreadPool.DefaultIdleTimeout;
12 { 12 private int _minWorkerThreads = SmartThreadPool.DefaultMinWorkerThreads;
13 /// <summary> 13 private int _maxWorkerThreads = SmartThreadPool.DefaultMaxWorkerThreads;
14 /// Idle timeout in milliseconds. 14#if !(WINDOWS_PHONE)
15 /// If a thread is idle for _idleTimeout milliseconds then 15 private ThreadPriority _threadPriority = SmartThreadPool.DefaultThreadPriority;
16 /// it may quit. 16#endif
17 /// </summary> 17 private string _performanceCounterInstanceName = SmartThreadPool.DefaultPerformanceCounterInstanceName;
18 private int _idleTimeout; 18 private bool _areThreadsBackground = SmartThreadPool.DefaultAreThreadsBackground;
19 19 private bool _enableLocalPerformanceCounters;
20 /// <summary> 20 private string _threadPoolName = SmartThreadPool.DefaultThreadPoolName;
21 /// The lower limit of threads in the pool. 21 private int? _maxStackSize = SmartThreadPool.DefaultMaxStackSize;
22 /// </summary> 22
23 private int _minWorkerThreads; 23 public STPStartInfo()
24 24 {
25 /// <summary> 25 _performanceCounterInstanceName = SmartThreadPool.DefaultPerformanceCounterInstanceName;
26 /// The upper limit of threads in the pool. 26#if !(WINDOWS_PHONE)
27 /// </summary> 27 _threadPriority = SmartThreadPool.DefaultThreadPriority;
28 private int _maxWorkerThreads; 28#endif
29 29 _maxWorkerThreads = SmartThreadPool.DefaultMaxWorkerThreads;
30 /// <summary> 30 _idleTimeout = SmartThreadPool.DefaultIdleTimeout;
31 /// The priority of the threads in the pool 31 _minWorkerThreads = SmartThreadPool.DefaultMinWorkerThreads;
32 /// </summary> 32 }
33 private ThreadPriority _threadPriority; 33
34 34 public STPStartInfo(STPStartInfo stpStartInfo)
35 /// <summary> 35 : base(stpStartInfo)
36 /// The thread pool name. Threads will get names depending on this. 36 {
37 /// </summary> 37 _idleTimeout = stpStartInfo.IdleTimeout;
38 private string _threadPoolName; 38 _minWorkerThreads = stpStartInfo.MinWorkerThreads;
39 39 _maxWorkerThreads = stpStartInfo.MaxWorkerThreads;
40 /// <summary> 40#if !(WINDOWS_PHONE)
41 /// If this field is not null then the performance counters are enabled 41 _threadPriority = stpStartInfo.ThreadPriority;
42 /// and use the string as the name of the instance. 42#endif
43 /// </summary> 43 _performanceCounterInstanceName = stpStartInfo.PerformanceCounterInstanceName;
44 private string _pcInstanceName; 44 _enableLocalPerformanceCounters = stpStartInfo._enableLocalPerformanceCounters;
45 45 _threadPoolName = stpStartInfo._threadPoolName;
46 private int _stackSize; 46 _areThreadsBackground = stpStartInfo.AreThreadsBackground;
47 47#if !(_SILVERLIGHT) && !(WINDOWS_PHONE)
48 public STPStartInfo() : base() 48 _apartmentState = stpStartInfo._apartmentState;
49 { 49#endif
50 _idleTimeout = SmartThreadPool.DefaultIdleTimeout; 50 }
51 _minWorkerThreads = SmartThreadPool.DefaultMinWorkerThreads; 51
52 _maxWorkerThreads = SmartThreadPool.DefaultMaxWorkerThreads; 52 /// <summary>
53 _threadPriority = SmartThreadPool.DefaultThreadPriority; 53 /// Get/Set the idle timeout in milliseconds.
54 _threadPoolName = SmartThreadPool.DefaultThreadPoolName; 54 /// If a thread is idle (starved) longer than IdleTimeout then it may quit.
55 _pcInstanceName = SmartThreadPool.DefaultPerformanceCounterInstanceName; 55 /// </summary>
56 _stackSize = SmartThreadPool.DefaultStackSize; 56 public virtual int IdleTimeout
57 } 57 {
58 58 get { return _idleTimeout; }
59 public STPStartInfo(STPStartInfo stpStartInfo) : base(stpStartInfo) 59 set
60 { 60 {
61 _idleTimeout = stpStartInfo._idleTimeout; 61 ThrowIfReadOnly();
62 _minWorkerThreads = stpStartInfo._minWorkerThreads; 62 _idleTimeout = value;
63 _maxWorkerThreads = stpStartInfo._maxWorkerThreads; 63 }
64 _threadPriority = stpStartInfo._threadPriority; 64 }
65 _threadPoolName = stpStartInfo._threadPoolName; 65
66 _pcInstanceName = stpStartInfo._pcInstanceName; 66
67 _stackSize = stpStartInfo._stackSize; 67 /// <summary>
68 } 68 /// Get/Set the lower limit of threads in the pool.
69 69 /// </summary>
70 public int IdleTimeout 70 public virtual int MinWorkerThreads
71 { 71 {
72 get { return _idleTimeout; } 72 get { return _minWorkerThreads; }
73 set { _idleTimeout = value; } 73 set
74 } 74 {
75 75 ThrowIfReadOnly();
76 public int MinWorkerThreads 76 _minWorkerThreads = value;
77 { 77 }
78 get { return _minWorkerThreads; } 78 }
79 set { _minWorkerThreads = value; } 79
80 } 80
81 81 /// <summary>
82 public int MaxWorkerThreads 82 /// Get/Set the upper limit of threads in the pool.
83 { 83 /// </summary>
84 get { return _maxWorkerThreads; } 84 public virtual int MaxWorkerThreads
85 set { _maxWorkerThreads = value; } 85 {
86 } 86 get { return _maxWorkerThreads; }
87 87 set
88 public ThreadPriority ThreadPriority 88 {
89 { 89 ThrowIfReadOnly();
90 get { return _threadPriority; } 90 _maxWorkerThreads = value;
91 set { _threadPriority = value; } 91 }
92 } 92 }
93 93
94 public virtual string ThreadPoolName 94#if !(WINDOWS_PHONE)
95 { 95 /// <summary>
96 get { return _threadPoolName; } 96 /// Get/Set the scheduling priority of the threads in the pool.
97 set { _threadPoolName = value; } 97 /// The Os handles the scheduling.
98 } 98 /// </summary>
99 99 public virtual ThreadPriority ThreadPriority
100 100 {
101 public string PerformanceCounterInstanceName 101 get { return _threadPriority; }
102 { 102 set
103 get { return _pcInstanceName; } 103 {
104 set { _pcInstanceName = value; } 104 ThrowIfReadOnly();
105 } 105 _threadPriority = value;
106 106 }
107 public int StackSize 107 }
108 { 108#endif
109 get { return _stackSize; } 109 /// <summary>
110 set { _stackSize = value; } 110 /// Get/Set the thread pool name. Threads will get names depending on this.
111 } 111 /// </summary>
112 } 112 public virtual string ThreadPoolName {
113} 113 get { return _threadPoolName; }
114 set
115 {
116 ThrowIfReadOnly ();
117 _threadPoolName = value;
118 }
119 }
120
121 /// <summary>
122 /// Get/Set the performance counter instance name of this SmartThreadPool
123 /// The default is null which indicate not to use performance counters at all.
124 /// </summary>
125 public virtual string PerformanceCounterInstanceName
126 {
127 get { return _performanceCounterInstanceName; }
128 set
129 {
130 ThrowIfReadOnly();
131 _performanceCounterInstanceName = value;
132 }
133 }
134
135 /// <summary>
136 /// Enable/Disable the local performance counter.
137 /// This enables the user to get some performance information about the SmartThreadPool
138 /// without using Windows performance counters. (Useful on WindowsCE, Silverlight, etc.)
139 /// The default is false.
140 /// </summary>
141 public virtual bool EnableLocalPerformanceCounters
142 {
143 get { return _enableLocalPerformanceCounters; }
144 set
145 {
146 ThrowIfReadOnly();
147 _enableLocalPerformanceCounters = value;
148 }
149 }
150
151 /// <summary>
152 /// Get/Set backgroundness of thread in thread pool.
153 /// </summary>
154 public virtual bool AreThreadsBackground
155 {
156 get { return _areThreadsBackground; }
157 set
158 {
159 ThrowIfReadOnly ();
160 _areThreadsBackground = value;
161 }
162 }
163
164 /// <summary>
165 /// Get a readonly version of this STPStartInfo.
166 /// </summary>
167 /// <returns>Returns a readonly reference to this STPStartInfo</returns>
168 public new STPStartInfo AsReadOnly()
169 {
170 return new STPStartInfo(this) { _readOnly = true };
171 }
172
173#if !(_SILVERLIGHT) && !(WINDOWS_PHONE)
174
175 private ApartmentState _apartmentState = SmartThreadPool.DefaultApartmentState;
176
177 /// <summary>
178 /// Get/Set the apartment state of threads in the thread pool
179 /// </summary>
180 public ApartmentState ApartmentState
181 {
182 get { return _apartmentState; }
183 set
184 {
185 ThrowIfReadOnly();
186 _apartmentState = value;
187 }
188 }
189
190#if !(_SILVERLIGHT) && !(WINDOWS_PHONE)
191
192 /// <summary>
193 /// Get/Set the max stack size of threads in the thread pool
194 /// </summary>
195 public int? MaxStackSize
196 {
197 get { return _maxStackSize; }
198 set
199 {
200 ThrowIfReadOnly();
201 if (value.HasValue && value.Value < 0)
202 {
203 throw new ArgumentOutOfRangeException("value", "Value must be greater than 0.");
204 }
205 _maxStackSize = value;
206 }
207 }
208#endif
209
210#endif
211 }
212}