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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/threading/platform_thread_internal_posix.h" 5 #include "base/threading/platform_thread_internal_posix.h"
6 6
7 #include <limits>
7 #include "base/logging.h" 8 #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.
8 9
9 namespace base { 10 namespace base {
10 11
11 namespace internal { 12 namespace internal {
12 13
13 int ThreadPriorityToNiceValue(ThreadPriority priority) { 14 int ThreadPriorityToNiceValue(ThreadPriority priority) {
14 for (const ThreadPriorityToNiceValuePair& pair : 15 for (const ThreadPriorityToNiceValuePair& pair :
15 kThreadPriorityToNiceValueMap) { 16 kThreadPriorityToNiceValueMap) {
16 if (pair.priority == priority) 17 if (pair.priority == priority)
17 return pair.nice_value; 18 return pair.nice_value;
18 } 19 }
19 NOTREACHED() << "Unknown ThreadPriority"; 20 NOTREACHED() << "Unknown ThreadPriority";
20 return 0; 21 return 0;
21 } 22 }
22 23
23 ThreadPriority NiceValueToThreadPriority(int nice_value) { 24 ThreadPriority NiceValueToThreadPriority(int nice_value) {
25 // Try to find a priority that best describes |nice_value|. If there isn't
26 // an exact match, this method returns the closest priority whose nice value
27 // is higher (lower priority) than |nice_value|.
28
29 ThreadPriority best_priority = ThreadPriority::BACKGROUND;
30 int best_nice_value = std::numeric_limits<int>::max();
24 for (const ThreadPriorityToNiceValuePair& pair : 31 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.
25 kThreadPriorityToNiceValueMap) { 32 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!
26 if (pair.nice_value == nice_value) 33 if (pair.nice_value >= nice_value) {
27 return pair.priority; 34 DCHECK_LT(pair.nice_value, best_nice_value);
35 best_priority = pair.priority;
36 best_nice_value = pair.nice_value;
37 } else {
38 break;
39 }
28 } 40 }
29 NOTREACHED() << "Unknown nice value"; 41 return best_priority;
30 return ThreadPriority::NORMAL;
31 } 42 }
32 43
33 } // namespace internal 44 } // namespace internal
34 45
35 } // namespace base 46 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698