OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.h" | 5 #include "base/threading/platform_thread.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <sched.h> | 8 #include <sched.h> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/threading/platform_thread_internal_posix.h" | 12 #include "base/threading/platform_thread_internal_posix.h" |
13 #include "base/threading/thread_id_name_manager.h" | 13 #include "base/threading/thread_id_name_manager.h" |
14 #include "base/tracked_objects.h" | 14 #include "base/tracked_objects.h" |
15 | 15 |
16 #if !defined(OS_NACL) | 16 #if !defined(OS_NACL) |
17 #include <pthread.h> | 17 #include <pthread.h> |
18 #include <sys/prctl.h> | 18 #include <sys/prctl.h> |
19 #include <sys/types.h> | 19 #include <sys/types.h> |
20 #include <unistd.h> | 20 #include <unistd.h> |
21 #endif | 21 #endif |
22 | 22 |
23 namespace base { | 23 namespace base { |
24 | 24 |
25 namespace internal { | 25 namespace internal { |
26 | 26 |
27 namespace { | 27 namespace { |
28 #if !defined(OS_NACL) | 28 #if !defined(OS_NACL) |
29 const struct sched_param kRealTimePrio = {8}; | 29 const struct sched_param kRealTimePrio = {8}; |
| 30 const struct sched_param kResetPrio = {0}; |
30 #endif | 31 #endif |
31 } // namespace | 32 } // namespace |
32 | 33 |
33 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = { | 34 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = { |
34 {ThreadPriority::BACKGROUND, 10}, | 35 {ThreadPriority::BACKGROUND, 10}, |
35 {ThreadPriority::NORMAL, 0}, | 36 {ThreadPriority::NORMAL, 0}, |
36 {ThreadPriority::DISPLAY, -6}, | 37 {ThreadPriority::DISPLAY, -6}, |
37 {ThreadPriority::REALTIME_AUDIO, -10}, | 38 {ThreadPriority::REALTIME_AUDIO, -10}, |
38 }; | 39 }; |
39 | 40 |
40 bool SetThreadPriorityForPlatform(PlatformThreadHandle handle, | 41 bool SetThreadPriorityForPlatform(PlatformThreadHandle handle, |
41 ThreadPriority priority) { | 42 ThreadPriority priority) { |
42 #if !defined(OS_NACL) | 43 #if !defined(OS_NACL) |
| 44 ThreadPriority current_priority; |
| 45 if (priority != ThreadPriority::REALTIME_AUDIO && |
| 46 GetThreadPriorityForPlatform(handle, ¤t_priority) && |
| 47 current_priority == ThreadPriority::REALTIME_AUDIO) { |
| 48 // If the pthread's round-robin scheduler is already enabled, and the new |
| 49 // priority will use setpriority() instead, the pthread scheduler should be |
| 50 // reset to use SCHED_OTHER so that setpriority() just works. |
| 51 pthread_setschedparam(pthread_self(), SCHED_OTHER, &kResetPrio); |
| 52 return false; |
| 53 } |
43 // TODO(gab): Assess the correctness of using |pthread_self()| below instead | 54 // TODO(gab): Assess the correctness of using |pthread_self()| below instead |
44 // of |handle|. http://crbug.com/468793. | 55 // of |handle|. http://crbug.com/468793. |
45 return priority == ThreadPriority::REALTIME_AUDIO && | 56 return priority == ThreadPriority::REALTIME_AUDIO && |
46 pthread_setschedparam(pthread_self(), SCHED_RR, &kRealTimePrio) == 0; | 57 pthread_setschedparam(pthread_self(), SCHED_RR, &kRealTimePrio) == 0; |
47 #else | 58 #else |
48 return false; | 59 return false; |
49 #endif | 60 #endif |
50 } | 61 } |
51 | 62 |
52 bool GetThreadPriorityForPlatform(PlatformThreadHandle handle, | 63 bool GetThreadPriorityForPlatform(PlatformThreadHandle handle, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 #if !defined(THREAD_SANITIZER) | 115 #if !defined(THREAD_SANITIZER) |
105 return 0; | 116 return 0; |
106 #else | 117 #else |
107 // ThreadSanitizer bloats the stack heavily. Evidence has been that the | 118 // ThreadSanitizer bloats the stack heavily. Evidence has been that the |
108 // default stack size isn't enough for some browser tests. | 119 // default stack size isn't enough for some browser tests. |
109 return 2 * (1 << 23); // 2 times 8192K (the default stack size on Linux). | 120 return 2 * (1 << 23); // 2 times 8192K (the default stack size on Linux). |
110 #endif | 121 #endif |
111 } | 122 } |
112 | 123 |
113 } // namespace base | 124 } // namespace base |
OLD | NEW |