Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
JoinBlockTarget.cs
Go to the documentation of this file.
3
5
6[DebuggerDisplay("{DebuggerDisplayContent,nq}")]
9{
18
19 private sealed class DebugView
20 {
22
24
26 {
27 get
28 {
29 if (!_joinBlockTarget._decliningPermanently)
30 {
31 return _joinBlockTarget._sharedResources._decliningPermanently;
32 }
33 return true;
34 }
35 }
36
41 }
42
44
46
47 private readonly Queue<T> _messages;
48
49 private readonly NonGreedyState _nonGreedy;
50
52
54
55 internal override bool HasAtLeastOneMessageAvailable
56 {
57 get
58 {
60 {
61 return _messages.Count > 0;
62 }
64 }
65 }
66
67 internal override bool HasAtLeastOnePostponedMessage
68 {
69 get
70 {
71 if (_nonGreedy != null)
72 {
73 return _nonGreedy.PostponedMessages.Count > 0;
74 }
75 return false;
76 }
77 }
78
80 {
81 get
82 {
84 {
85 return _messages.Count;
86 }
88 }
89 }
90
92 {
93 get
94 {
95 int count = _messages.Count;
97 foreach (JoinBlockTargetBase joinBlockTargetBase in targets)
98 {
99 if (joinBlockTargetBase != this && joinBlockTargetBase.NumberOfMessagesAvailableOrPostponed > count)
100 {
101 return false;
102 }
103 }
104 return true;
105 }
106 }
107
109 {
110 get
111 {
113 }
114 }
115
117
119 {
120 get
121 {
122 if (_messages == null)
123 {
125 {
126 return 0;
127 }
128 return 1;
129 }
130 return _messages.Count;
131 }
132 }
133
135 {
136 get
137 {
138 IDebuggerDisplay debuggerDisplay = _sharedResources._ownerJoin as IDebuggerDisplay;
139 return $"{Common.GetNameForDebugger(this)} InputCount={InputCountForDebugger}, Join=\"{((debuggerDisplay != null) ? debuggerDisplay.Content : _sharedResources._ownerJoin)}\"";
140 }
141 }
142
143 object IDebuggerDisplay.Content => DebuggerDisplayContent;
144
146 {
149 if (!dataflowBlockOptions.Greedy || dataflowBlockOptions.BoundedCapacity > 0)
150 {
152 }
153 if (dataflowBlockOptions.Greedy)
154 {
155 _messages = new Queue<T>();
156 }
157 }
158
159 internal T GetOneMessage()
160 {
162 {
163 return _messages.Dequeue();
164 }
166 _nonGreedy.ConsumedMessage = new KeyValuePair<bool, T>(key: false, default(T));
167 return value;
168 }
169
170 internal override bool ReserveOneMessage()
171 {
174 {
176 {
177 return false;
178 }
179 }
180 while (!item.Key.ReserveMessage(item.Value, this))
181 {
183 {
185 {
186 return false;
187 }
188 }
189 }
190 _nonGreedy.ReservedMessage = item;
191 return true;
192 }
193
194 internal override bool ConsumeReservedMessage()
195 {
196 bool messageConsumed;
197 T value = _nonGreedy.ReservedMessage.Key.ConsumeMessage(_nonGreedy.ReservedMessage.Value, this, out messageConsumed);
198 _nonGreedy.ReservedMessage = default(KeyValuePair<ISourceBlock<T>, DataflowMessageHeader>);
199 if (!messageConsumed)
200 {
203 return false;
204 }
206 {
207 _nonGreedy.ConsumedMessage = new KeyValuePair<bool, T>(key: true, value);
209 }
210 return true;
211 }
212
213 internal override bool ConsumeOnePostponedMessage()
214 {
216 T item2;
217 bool messageConsumed;
218 do
219 {
222 {
224 bool flag = _sharedResources._boundingState.CountIsLessThanBound || !hasTheHighestNumberOfMessagesAvailable;
226 {
227 return false;
228 }
229 }
230 item2 = item.Key.ConsumeMessage(item.Value, this, out messageConsumed);
231 }
232 while (!messageConsumed);
234 {
236 {
238 }
239 _messages.Enqueue(item2);
241 return true;
242 }
243 }
244
246 {
247 int num = (_sharedResources._dataflowBlockOptions.Greedy ? _messages.Count : (_nonGreedy.ConsumedMessage.Key ? 1 : 0));
249 {
250 return;
251 }
253 bool flag = true;
255 foreach (JoinBlockTargetBase joinBlockTargetBase in targets)
256 {
257 if (!joinBlockTargetBase.IsDecliningPermanently)
258 {
259 flag = false;
260 break;
261 }
262 }
263 if (flag)
264 {
265 _sharedResources._decliningPermanently = true;
266 }
267 }
268
269 internal override void ReleaseReservedMessage()
270 {
271 if (_nonGreedy != null && _nonGreedy.ReservedMessage.Key != null)
272 {
273 try
274 {
275 _nonGreedy.ReservedMessage.Key.ReleaseReservation(_nonGreedy.ReservedMessage.Value, this);
276 }
277 finally
278 {
280 }
281 }
282 }
283
284 internal override void ClearReservation()
285 {
286 _nonGreedy.ReservedMessage = default(KeyValuePair<ISourceBlock<T>, DataflowMessageHeader>);
287 }
288
289 internal override void CompleteOncePossible()
290 {
292 {
294 if (_messages != null)
295 {
296 _messages.Clear();
297 }
298 }
300 if (_nonGreedy != null)
301 {
302 Common.ReleaseAllPostponedMessages(this, _nonGreedy.PostponedMessages, ref exceptions);
303 }
304 if (exceptions != null)
305 {
306 foreach (Exception item in exceptions)
307 {
309 }
310 }
311 _completionTask.TrySetResult(default(VoidResult));
312 }
313
315 {
316 if (!messageHeader.IsValid)
317 {
318 throw new ArgumentException(System.SR.Argument_InvalidMessageHeader, "messageHeader");
319 }
320 if (source == null && consumeToAccept)
321 {
323 }
325 {
327 {
329 return DataflowMessageStatus.DecliningPermanently;
330 }
332 {
333 if (consumeToAccept)
334 {
335 messageValue = source.ConsumeMessage(messageHeader, this, out var messageConsumed);
336 if (!messageConsumed)
337 {
338 return DataflowMessageStatus.NotAvailable;
339 }
340 }
342 {
344 }
345 _messages.Enqueue(messageValue);
348 {
351 }
353 return DataflowMessageStatus.Accepted;
354 }
355 if (source != null)
356 {
359 return DataflowMessageStatus.Postponed;
360 }
361 return DataflowMessageStatus.Declined;
362 }
363 }
364
366 {
369 {
371 {
373 }
375 {
376 _messages.Clear();
377 }
378 }
380 {
382 foreach (JoinBlockTargetBase joinBlockTargetBase in targets)
383 {
384 try
385 {
386 joinBlockTargetBase.ReleaseReservedMessage();
387 }
388 catch (Exception obj)
389 {
391 }
392 }
393 }
395 {
398 }
399 }
400
402 {
403 if (exception == null)
404 {
405 throw new ArgumentNullException("exception");
406 }
408 }
409}
static string InvalidOperation_FailedToConsumeReservedMessage
Definition SR.cs:32
static string Argument_InvalidMessageHeader
Definition SR.cs:24
static string NotSupported_MemberNotNeeded
Definition SR.cs:36
static string Argument_CantConsumeFromANullSource
Definition SR.cs:22
Definition SR.cs:7
readonly QueuedMap< ISourceBlock< T >, DataflowMessageHeader > PostponedMessages
KeyValuePair< ISourceBlock< T >, DataflowMessageHeader > ReservedMessage
JoinBlockTarget(JoinBlockTargetSharedResources sharedResources)
readonly TaskCompletionSource< VoidResult > _completionTask
readonly JoinBlockTargetSharedResources _sharedResources
override void CompleteCore(Exception exception, bool dropPendingMessages, bool releaseReservedMessages)