• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "base/threading/platform_thread_internal_posix.h"
6 
7 #include "base/containers/adapters.h"
8 #include "base/logging.h"
9 
10 namespace base {
11 
12 namespace internal {
13 
ThreadPriorityToNiceValue(ThreadPriority priority)14 int ThreadPriorityToNiceValue(ThreadPriority priority) {
15   for (const auto& pair : kThreadPriorityToNiceValueMap) {
16     if (pair.priority == priority)
17       return pair.nice_value;
18   }
19   NOTREACHED() << "Unknown ThreadPriority";
20   return 0;
21 }
22 
NiceValueToThreadPriority(int nice_value)23 ThreadPriority NiceValueToThreadPriority(int nice_value) {
24   // Try to find a priority that best describes |nice_value|. If there isn't
25   // an exact match, this method returns the closest priority whose nice value
26   // is higher (lower priority) than |nice_value|.
27   for (const auto& pair : Reversed(kThreadPriorityToNiceValueMap)) {
28     if (pair.nice_value >= nice_value)
29       return pair.priority;
30   }
31 
32   // Reaching here means |nice_value| is more than any of the defined
33   // priorities. The lowest priority is suitable in this case.
34   return ThreadPriority::BACKGROUND;
35 }
36 
37 }  // namespace internal
38 
39 }  // namespace base
40