Skip to content

Commit 528bba4

Browse files
Fully separated unprocessed jobs and processed jobs
Extracted reusable PriorityQueue and used it in CooperativeGlobalExecutor.inc
1 parent f93de01 commit 528bba4

File tree

12 files changed

+662
-973
lines changed

12 files changed

+662
-973
lines changed

include/swift/ABI/MetadataValues.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,6 +2511,32 @@ inline int descendingPriorityOrder(JobPriority lhs,
25112511
return (lhs == rhs ? 0 : lhs > rhs ? -1 : 1);
25122512
}
25132513

2514+
enum { PriorityBucketCount = 5 };
2515+
2516+
inline int getPriorityBucketIndex(JobPriority priority) {
2517+
// Any unknown priorities will be rounded up to a known one.
2518+
// Priorities higher than UserInteractive are clamped to UserInteractive.
2519+
// Jobs of unknown priorities will end up in the same bucket as jobs of a
2520+
// corresponding known priority. Within the bucket they will be sorted in
2521+
// FIFO order.
2522+
if (priority > JobPriority::UserInitiated) {
2523+
// UserInteractive and higher
2524+
return 0;
2525+
} else if (priority > JobPriority::Default) {
2526+
// UserInitiated
2527+
return 1;
2528+
} else if (priority > JobPriority::Utility) {
2529+
// Default
2530+
return 2;
2531+
} else if (priority > JobPriority::Background) {
2532+
// Utility
2533+
return 3;
2534+
} else {
2535+
// Background and lower
2536+
return 4;
2537+
}
2538+
}
2539+
25142540
inline JobPriority withUserInteractivePriorityDowngrade(JobPriority priority) {
25152541
return (priority == JobPriority::UserInteractive) ? JobPriority::UserInitiated
25162542
: priority;

0 commit comments

Comments
 (0)