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

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: Fix 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..b0919e4fa8705e00f3744c14456e722d60beb706 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"
namespace base {
@@ -21,13 +22,26 @@ 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, we return the priority whose nice value is closest to
gab 2016/04/08 15:50:49 How about: "we return the priority whose nice val
Yuta Kitamura 2016/04/12 10:18:59 Yeah, that's much better (I rewrote the phrase sev
+ // |nice_value| among the priorities whose nice values are more than
+ // |nice_value|.
+
+ ThreadPriority best_priority;
+ int best_nice_value = std::numeric_limits<int>::max();
for (const ThreadPriorityToNiceValuePair& pair :
kThreadPriorityToNiceValueMap) {
gab 2016/04/08 15:50:49 If we add a requirement that the kThreadPriorityTo
Yuta Kitamura 2016/04/12 10:18:59 Adopted your first code. Also added a comment for
- if (pair.nice_value == nice_value)
- return pair.priority;
+ if (pair.nice_value >= nice_value && pair.nice_value < best_nice_value) {
+ best_priority = pair.priority;
+ best_nice_value = pair.nice_value;
+ }
}
- NOTREACHED() << "Unknown nice value";
- return ThreadPriority::NORMAL;
+ if (best_nice_value != std::numeric_limits<int>::max())
+ return best_priority;
+
+ // Reaching here means |nice_value| is more than any of the defined
+ // priorites. The lowest priority is suitable in this case.
+ return ThreadPriority::BACKGROUND;
}
} // namespace internal

Powered by Google App Engine
This is Rietveld 408576698