From 6b31a9cce9d9c85a896195bfdd4c7ff0b660470b Mon Sep 17 00:00:00 2001 From: Lifeng Lu Date: Sun, 7 Mar 2021 13:11:43 -0800 Subject: [PATCH] Use strong references for JTF dependencies. --- .../JoinableTaskDependencyGraph.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.VisualStudio.Threading/JoinableTaskDependencyGraph.cs b/src/Microsoft.VisualStudio.Threading/JoinableTaskDependencyGraph.cs index 4fa79a37e..90824c7b0 100644 --- a/src/Microsoft.VisualStudio.Threading/JoinableTaskDependencyGraph.cs +++ b/src/Microsoft.VisualStudio.Threading/JoinableTaskDependencyGraph.cs @@ -290,7 +290,7 @@ internal struct JoinableTaskDependentData /// When the value in an entry is decremented to 0, the entry is removed from the map. /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private WeakKeyDictionary childDependentNodes; + private Dictionary childDependentNodes; /// /// The head of a singly linked list of records to track which task may process events of this task. @@ -301,7 +301,7 @@ internal struct JoinableTaskDependentData /// /// Gets a value indicating whether the is empty. /// - internal bool HasNoChildDependentNode => this.childDependentNodes is null || this.childDependentNodes.Count == 0 || !this.childDependentNodes.Any(); + internal bool HasNoChildDependentNode => this.childDependentNodes is null || this.childDependentNodes.Count == 0; /// /// Gets a snapshot of all joined tasks. @@ -352,7 +352,7 @@ internal static JoinableTaskCollection.JoinRelease AddDependency(IJoinableTaskDe ref JoinableTaskDependentData data = ref parentTaskOrCollection.GetJoinableTaskDependentData(); if (data.childDependentNodes is null) { - data.childDependentNodes = new WeakKeyDictionary(capacity: 2); + data.childDependentNodes = new Dictionary(capacity: 2); } if (data.childDependentNodes.TryGetValue(joinChild, out int refCount) && !parentTaskOrCollection.NeedRefCountChildDependencies) @@ -471,7 +471,7 @@ internal static void AddSelfAndDescendentOrJoinedJobs(IJoinableTaskDependent tas } } - WeakKeyDictionary? childDependentNodes = taskOrCollection.GetJoinableTaskDependentData().childDependentNodes; + Dictionary? childDependentNodes = taskOrCollection.GetJoinableTaskDependentData().childDependentNodes; if (childDependentNodes is object) { foreach (KeyValuePair item in childDependentNodes) @@ -555,7 +555,7 @@ internal static void ComputeSelfAndDescendentOrJoinedJobsAndRemainTasks(IJoinabl return; } - WeakKeyDictionary? dependencies = taskOrCollection.GetJoinableTaskDependentData().childDependentNodes; + Dictionary? dependencies = taskOrCollection.GetJoinableTaskDependentData().childDependentNodes; if (dependencies is object) { foreach (KeyValuePair item in dependencies) @@ -664,7 +664,7 @@ internal void OnTaskCompleted(IJoinableTaskDependent thisDependentNode) if (this.childDependentNodes is object) { - var childrenTasks = new List(this.childDependentNodes.Keys); + Dictionary.KeyCollection? childrenTasks = this.childDependentNodes.Keys; while (existingTaskTracking is object) { RemoveDependingSynchronousTaskFrom(childrenTasks, existingTaskTracking.SynchronousTask, force: existingTaskTracking.SynchronousTask == thisDependentNode); @@ -871,7 +871,7 @@ private static void RemoveDependingSynchronousTask(IJoinableTaskDependent taskOr /// A list of tasks we need update the tracking list. /// The synchronous task we want to remove. /// We always remove it from the tracking list if it is true. Otherwise, we keep tracking the reference count. - private static void RemoveDependingSynchronousTaskFrom(IReadOnlyList tasks, JoinableTask syncTask, bool force) + private static void RemoveDependingSynchronousTaskFrom(IReadOnlyCollection tasks, JoinableTask syncTask, bool force) { Requires.NotNull(tasks, nameof(tasks)); Requires.NotNull(syncTask, nameof(syncTask));