Skip to content

Commit e7032ce

Browse files
Fully separated unprocessed jobs and processed jobs
Extracted reusable PriorityQueue and used it in CooperativeGlobalExecutor.inc
1 parent 0da79ec commit e7032ce

File tree

12 files changed

+661
-973
lines changed

12 files changed

+661
-973
lines changed

include/swift/ABI/MetadataValues.h

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

2384+
enum { PriorityBucketCount = 5 };
2385+
2386+
inline int getPriorityBucketIndex(JobPriority priority) {
2387+
// Any unknown priorities will be rounded up to a known one.
2388+
// Priorities higher than UserInteractive are clamped to UserInteractive.
2389+
// Jobs of unknown priorities will end up in the same bucket as jobs of a
2390+
// corresponding known priority. Within the bucket they will be sorted in
2391+
// FIFO order.
2392+
if (priority > JobPriority::UserInitiated) {
2393+
// UserInteractive and higher
2394+
return 0;
2395+
} else if (priority > JobPriority::Default) {
2396+
// UserInitiated
2397+
return 1;
2398+
} else if (priority > JobPriority::Utility) {
2399+
// Default
2400+
return 2;
2401+
} else if (priority > JobPriority::Background) {
2402+
// Utility
2403+
return 3;
2404+
} else {
2405+
// Background and lower
2406+
return 4;
2407+
}
2408+
}
2409+
23842410
inline JobPriority withUserInteractivePriorityDowngrade(JobPriority priority) {
23852411
return (priority == JobPriority::UserInteractive) ? JobPriority::UserInitiated
23862412
: priority;

0 commit comments

Comments
 (0)