Skip to content

Commit f93de01

Browse files
Fallback logic for unknown priorities
1 parent 9888026 commit f93de01

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

stdlib/public/Concurrency/Actor.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,19 +1000,26 @@ static void setNextJob(Job *job, Job* next) {
10001000
enum { NumPriorityBuckets = 5 };
10011001

10021002
static int getPriorityIndex(JobPriority priority) {
1003-
switch (priority) {
1004-
case JobPriority::UserInteractive:
1005-
return 0;
1006-
case JobPriority::UserInitiated:
1007-
return 1;
1008-
case JobPriority::Unspecified:
1009-
assert(false);
1010-
case JobPriority::Default:
1011-
return 2;
1012-
case JobPriority::Utility:
1013-
return 3;
1014-
case JobPriority::Background:
1015-
return 4;
1003+
// Any unknown priorities will be rounded up to a known one.
1004+
// Priorities higher than UserInteractive are clamped to UserInteractive.
1005+
// Jobs of unknown priorities will end up in the same bucket as jobs of a
1006+
// corresponding known priority. Within the bucket they will be sorted in FIFO
1007+
// order.
1008+
if (priority > JobPriority::UserInitiated) {
1009+
// UserInteractive and higher
1010+
return 0;
1011+
} else if (priority > JobPriority::Default) {
1012+
// UserInitiated
1013+
return 1;
1014+
} else if (priority > JobPriority::Utility) {
1015+
// Default
1016+
return 2;
1017+
} else if (priority > JobPriority::Background) {
1018+
// Utility
1019+
return 3;
1020+
} else {
1021+
// Background and lower
1022+
return 4;
10161023
}
10171024
}
10181025

0 commit comments

Comments
 (0)