Skip to content

Commit 4c7314e

Browse files
author
Lifeng Lu
committed
Fix problems raised in code review.
Minor style changes + make code slightly more efficient.
1 parent 62082a5 commit 4c7314e

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/Microsoft.VisualStudio.Threading/JoinableTaskDependencyGraph.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ internal static bool CleanUpPotentialUnreachableDependentItems(JoinableTask sync
241241
if (possibleUnreachableItems is object && possibleUnreachableItems.Count > 0)
242242
{
243243
var reachableNodes = new HashSet<IJoinableTaskDependent>();
244-
var syncTaskItem = (IJoinableTaskDependent)syncTask;
244+
IJoinableTaskDependent syncTaskItem = syncTask;
245245

246246
JoinableTaskDependentData.ComputeSelfAndDescendentOrJoinedJobsAndRemainTasks(syncTaskItem, reachableNodes, possibleUnreachableItems);
247247

@@ -453,7 +453,17 @@ internal static void AddSelfAndDescendentOrJoinedJobs(IJoinableTaskDependent tas
453453

454454
if (taskOrCollection is JoinableTask thisJoinableTask)
455455
{
456-
if (thisJoinableTask.IsFullyCompleted || !joinables.Add(thisJoinableTask) || thisJoinableTask.IsCompleteRequested)
456+
if (thisJoinableTask.IsCompleteRequested)
457+
{
458+
if (!thisJoinableTask.IsFullyCompleted)
459+
{
460+
joinables.Add(thisJoinableTask);
461+
}
462+
463+
return;
464+
}
465+
466+
if (!joinables.Add(thisJoinableTask))
457467
{
458468
return;
459469
}
@@ -483,7 +493,6 @@ internal static void OnSynchronousTaskStartToBlockWaiting(JoinableTask syncTask,
483493
Requires.NotNull(syncTask, nameof(syncTask));
484494

485495
pendingRequestsCount = 0;
486-
taskHasPendingRequests = null;
487496

488497
taskHasPendingRequests = AddDependingSynchronousTask(syncTask, syncTask, ref pendingRequestsCount);
489498
}
@@ -502,7 +511,7 @@ internal static void OnSynchronousTaskEndToBlockWaiting(JoinableTask syncTask)
502511
lock (syncTask.Factory.Context.SyncContextLock)
503512
{
504513
// Remove itself from the tracking list, after the task is completed.
505-
var syncTaskItem = (IJoinableTaskDependent)syncTask;
514+
IJoinableTaskDependent syncTaskItem = syncTask;
506515
if (syncTaskItem.GetJoinableTaskDependentData().dependingSynchronousTaskTracking is object)
507516
{
508517
RemoveDependingSynchronousTask(syncTask, syncTask, force: true);

0 commit comments

Comments
 (0)