@@ -574,12 +574,16 @@ static inline bool isUnspecified(JobPriority priority) {
574
574
return priority == JobPriority::Unspecified;
575
575
}
576
576
577
- static inline bool taskIsUnstructured (JobFlags jobFlags) {
578
- return !jobFlags.task_isAsyncLetTask () && !jobFlags.task_isGroupChildTask ();
577
+ static inline bool taskIsStructured (JobFlags jobFlags) {
578
+ return jobFlags.task_isAsyncLetTask () || jobFlags.task_isGroupChildTask ();
579
+ }
580
+
581
+ static inline bool taskIsUnstructured (TaskCreateFlags createFlags, JobFlags jobFlags) {
582
+ return !taskIsStructured (jobFlags) && !createFlags.isInlineTask ();
579
583
}
580
584
581
585
static inline bool taskIsDetached (TaskCreateFlags createFlags, JobFlags jobFlags) {
582
- return taskIsUnstructured (jobFlags) && !createFlags.copyTaskLocals ();
586
+ return taskIsUnstructured (createFlags, jobFlags) && !createFlags.copyTaskLocals ();
583
587
}
584
588
585
589
static std::pair<size_t , size_t > amountToAllocateForHeaderAndTask (
@@ -692,20 +696,27 @@ static AsyncTaskAndContext swift_task_create_commonImpl(
692
696
// Start with user specified priority at creation time (if any)
693
697
JobPriority basePriority = (taskCreateFlags.getRequestedPriority ());
694
698
695
- if (taskIsDetached (taskCreateFlags, jobFlags)) {
696
- SWIFT_TASK_DEBUG_LOG (" Creating a detached task from %p" , currentTask);
697
- // Case 1: No priority specified
698
- // Base priority = UN
699
- // Escalated priority = UN
700
- // Case 2: Priority specified
701
- // Base priority = user specified priority
702
- // Escalated priority = UN
703
- //
704
- // Task will be created with max priority = max(base priority, UN) = base
705
- // priority. We shouldn't need to do any additional manipulations here since
706
- // basePriority should already be the right value
699
+ if (taskCreateFlags.isInlineTask ()) {
700
+ SWIFT_TASK_DEBUG_LOG (" Creating an inline task from %p" , currentTask);
701
+
702
+ // We'll take the current priority and set it as base and escalated
703
+ // priority of the task. No UI->IN downgrade needed.
704
+ basePriority = swift_task_getCurrentThreadPriority ();
707
705
708
- } else if (taskIsUnstructured (jobFlags)) {
706
+ } else if (taskIsDetached (taskCreateFlags, jobFlags)) {
707
+ SWIFT_TASK_DEBUG_LOG (" Creating a detached task from %p" , currentTask);
708
+ // Case 1: No priority specified
709
+ // Base priority = UN
710
+ // Escalated priority = UN
711
+ // Case 2: Priority specified
712
+ // Base priority = user specified priority
713
+ // Escalated priority = UN
714
+ //
715
+ // Task will be created with max priority = max(base priority, UN) = base
716
+ // priority. We shouldn't need to do any additional manipulations here since
717
+ // basePriority should already be the right value
718
+
719
+ } else if (taskIsUnstructured (taskCreateFlags, jobFlags)) {
709
720
SWIFT_TASK_DEBUG_LOG (" Creating an unstructured task from %p" , currentTask);
710
721
711
722
if (isUnspecified (basePriority)) {
@@ -1009,8 +1020,10 @@ void swift::swift_task_run_inline(OpaqueValue *result, void *closureAFP,
1009
1020
// containing a pointer to the allocation enabling us to provide our stack
1010
1021
// allocation rather than swift_task_create_common having to malloc it.
1011
1022
RunInlineTaskOptionRecord option (allocation, allocationBytes);
1023
+ size_t taskCreateFlags = 1 << TaskCreateFlags::Task_IsInlineTask;
1024
+
1012
1025
auto taskAndContext = swift_task_create_common (
1013
- /* rawTaskCreateFlags= */ 0 , &option, futureResultType,
1026
+ taskCreateFlags , &option, futureResultType,
1014
1027
reinterpret_cast <TaskContinuationFunction *>(closure), closureContext,
1015
1028
/* initialContextSize=*/ closureContextSize);
1016
1029
0 commit comments