Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ActionBlock.cs
Go to the documentation of this file.
5
7
8[DebuggerDisplay("{DebuggerDisplayContent,nq}")]
11{
12 private sealed class DebugView
13 {
15
16 private readonly TargetCore<TInput>.DebuggingInformation _defaultDebugInfo;
17
18 private readonly SpscTargetCore<TInput>.DebuggingInformation _spscDebugInfo;
19
21 {
22 get
23 {
24 if (_defaultDebugInfo == null)
25 {
26 return _spscDebugInfo.InputQueue;
27 }
28 return _defaultDebugInfo.InputQueue;
29 }
30 }
31
33 {
34 get
35 {
36 if (_defaultDebugInfo == null)
37 {
38 return null;
39 }
40 return _defaultDebugInfo.PostponedMessages;
41 }
42 }
43
45 {
46 get
47 {
48 if (_defaultDebugInfo == null)
49 {
50 return _spscDebugInfo.CurrentDegreeOfParallelism;
51 }
52 return _defaultDebugInfo.CurrentDegreeOfParallelism;
53 }
54 }
55
57 {
58 get
59 {
60 if (_defaultDebugInfo == null)
61 {
62 return _spscDebugInfo.DataflowBlockOptions;
63 }
64 return _defaultDebugInfo.DataflowBlockOptions;
65 }
66 }
67
69 {
70 get
71 {
72 if (_defaultDebugInfo == null)
73 {
74 return _spscDebugInfo.IsDecliningPermanently;
75 }
76 return _defaultDebugInfo.IsDecliningPermanently;
77 }
78 }
79
80 public bool IsCompleted
81 {
82 get
83 {
84 if (_defaultDebugInfo == null)
85 {
86 return _spscDebugInfo.IsCompleted;
87 }
88 return _defaultDebugInfo.IsCompleted;
89 }
90 }
91
93
95 {
97 if (_actionBlock._defaultTarget != null)
98 {
99 _defaultDebugInfo = actionBlock._defaultTarget.GetDebuggingInformation();
100 }
101 else
102 {
103 _spscDebugInfo = actionBlock._spscTarget.GetDebuggingInformation();
104 }
105 }
106 }
107
109
111
113 {
114 get
115 {
116 if (_defaultTarget == null)
117 {
118 return _spscTarget.Completion;
119 }
120 return _defaultTarget.Completion;
121 }
122 }
123
124 public int InputCount
125 {
126 get
127 {
128 if (_defaultTarget == null)
129 {
130 return _spscTarget.InputCount;
131 }
132 return _defaultTarget.InputCount;
133 }
134 }
135
137 {
138 get
139 {
140 if (_defaultTarget == null)
141 {
142 return _spscTarget.InputCount;
143 }
144 return _defaultTarget.GetDebuggingInformation().InputCount;
145 }
146 }
147
148 private object DebuggerDisplayContent => $"{Common.GetNameForDebugger(this, (_defaultTarget != null) ? _defaultTarget.DataflowBlockOptions : _spscTarget.DataflowBlockOptions)}, InputCount={InputCountForDebugger}";
149
150 object IDebuggerDisplay.Content => DebuggerDisplayContent;
151
156
161
166
171
173 {
175 if ((object)action == null)
176 {
177 throw new ArgumentNullException("action");
178 }
179 if (dataflowBlockOptions == null)
180 {
181 throw new ArgumentNullException("dataflowBlockOptions");
182 }
185 if (syncAction != null && dataflowBlockOptions.SingleProducerConstrained && dataflowBlockOptions.MaxDegreeOfParallelism == 1 && !dataflowBlockOptions.CancellationToken.CanBeCanceled && dataflowBlockOptions.BoundedCapacity == -1)
186 {
188 }
189 else
190 {
191 if (syncAction != null)
192 {
194 {
195 actionBlock.ProcessMessage(syncAction, messageWithId);
196 }, null, dataflowBlockOptions, TargetCoreOptions.RepresentsBlockCompletion);
197 }
198 else
199 {
202 {
203 actionBlock.ProcessMessageWithTask(asyncAction, messageWithId);
204 }, null, dataflowBlockOptions, TargetCoreOptions.UsesAsyncCompletion | TargetCoreOptions.RepresentsBlockCompletion);
205 }
207 {
208 ((TargetCore<TInput>)state).Complete(null, dropPendingMessages: true);
209 }, _defaultTarget);
210 }
212 if (log.IsEnabled())
213 {
214 log.DataflowBlockCreated(this, dataflowBlockOptions);
215 }
216 }
217
219 {
220 try
221 {
223 }
224 catch (Exception exception)
225 {
227 {
228 throw;
229 }
230 }
231 finally
232 {
233 if (_defaultTarget.IsBounded)
234 {
235 _defaultTarget.ChangeBoundingCount(-1);
236 }
237 }
238 }
239
241 {
242 Task task = null;
243 Exception ex = null;
244 try
245 {
247 }
248 catch (Exception ex2)
249 {
250 ex = ex2;
251 }
252 if (task == null)
253 {
254 if (ex != null && !Common.IsCooperativeCancellation(ex))
255 {
256 Common.StoreDataflowMessageValueIntoExceptionData(ex, messageWithId.Key);
258 }
259 _defaultTarget.SignalOneAsyncMessageCompleted(-1);
260 }
261 else if (task.IsCompleted)
262 {
264 }
265 else
266 {
267 task.ContinueWith(delegate(Task completed, object state)
268 {
269 ((ActionBlock<TInput>)state).AsyncCompleteProcessMessageWithTask(completed);
271 }
272 }
273
275 {
276 if (completed.IsFaulted)
277 {
279 }
280 _defaultTarget.SignalOneAsyncMessageCompleted(-1);
281 }
282
283 public void Complete()
284 {
285 if (_defaultTarget != null)
286 {
287 _defaultTarget.Complete(null, dropPendingMessages: false);
288 }
289 else
290 {
291 _spscTarget.Complete(null);
292 }
293 }
294
296 {
297 if (exception == null)
298 {
299 throw new ArgumentNullException("exception");
300 }
301 if (_defaultTarget != null)
302 {
304 }
305 else
306 {
307 _spscTarget.Complete(exception);
308 }
309 }
310
311 [MethodImpl(MethodImplOptions.AggressiveInlining)]
312 public bool Post(TInput item)
313 {
314 if (_defaultTarget == null)
315 {
316 return _spscTarget.Post(item);
317 }
318 return _defaultTarget.OfferMessage(Common.SingleMessageHeader, item, null, consumeToAccept: false) == DataflowMessageStatus.Accepted;
319 }
320
329
330 public override string ToString()
331 {
332 return Common.GetNameForDebugger(this, (_defaultTarget != null) ? _defaultTarget.DataflowBlockOptions : _spscTarget.DataflowBlockOptions);
333 }
334}
readonly SpscTargetCore< TInput >.DebuggingInformation _spscDebugInfo
QueuedMap< ISourceBlock< TInput >, DataflowMessageHeader > PostponedMessages
DebugView(ActionBlock< TInput > actionBlock)
readonly TargetCore< TInput >.DebuggingInformation _defaultDebugInfo
ActionBlock(Delegate action, ExecutionDataflowBlockOptions dataflowBlockOptions)
void AsyncCompleteProcessMessageWithTask(Task completed)
ActionBlock(Action< TInput > action, ExecutionDataflowBlockOptions dataflowBlockOptions)
void ProcessMessageWithTask(Func< TInput, Task > action, KeyValuePair< TInput, long > messageWithId)
readonly SpscTargetCore< TInput > _spscTarget
void ProcessMessage(Action< TInput > action, KeyValuePair< TInput, long > messageWithId)
ActionBlock(Func< TInput, Task > action, ExecutionDataflowBlockOptions dataflowBlockOptions)
ActionBlock(Func< TInput, Task > action)
readonly TargetCore< TInput > _defaultTarget
static bool IsCooperativeCancellation(Exception exception)
Definition Common.cs:88
static TaskContinuationOptions GetContinuationOptions(TaskContinuationOptions toInclude=TaskContinuationOptions.None)
Definition Common.cs:262
static string GetNameForDebugger(IDataflowBlock block, DataflowBlockOptions options=null)
Definition Common.cs:66
static readonly DataflowMessageHeader SingleMessageHeader
Definition Common.cs:26
static void WireCancellationToComplete(CancellationToken cancellationToken, Task completionTask, Action< object > completeAction, object completeState)
Definition Common.cs:93
static int GetBlockId(IDataflowBlock block)
Definition Common.cs:61