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

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: Apply gab's comments. 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
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..360ee113557d3cb2a6a276c71cd0b71979ba0e53 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 <limits>
#include "base/logging.h"
gab 2016/04/12 13:20:46 nit: empty line between C++ includes and Chrome in
Yuta Kitamura 2016/04/13 08:49:17 Done.
namespace base {
@@ -21,13 +22,23 @@ int ThreadPriorityToNiceValue(ThreadPriority priority) {
}
ThreadPriority NiceValueToThreadPriority(int 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|.
+
+ ThreadPriority best_priority = ThreadPriority::BACKGROUND;
+ int best_nice_value = std::numeric_limits<int>::max();
for (const ThreadPriorityToNiceValuePair& pair :
danakj 2016/04/12 21:02:26 this should use const auto&
Yuta Kitamura 2016/04/13 08:49:17 Done.
kThreadPriorityToNiceValueMap) {
danakj 2016/04/12 21:02:26 if you base::Reversed this to iterate opposite, yo
Yuta Kitamura 2016/04/13 08:49:17 Yeah, that's much simpler. Thanks!
- if (pair.nice_value == nice_value)
- return pair.priority;
+ if (pair.nice_value >= nice_value) {
+ DCHECK_LT(pair.nice_value, best_nice_value);
+ best_priority = pair.priority;
+ best_nice_value = pair.nice_value;
+ } else {
+ break;
+ }
}
- NOTREACHED() << "Unknown nice value";
- return ThreadPriority::NORMAL;
+ return best_priority;
}
} // namespace internal

Powered by Google App Engine
This is Rietveld 408576698