Skip to content

Commit f2d65c1

Browse files
committed
Fix priority propagation when creating new tasks
1 parent ec367ce commit f2d65c1

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

stdlib/public/Concurrency/Task.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,20 @@ static AsyncTaskAndContext swift_task_create_commonImpl(
450450
if (jobFlags.task_isChildTask()) {
451451
parent = swift_task_getCurrent();
452452
assert(parent != nullptr && "creating a child task with no active task");
453+
}
453454

454-
// Inherit the priority of the parent task if unspecified.
455-
if (jobFlags.getPriority() == JobPriority::Unspecified)
456-
jobFlags.setPriority(parent->getPriority());
455+
// Inherit the priority of the currently-executing task if unspecified and
456+
// we want to inherit.
457+
if (jobFlags.getPriority() == JobPriority::Unspecified &&
458+
(jobFlags.task_isChildTask() || taskCreateFlags.inheritContext())) {
459+
AsyncTask *currentTask = parent;
460+
if (!currentTask)
461+
currentTask = swift_task_getCurrent();
462+
463+
if (currentTask)
464+
jobFlags.setPriority(currentTask->getPriority());
465+
else
466+
jobFlags.setPriority(swift_task_getCurrentThreadPriority());
457467
}
458468

459469
// Figure out the size of the header.

0 commit comments

Comments
 (0)