| 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" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #endif | 31 #endif |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = { | 34 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = { |
| 35 {ThreadPriority::BACKGROUND, 10}, | 35 {ThreadPriority::BACKGROUND, 10}, |
| 36 {ThreadPriority::NORMAL, 0}, | 36 {ThreadPriority::NORMAL, 0}, |
| 37 {ThreadPriority::DISPLAY, -6}, | 37 {ThreadPriority::DISPLAY, -6}, |
| 38 {ThreadPriority::REALTIME_AUDIO, -10}, | 38 {ThreadPriority::REALTIME_AUDIO, -10}, |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 bool SetThreadPriorityForPlatform(PlatformThreadHandle handle, | 41 bool SetCurrentThreadPriorityForPlatform(ThreadPriority priority) { |
| 42 ThreadPriority priority) { | |
| 43 #if !defined(OS_NACL) | 42 #if !defined(OS_NACL) |
| 44 ThreadPriority current_priority; | 43 ThreadPriority current_priority; |
| 45 if (priority != ThreadPriority::REALTIME_AUDIO && | 44 if (priority != ThreadPriority::REALTIME_AUDIO && |
| 46 GetThreadPriorityForPlatform(handle, ¤t_priority) && | 45 GetCurrentThreadPriorityForPlatform(¤t_priority) && |
| 47 current_priority == ThreadPriority::REALTIME_AUDIO) { | 46 current_priority == ThreadPriority::REALTIME_AUDIO) { |
| 48 // If the pthread's round-robin scheduler is already enabled, and the new | 47 // If the pthread's round-robin scheduler is already enabled, and the new |
| 49 // priority will use setpriority() instead, the pthread scheduler should be | 48 // priority will use setpriority() instead, the pthread scheduler should be |
| 50 // reset to use SCHED_OTHER so that setpriority() just works. | 49 // reset to use SCHED_OTHER so that setpriority() just works. |
| 51 pthread_setschedparam(pthread_self(), SCHED_OTHER, &kResetPrio); | 50 pthread_setschedparam(pthread_self(), SCHED_OTHER, &kResetPrio); |
| 52 return false; | 51 return false; |
| 53 } | 52 } |
| 54 // TODO(gab): Assess the correctness of using |pthread_self()| below instead | |
| 55 // of |handle|. http://crbug.com/468793. | |
| 56 return priority == ThreadPriority::REALTIME_AUDIO && | 53 return priority == ThreadPriority::REALTIME_AUDIO && |
| 57 pthread_setschedparam(pthread_self(), SCHED_RR, &kRealTimePrio) == 0; | 54 pthread_setschedparam(pthread_self(), SCHED_RR, &kRealTimePrio) == 0; |
| 58 #else | 55 #else |
| 59 return false; | 56 return false; |
| 60 #endif | 57 #endif |
| 61 } | 58 } |
| 62 | 59 |
| 63 bool GetThreadPriorityForPlatform(PlatformThreadHandle handle, | 60 bool GetCurrentThreadPriorityForPlatform(ThreadPriority* priority) { |
| 64 ThreadPriority* priority) { | |
| 65 #if !defined(OS_NACL) | 61 #if !defined(OS_NACL) |
| 66 int maybe_sched_rr = 0; | 62 int maybe_sched_rr = 0; |
| 67 struct sched_param maybe_realtime_prio = {0}; | 63 struct sched_param maybe_realtime_prio = {0}; |
| 68 // TODO(gab): Assess the correctness of using |pthread_self()| below instead | |
| 69 // of |handle|. http://crbug.com/468793. | |
| 70 if (pthread_getschedparam(pthread_self(), &maybe_sched_rr, | 64 if (pthread_getschedparam(pthread_self(), &maybe_sched_rr, |
| 71 &maybe_realtime_prio) == 0 && | 65 &maybe_realtime_prio) == 0 && |
| 72 maybe_sched_rr == SCHED_RR && | 66 maybe_sched_rr == SCHED_RR && |
| 73 maybe_realtime_prio.sched_priority == kRealTimePrio.sched_priority) { | 67 maybe_realtime_prio.sched_priority == kRealTimePrio.sched_priority) { |
| 74 *priority = ThreadPriority::REALTIME_AUDIO; | 68 *priority = ThreadPriority::REALTIME_AUDIO; |
| 75 return true; | 69 return true; |
| 76 } | 70 } |
| 77 #endif | 71 #endif |
| 78 return false; | 72 return false; |
| 79 } | 73 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 #if !defined(THREAD_SANITIZER) | 109 #if !defined(THREAD_SANITIZER) |
| 116 return 0; | 110 return 0; |
| 117 #else | 111 #else |
| 118 // ThreadSanitizer bloats the stack heavily. Evidence has been that the | 112 // ThreadSanitizer bloats the stack heavily. Evidence has been that the |
| 119 // default stack size isn't enough for some browser tests. | 113 // default stack size isn't enough for some browser tests. |
| 120 return 2 * (1 << 23); // 2 times 8192K (the default stack size on Linux). | 114 return 2 * (1 << 23); // 2 times 8192K (the default stack size on Linux). |
| 121 #endif | 115 #endif |
| 122 } | 116 } |
| 123 | 117 |
| 124 } // namespace base | 118 } // namespace base |
| OLD | NEW |