Skip to content

Commit 1e6c662

Browse files
committed
Fix priority propagation when creating new tasks
1 parent 5148ec6 commit 1e6c662

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
@@ -445,10 +445,20 @@ static AsyncTaskAndContext swift_task_create_commonImpl(
445445
if (jobFlags.task_isChildTask()) {
446446
parent = swift_task_getCurrent();
447447
assert(parent != nullptr && "creating a child task with no active task");
448+
}
448449

449-
// Inherit the priority of the parent task if unspecified.
450-
if (jobFlags.getPriority() == JobPriority::Unspecified)
451-
jobFlags.setPriority(parent->getPriority());
450+
// Inherit the priority of the currently-executing task if unspecified and
451+
// we want to inherit.
452+
if (jobFlags.getPriority() == JobPriority::Unspecified &&
453+
(jobFlags.task_isChildTask() || taskCreateFlags.inheritContext())) {
454+
AsyncTask *currentTask = parent;
455+
if (!currentTask)
456+
currentTask = swift_task_getCurrent();
457+
458+
if (currentTask)
459+
jobFlags.setPriority(currentTask->getPriority());
460+
else
461+
jobFlags.setPriority(swift_task_getCurrentThreadPriority());
452462
}
453463

454464
// Figure out the size of the header.

0 commit comments

Comments
 (0)