Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use strong references for JTF dependencies. #847

Merged
merged 1 commit into from May 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -290,7 +290,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 @@ -301,7 +301,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 @@ -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<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 @@ -471,7 +471,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 @@ -555,7 +555,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 @@ -664,7 +664,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 @@ -871,7 +871,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