Skip to content

Commit

Permalink
Merge pull request #847 from microsoft/dev/lifengl/moveAwayWeakDepend…
Browse files Browse the repository at this point in the history
…encies

Use strong references for JTF dependencies.
  • Loading branch information
lifengl committed May 11, 2021
2 parents 63476ca + 6b31a9c commit 1bbd7b2
Showing 1 changed file with 7 additions and 7 deletions.
Expand Up @@ -298,7 +298,7 @@ internal struct JoinableTaskDependentData
/// When the value in an entry is decremented to 0, the entry is removed from the map.
/// </remarks>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private WeakKeyDictionary<IJoinableTaskDependent, int> childDependentNodes;
private Dictionary<IJoinableTaskDependent, int> childDependentNodes;

/// <summary>
/// The head of a singly linked list of records to track which task may process events of this task.
Expand All @@ -309,7 +309,7 @@ internal struct JoinableTaskDependentData
/// <summary>
/// Gets a value indicating whether the <see cref="childDependentNodes"/> is empty.
/// </summary>
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;

/// <summary>
/// Gets a snapshot of all joined tasks.
Expand Down Expand Up @@ -360,7 +360,7 @@ internal static JoinableTaskCollection.JoinRelease AddDependency(IJoinableTaskDe
ref JoinableTaskDependentData data = ref parentTaskOrCollection.GetJoinableTaskDependentData();
if (data.childDependentNodes is null)
{
data.childDependentNodes = new WeakKeyDictionary<IJoinableTaskDependent, int>(capacity: 2);
data.childDependentNodes = new Dictionary<IJoinableTaskDependent, int>(capacity: 2);
}

if (data.childDependentNodes.TryGetValue(joinChild, out int refCount) && !parentTaskOrCollection.NeedRefCountChildDependencies)
Expand Down Expand Up @@ -479,7 +479,7 @@ internal static void AddSelfAndDescendentOrJoinedJobs(IJoinableTaskDependent tas
}
}

WeakKeyDictionary<IJoinableTaskDependent, int>? childDependentNodes = taskOrCollection.GetJoinableTaskDependentData().childDependentNodes;
Dictionary<IJoinableTaskDependent, int>? childDependentNodes = taskOrCollection.GetJoinableTaskDependentData().childDependentNodes;
if (childDependentNodes is object)
{
foreach (KeyValuePair<IJoinableTaskDependent, int> item in childDependentNodes)
Expand Down Expand Up @@ -563,7 +563,7 @@ internal static void ComputeSelfAndDescendentOrJoinedJobsAndRemainTasks(IJoinabl
return;
}

WeakKeyDictionary<IJoinableTaskDependent, int>? dependencies = taskOrCollection.GetJoinableTaskDependentData().childDependentNodes;
Dictionary<IJoinableTaskDependent, int>? dependencies = taskOrCollection.GetJoinableTaskDependentData().childDependentNodes;
if (dependencies is object)
{
foreach (KeyValuePair<IJoinableTaskDependent, int> item in dependencies)
Expand Down Expand Up @@ -691,7 +691,7 @@ internal void OnTaskCompleted(IJoinableTaskDependent thisDependentNode)

if (this.childDependentNodes is object)
{
var childrenTasks = new List<IJoinableTaskDependent>(this.childDependentNodes.Keys);
Dictionary<IJoinableTaskDependent, int>.KeyCollection? childrenTasks = this.childDependentNodes.Keys;
while (existingTaskTracking is object)
{
RemoveDependingSynchronousTaskFrom(childrenTasks, existingTaskTracking.SynchronousTask, force: existingTaskTracking.SynchronousTask == thisDependentNode);
Expand Down Expand Up @@ -901,7 +901,7 @@ private static void RemoveDependingSynchronousTask(IJoinableTaskDependent taskOr
/// <param name="tasks">A list of tasks we need update the tracking list.</param>
/// <param name="syncTask">The synchronous task we want to remove.</param>
/// <param name="force">We always remove it from the tracking list if it is true. Otherwise, we keep tracking the reference count.</param>
private static void RemoveDependingSynchronousTaskFrom(IReadOnlyList<IJoinableTaskDependent> tasks, JoinableTask syncTask, bool force)
private static void RemoveDependingSynchronousTaskFrom(IReadOnlyCollection<IJoinableTaskDependent> tasks, JoinableTask syncTask, bool force)
{
Requires.NotNull(tasks, nameof(tasks));
Requires.NotNull(syncTask, nameof(syncTask));
Expand Down

0 comments on commit 1bbd7b2

Please sign in to comment.