Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3618)

Unified Diff: base/threading/platform_thread_internal_posix.cc

Issue 1870033002: Fix NiceValueToThreadPriority failing on an unknown nice value. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a comment about exclusion of OSX/iOS. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/threading/platform_thread_internal_posix.h ('k') | base/threading/platform_thread_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/threading/platform_thread_internal_posix.cc
diff --git a/base/threading/platform_thread_internal_posix.cc b/base/threading/platform_thread_internal_posix.cc
index 9af02044fceed2635b4fc5bf1ee5e1a06927a6fe..378a24d0d1d8f9be8aed6da1b6a2dca7ce9dd641 100644
--- a/base/threading/platform_thread_internal_posix.cc
+++ b/base/threading/platform_thread_internal_posix.cc
@@ -4,6 +4,7 @@
#include "base/threading/platform_thread_internal_posix.h"
+#include "base/containers/adapters.h"
#include "base/logging.h"
namespace base {
@@ -11,8 +12,7 @@ namespace base {
namespace internal {
int ThreadPriorityToNiceValue(ThreadPriority priority) {
- for (const ThreadPriorityToNiceValuePair& pair :
- kThreadPriorityToNiceValueMap) {
+ for (const auto& pair : kThreadPriorityToNiceValueMap) {
if (pair.priority == priority)
return pair.nice_value;
}
@@ -21,13 +21,17 @@ int ThreadPriorityToNiceValue(ThreadPriority priority) {
}
ThreadPriority NiceValueToThreadPriority(int nice_value) {
- for (const ThreadPriorityToNiceValuePair& pair :
- kThreadPriorityToNiceValueMap) {
- if (pair.nice_value == nice_value)
+ // Try to find a priority that best describes |nice_value|. If there isn't
+ // an exact match, this method returns the closest priority whose nice value
+ // is higher (lower priority) than |nice_value|.
+ for (const auto& pair : Reversed(kThreadPriorityToNiceValueMap)) {
+ if (pair.nice_value >= nice_value)
return pair.priority;
}
- NOTREACHED() << "Unknown nice value";
- return ThreadPriority::NORMAL;
+
+ // Reaching here means |nice_value| is more than any of the defined
+ // priorities. The lowest priority is suitable in this case.
+ return ThreadPriority::BACKGROUND;
}
} // namespace internal
« no previous file with comments | « base/threading/platform_thread_internal_posix.h ('k') | base/threading/platform_thread_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698