Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
JoinBlock.cs
Go to the documentation of this file.
5
7
8[DebuggerDisplay("{DebuggerDisplayContent,nq}")]
10public sealed class JoinBlock<T1, T2> : IReceivableSourceBlock<Tuple<T1, T2>>, ISourceBlock<Tuple<T1, T2>>, IDataflowBlock, IDebuggerDisplay
11{
12 private sealed class DebugView
13 {
14 private readonly JoinBlock<T1, T2> _joinBlock;
15
16 private readonly SourceCore<Tuple<T1, T2>>.DebuggingInformation _sourceDebuggingInformation;
17
19
21
23
24 public Task TaskForOutputProcessing => _sourceDebuggingInformation.TaskForOutputProcessing;
25
27
29
30 public bool IsCompleted => _sourceDebuggingInformation.IsCompleted;
31
33
35
37
39
41
43 {
45 _sourceDebuggingInformation = joinBlock._source.GetDebuggingInformation();
46 }
47 }
48
50
52
53 private readonly JoinBlockTarget<T1> _target1;
54
55 private readonly JoinBlockTarget<T2> _target2;
56
57 public int OutputCount => _source.OutputCount;
58
59 public Task Completion => _source.Completion;
60
62
64
65 private int OutputCountForDebugger => _source.GetDebuggingInformation().OutputCount;
66
67 private object DebuggerDisplayContent => $"{Common.GetNameForDebugger(this, _source.DataflowBlockOptions)}, OutputCount={OutputCountForDebugger}";
68
69 object IDebuggerDisplay.Content => DebuggerDisplayContent;
70
75
77 {
78 if (dataflowBlockOptions == null)
79 {
80 throw new ArgumentNullException("dataflowBlockOptions");
81 }
84 if (dataflowBlockOptions.BoundedCapacity > 0)
85 {
87 {
88 ((JoinBlock<T1, T2>)owningSource)._sharedResources.OnItemsRemoved(count);
89 };
90 }
92 {
93 ((JoinBlock<T1, T2>)owningSource)._sharedResources.CompleteEachTarget();
97 {
100 {
102 _source.AddException(exception);
106 Task.Factory.ContinueWhenAll(new Task[2] { _target1.CompletionTaskInternal, _target2.CompletionTaskInternal }, delegate
107 {
108 _source.Complete();
110 _source.Completion.ContinueWith(delegate(Task completed, object state)
111 {
113 dataflowBlock.Fault(completed.Exception);
115 Common.WireCancellationToComplete(dataflowBlockOptions.CancellationToken, _source.Completion, delegate(object state)
116 {
117 ((JoinBlock<T1, T2>)state)._sharedResources.CompleteEachTarget();
118 }, this);
120 if (log.IsEnabled())
121 {
122 log.DataflowBlockCreated(this, dataflowBlockOptions);
123 }
124 }
125
127 {
128 return _source.LinkTo(target, linkOptions);
129 }
130
132 {
133 return _source.TryReceive(filter, out item);
134 }
135
136 public bool TryReceiveAll([NotNullWhen(true)] out IList<Tuple<T1, T2>>? items)
137 {
138 return _source.TryReceiveAll(out items);
139 }
140
146
148 {
149 if (exception == null)
150 {
151 throw new ArgumentNullException("exception");
152 }
154 {
156 {
158 }
159 }
160 Complete();
161 }
162
167
169 {
170 return _source.ReserveMessage(messageHeader, target);
171 }
172
174 {
175 _source.ReleaseReservation(messageHeader, target);
176 }
177
178 public override string ToString()
179 {
180 return Common.GetNameForDebugger(this, _source.DataflowBlockOptions);
181 }
182}
183[DebuggerDisplay("{DebuggerDisplayContent,nq}")]
185public sealed class JoinBlock<T1, T2, T3> : IReceivableSourceBlock<Tuple<T1, T2, T3>>, ISourceBlock<Tuple<T1, T2, T3>>, IDataflowBlock, IDebuggerDisplay
186{
187 private sealed class DebugView
188 {
190
191 private readonly SourceCore<Tuple<T1, T2, T3>>.DebuggingInformation _sourceDebuggingInformation;
192
194
196
198
199 public Task TaskForOutputProcessing => _sourceDebuggingInformation.TaskForOutputProcessing;
200
202
204
205 public bool IsCompleted => _sourceDebuggingInformation.IsCompleted;
206
207 public int Id => Common.GetBlockId(_joinBlock);
208
210
212
214
216
218
220 {
222 _sourceDebuggingInformation = joinBlock._source.GetDebuggingInformation();
223 }
224 }
225
227
229
230 private readonly JoinBlockTarget<T1> _target1;
231
232 private readonly JoinBlockTarget<T2> _target2;
233
235
236 public int OutputCount => _source.OutputCount;
237
238 public Task Completion => _source.Completion;
239
241
243
245
246 private int OutputCountForDebugger => _source.GetDebuggingInformation().OutputCount;
247
248 private object DebuggerDisplayContent => $"{Common.GetNameForDebugger(this, _source.DataflowBlockOptions)} OutputCount={OutputCountForDebugger}";
249
250 object IDebuggerDisplay.Content => DebuggerDisplayContent;
251
256
258 {
259 if (dataflowBlockOptions == null)
260 {
261 throw new ArgumentNullException("dataflowBlockOptions");
262 }
265 if (dataflowBlockOptions.BoundedCapacity > 0)
266 {
268 {
269 ((JoinBlock<T1, T2, T3>)owningSource)._sharedResources.OnItemsRemoved(count);
270 };
271 }
273 {
274 ((JoinBlock<T1, T2, T3>)owningSource)._sharedResources.CompleteEachTarget();
278 {
281 {
283 _source.AddException(exception);
288 Task.Factory.ContinueWhenAll(new Task[3] { _target1.CompletionTaskInternal, _target2.CompletionTaskInternal, _target3.CompletionTaskInternal }, delegate
289 {
290 _source.Complete();
292 _source.Completion.ContinueWith(delegate(Task completed, object state)
293 {
295 dataflowBlock.Fault(completed.Exception);
297 Common.WireCancellationToComplete(dataflowBlockOptions.CancellationToken, _source.Completion, delegate(object state)
298 {
299 ((JoinBlock<T1, T2, T3>)state)._sharedResources.CompleteEachTarget();
300 }, this);
302 if (log.IsEnabled())
303 {
304 log.DataflowBlockCreated(this, dataflowBlockOptions);
305 }
306 }
307
309 {
310 return _source.LinkTo(target, linkOptions);
311 }
312
314 {
315 return _source.TryReceive(filter, out item);
316 }
317
319 {
320 return _source.TryReceiveAll(out items);
321 }
322
329
331 {
332 if (exception == null)
333 {
334 throw new ArgumentNullException("exception");
335 }
337 {
339 {
341 }
342 }
343 Complete();
344 }
345
350
352 {
353 return _source.ReserveMessage(messageHeader, target);
354 }
355
357 {
358 _source.ReleaseReservation(messageHeader, target);
359 }
360
361 public override string ToString()
362 {
363 return Common.GetNameForDebugger(this, _source.DataflowBlockOptions);
364 }
365}
static TaskContinuationOptions GetContinuationOptions(TaskContinuationOptions toInclude=TaskContinuationOptions.None)
Definition Common.cs:262
static string GetNameForDebugger(IDataflowBlock block, DataflowBlockOptions options=null)
Definition Common.cs:66
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
override void CompleteCore(Exception exception, bool dropPendingMessages, bool releaseReservedMessages)
readonly SourceCore< Tuple< T1, T2 > >.DebuggingInformation _sourceDebuggingInformation
Definition JoinBlock.cs:16
readonly JoinBlock< T1, T2, T3 > _joinBlock
Definition JoinBlock.cs:189
ITargetBlock< Tuple< T1, T2 > > NextMessageReservedFor
Definition JoinBlock.cs:40
TargetRegistry< Tuple< T1, T2 > > LinkedTargets
Definition JoinBlock.cs:38
DebugView(JoinBlock< T1, T2, T3 > joinBlock)
Definition JoinBlock.cs:219
readonly SourceCore< Tuple< T1, T2, T3 > >.DebuggingInformation _sourceDebuggingInformation
Definition JoinBlock.cs:191
DebugView(JoinBlock< T1, T2 > joinBlock)
Definition JoinBlock.cs:42
IEnumerable< Tuple< T1, T2 > > OutputQueue
Definition JoinBlock.cs:18
bool TryReceiveAll([NotNullWhen(true)] out IList< Tuple< T1, T2 > >? items)
Definition JoinBlock.cs:136
bool TryReceiveAll([NotNullWhen(true)] out IList< Tuple< T1, T2, T3 > >? items)
Definition JoinBlock.cs:318
IDisposable LinkTo(ITargetBlock< Tuple< T1, T2, T3 > > target, DataflowLinkOptions linkOptions)
Definition JoinBlock.cs:308
readonly JoinBlockTarget< T1 > _target1
Definition JoinBlock.cs:53
readonly SourceCore< Tuple< T1, T2, T3 > > _source
Definition JoinBlock.cs:228
JoinBlock(GroupingDataflowBlockOptions dataflowBlockOptions)
Definition JoinBlock.cs:76
readonly JoinBlockTargetSharedResources _sharedResources
Definition JoinBlock.cs:49
bool TryReceive(Predicate< Tuple< T1, T2, T3 > >? filter, [NotNullWhen(true)] out Tuple< T1, T2, T3 >? item)
Definition JoinBlock.cs:313
readonly JoinBlockTarget< T3 > _target3
Definition JoinBlock.cs:234
bool TryReceive(Predicate< Tuple< T1, T2 > >? filter, [NotNullWhen(true)] out Tuple< T1, T2 >? item)
Definition JoinBlock.cs:131
IDisposable LinkTo(ITargetBlock< Tuple< T1, T2 > > target, DataflowLinkOptions linkOptions)
Definition JoinBlock.cs:126
readonly SourceCore< Tuple< T1, T2 > > _source
Definition JoinBlock.cs:51
readonly JoinBlockTarget< T2 > _target2
Definition JoinBlock.cs:55
static new TaskFactory< TResult > Factory
Definition Task.cs:56
static void Write(ref bool location, bool value)
Definition Volatile.cs:74