Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TargetRegistry.cs
Go to the documentation of this file.
3
5
6[DebuggerDisplay("Count={Count}")]
8internal sealed class TargetRegistry<T>
9{
10 internal sealed class LinkedTargetInfo
11 {
12 internal readonly ITargetBlock<T> Target;
13
14 internal readonly bool PropagateCompletion;
15
16 internal int RemainingMessages;
17
19
21
23 {
24 Target = target;
25 PropagateCompletion = linkOptions.PropagateCompletion;
26 RemainingMessages = linkOptions.MaxMessages;
27 }
28 }
29
30 [DebuggerDisplay("{DebuggerDisplayContent,nq}")]
31 [DebuggerTypeProxy(typeof(TargetRegistry<>.NopLinkPropagator.DebugView))]
33 {
45
47
48 private readonly ITargetBlock<T> _target;
49
50 Task IDataflowBlock.Completion => _owningSource.Completion;
51
53 {
54 get
55 {
58 return $"{Common.GetNameForDebugger(this)} Source=\"{((debuggerDisplay != null) ? debuggerDisplay.Content : _owningSource)}\", Target=\"{((debuggerDisplay2 != null) ? debuggerDisplay2.Content : _target)}\"";
59 }
60 }
61
62 object IDebuggerDisplay.Content => DebuggerDisplayContent;
63
69
74
79
84
89
91 {
92 _target.Complete();
93 }
94
99
104 }
105
106 private sealed class DebugView
107 {
108 private readonly TargetRegistry<T> _registry;
109
111 public ITargetBlock<T>[] Targets => _registry.TargetsForDebugger;
112
117 }
118
120
122
124
126
128
130
132
134 {
135 get
136 {
138 int num = 0;
140 {
141 array[num++] = linkedTargetInfo.Target;
142 }
143 return array;
144 }
145 }
146
152
154 {
156 {
157 target = new NopLinkPropagator(_owningSource, target);
158 }
162 if (linkedTargetInfo.RemainingMessages > 0)
163 {
165 }
167 if (log.IsEnabled())
168 {
169 log.DataflowBlockLinking(_owningSource, target);
170 }
171 }
172
173 internal void Remove(ITargetBlock<T> target, bool onlyIfReachedMaxMessages = false)
174 {
176 {
178 }
179 }
180
182 {
184 {
185 return;
186 }
187 if (!onlyIfReachedMaxMessages || value.RemainingMessages == 1)
188 {
191 if (value.RemainingMessages == 0)
192 {
194 }
196 if (log.IsEnabled())
197 {
198 log.DataflowBlockUnlinking(_owningSource, target);
199 }
200 }
201 else if (value.RemainingMessages > 0)
202 {
203 value.RemainingMessages--;
204 }
205 }
206
215
227
229 {
230 if (_firstTarget == null && _lastTarget == null)
231 {
233 }
234 else if (append)
235 {
236 node.Previous = _lastTarget;
237 _lastTarget.Next = node;
239 }
240 else
241 {
242 node.Next = _firstTarget;
243 _firstTarget.Previous = node;
245 }
246 }
247
249 {
250 LinkedTargetInfo previous = node.Previous;
251 LinkedTargetInfo next = node.Next;
252 if (node.Previous != null)
253 {
254 node.Previous.Next = next;
255 node.Previous = null;
256 }
257 if (node.Next != null)
258 {
259 node.Next.Previous = previous;
260 node.Next = null;
261 }
262 if (_firstTarget == node)
263 {
264 _firstTarget = next;
265 }
266 if (_lastTarget == node)
267 {
269 }
270 }
271}
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)
static string NotSupported_MemberNotNeeded
Definition SR.cs:36
Definition SR.cs:7
static readonly Action< Exception > AsyncExceptionHandler
Definition Common.cs:36
static void PropagateCompletion(Task sourceCompletionTask, IDataflowBlock target, Action< Exception > exceptionHandler)
Definition Common.cs:324
LinkedTargetInfo(ITargetBlock< T > target, DataflowLinkOptions linkOptions)
NopLinkPropagator(ISourceBlock< T > owningSource, ITargetBlock< T > target)
void PropagateCompletion(LinkedTargetInfo firstTarget)
void Remove(ITargetBlock< T > target, bool onlyIfReachedMaxMessages=false)
void AddToList(LinkedTargetInfo node, bool append)
void Add(ref ITargetBlock< T > target, DataflowLinkOptions linkOptions)
readonly Dictionary< ITargetBlock< T >, LinkedTargetInfo > _targetInformation
void Remove_Slow(ITargetBlock< T > target, bool onlyIfReachedMaxMessages)
bool ReserveMessage(DataflowMessageHeader messageHeader, ITargetBlock< TOutput > target)
void ReleaseReservation(DataflowMessageHeader messageHeader, ITargetBlock< TOutput > target)
TOutput? ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock< TOutput > target, out bool messageConsumed)
DataflowMessageStatus OfferMessage(DataflowMessageHeader messageHeader, TInput messageValue, ISourceBlock< TInput >? source, bool consumeToAccept)