| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 18 matching lines...) Expand all Loading... |
| 29 #endif | 29 #endif |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = { | 32 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = { |
| 33 {ThreadPriority::BACKGROUND, 10}, | 33 {ThreadPriority::BACKGROUND, 10}, |
| 34 {ThreadPriority::NORMAL, 0}, | 34 {ThreadPriority::NORMAL, 0}, |
| 35 {ThreadPriority::DISPLAY, -6}, | 35 {ThreadPriority::DISPLAY, -6}, |
| 36 {ThreadPriority::REALTIME_AUDIO, -10}, | 36 {ThreadPriority::REALTIME_AUDIO, -10}, |
| 37 } | 37 } |
| 38 | 38 |
| 39 bool SetThreadPriorityForPlatform(PlatformThreadHandle handle, | 39 bool SetCurrentThreadPriorityForPlatform(ThreadPriority priority) { |
| 40 ThreadPriority priority) { | |
| 41 #if !defined(OS_NACL) | 40 #if !defined(OS_NACL) |
| 42 // TODO(gab): Assess the correctness of using |pthread_self()| below instead | |
| 43 // of |handle|. http://crbug.com/468793. | |
| 44 return priority == ThreadPriority::REALTIME_AUDIO && | 41 return priority == ThreadPriority::REALTIME_AUDIO && |
| 45 pthread_setschedparam(pthread_self(), SCHED_RR, &kRealTimePrio) == 0; | 42 pthread_setschedparam(pthread_self(), SCHED_RR, &kRealTimePrio) == 0; |
| 46 #else | 43 #else |
| 47 return false; | 44 return false; |
| 48 #endif | 45 #endif |
| 49 } | 46 } |
| 50 | 47 |
| 51 bool GetThreadPriorityForPlatform(PlatformThreadHandle handle, | 48 bool GetCurrentThreadPriorityForPlatform(ThreadPriority* priority) { |
| 52 ThreadPriority* priority) { | |
| 53 #if !defined(OS_NACL) | 49 #if !defined(OS_NACL) |
| 54 // TODO(gab): Assess the correctness of using |pthread_self()| below instead | |
| 55 // of |handle|. http://crbug.com/468793. | |
| 56 int maybe_sched_rr = 0; | 50 int maybe_sched_rr = 0; |
| 57 struct sched_param maybe_realtime_prio = {0}; | 51 struct sched_param maybe_realtime_prio = {0}; |
| 58 if (pthread_getschedparam(pthread_self(), &maybe_sched_rr, | 52 if (pthread_getschedparam(pthread_self(), &maybe_sched_rr, |
| 59 &maybe_realtime_prio) == 0 && | 53 &maybe_realtime_prio) == 0 && |
| 60 maybe_sched_rr == SCHED_RR && | 54 maybe_sched_rr == SCHED_RR && |
| 61 maybe_realtime_prio.sched_priority == kRealTimePrio.sched_priority) { | 55 maybe_realtime_prio.sched_priority == kRealTimePrio.sched_priority) { |
| 62 *priority = ThreadPriority::REALTIME_AUDIO; | 56 *priority = ThreadPriority::REALTIME_AUDIO; |
| 63 return true; | 57 return true; |
| 64 } | 58 } |
| 65 #endif | 59 #endif |
| (...skipping 28 matching lines...) Expand all Loading... |
| 94 #if !defined(THREAD_SANITIZER) | 88 #if !defined(THREAD_SANITIZER) |
| 95 return 0; | 89 return 0; |
| 96 #else | 90 #else |
| 97 // ThreadSanitizer bloats the stack heavily. Evidence has been that the | 91 // ThreadSanitizer bloats the stack heavily. Evidence has been that the |
| 98 // default stack size isn't enough for some browser tests. | 92 // default stack size isn't enough for some browser tests. |
| 99 return 2 * (1 << 23); // 2 times 8192K (the default stack size on Linux). | 93 return 2 * (1 << 23); // 2 times 8192K (the default stack size on Linux). |
| 100 #endif | 94 #endif |
| 101 } | 95 } |
| 102 | 96 |
| 103 } // namespace base | 97 } // namespace base |
| OLD | NEW |