public void RemoveLink(LinkRegistration <T> registration) { lock (this._links) { var newList = CreateRemovedList(this._targetToNodeTable[registration.Target]); if (newList == null) { this._targetToNodeTable.Remove(registration.Target); } else { this._targetToNodeTable[registration.Target] = newList; } SingleLinkedList <DoubleLinkedList <LinkRegistration <T> > .Node>?CreateRemovedList( SingleLinkedList <DoubleLinkedList <LinkRegistration <T> > .Node> listNode) { if (listNode.Value.Value == registration) { this._links.Remove(listNode.Value); return(listNode.Next); } if (listNode.Next == null) { throw new ArgumentException("The specified registration is not found."); } listNode.Next = CreateRemovedList(listNode.Next); return(listNode); } } }
IDisposable ISourceBlock <T> .LinkTo(ITargetBlock <T> target, DataflowLinkOptions?linkOptions) { if (target == null) { throw new ArgumentNullException(nameof(target)); } linkOptions ??= new DataflowLinkOptions(); LinkRegistration <T> registration; lock (this.CompletionLock) { if (this.Completion.IsCompleted) { var exception = this.Completion.Exception; if (exception == null) { target.Complete(); } else { target.Fault(exception); } return(ActionDisposable.Nop); } registration = new LinkRegistration <T>(target, linkOptions.MaxMessages, linkOptions.PropagateCompletion, this.HandleUnlink); this._linkManager.AddLink(registration, linkOptions.Append); } this._resetEvent.Set(); return(new ActionDisposable(registration.Unlink)); }
public void AddLink(LinkRegistration <T> registration, bool append) { lock (this._links) { if (append) { var node = this._links.AddLast(registration); var listNode = new SingleLinkedList <DoubleLinkedList <LinkRegistration <T> > .Node>(node); if (this._targetToNodeTable.TryGetValue(registration.Target, out var list)) { while (list.Next != null) { list = list.Next; } list.Next = listNode; } else { this._targetToNodeTable.Add(registration.Target, listNode); } } else { var node = this._links.AddFirst(registration); this._targetToNodeTable.TryGetValue(registration.Target, out var listNode); this._targetToNodeTable[registration.Target] = new SingleLinkedList <DoubleLinkedList <LinkRegistration <T> > .Node>(node, listNode); } } }