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