| 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 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include <unistd.h> | 22 #include <unistd.h> |
| 23 #endif | 23 #endif |
| 24 | 24 |
| 25 namespace base { | 25 namespace base { |
| 26 | 26 |
| 27 namespace internal { | 27 namespace internal { |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 #if !defined(OS_NACL) | 30 #if !defined(OS_NACL) |
| 31 const struct sched_param kRealTimePrio = {8}; | 31 const struct sched_param kRealTimePrio = {8}; |
| 32 const struct sched_param kResetPrio = {0}; | |
| 33 #endif | 32 #endif |
| 34 } // namespace | 33 } // namespace |
| 35 | 34 |
| 36 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = { | 35 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = { |
| 37 {ThreadPriority::BACKGROUND, 10}, | 36 {ThreadPriority::BACKGROUND, 10}, |
| 38 {ThreadPriority::NORMAL, 0}, | 37 {ThreadPriority::NORMAL, 0}, |
| 39 {ThreadPriority::DISPLAY, -6}, | 38 {ThreadPriority::DISPLAY, -6}, |
| 40 {ThreadPriority::REALTIME_AUDIO, -10}, | 39 {ThreadPriority::REALTIME_AUDIO, -10}, |
| 41 }; | 40 }; |
| 42 | 41 |
| 43 bool SetCurrentThreadPriorityForPlatform(ThreadPriority priority) { | 42 bool SetCurrentThreadPriorityForPlatform(ThreadPriority priority) { |
| 44 #if !defined(OS_NACL) | 43 #if !defined(OS_NACL) |
| 45 ThreadPriority current_priority; | 44 return priority == ThreadPriority::REALTIME_AUDIO && |
| 46 if (priority != ThreadPriority::REALTIME_AUDIO && | |
| 47 GetCurrentThreadPriorityForPlatform(¤t_priority) && | |
| 48 current_priority == ThreadPriority::REALTIME_AUDIO) { | |
| 49 // If the pthread's round-robin scheduler is already enabled, and the new | |
| 50 // priority will use setpriority() instead, the pthread scheduler should be | |
| 51 // reset to use SCHED_OTHER so that setpriority() just works. | |
| 52 pthread_setschedparam(pthread_self(), SCHED_OTHER, &kResetPrio); | |
| 53 return false; | |
| 54 } | |
| 55 return priority == ThreadPriority::REALTIME_AUDIO && | |
| 56 pthread_setschedparam(pthread_self(), SCHED_RR, &kRealTimePrio) == 0; | 45 pthread_setschedparam(pthread_self(), SCHED_RR, &kRealTimePrio) == 0; |
| 57 #else | 46 #else |
| 58 return false; | 47 return false; |
| 59 #endif | 48 #endif |
| 60 } | 49 } |
| 61 | 50 |
| 62 bool GetCurrentThreadPriorityForPlatform(ThreadPriority* priority) { | 51 bool GetCurrentThreadPriorityForPlatform(ThreadPriority* priority) { |
| 63 #if !defined(OS_NACL) | 52 #if !defined(OS_NACL) |
| 64 int maybe_sched_rr = 0; | 53 int maybe_sched_rr = 0; |
| 65 struct sched_param maybe_realtime_prio = {0}; | 54 struct sched_param maybe_realtime_prio = {0}; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 96 // that it can set the name of threads other than the current thread. | 85 // that it can set the name of threads other than the current thread. |
| 97 int err = prctl(PR_SET_NAME, name.c_str()); | 86 int err = prctl(PR_SET_NAME, name.c_str()); |
| 98 // We expect EPERM failures in sandboxed processes, just ignore those. | 87 // We expect EPERM failures in sandboxed processes, just ignore those. |
| 99 if (err < 0 && errno != EPERM) | 88 if (err < 0 && errno != EPERM) |
| 100 DPLOG(ERROR) << "prctl(PR_SET_NAME)"; | 89 DPLOG(ERROR) << "prctl(PR_SET_NAME)"; |
| 101 #endif // !defined(OS_NACL) | 90 #endif // !defined(OS_NACL) |
| 102 } | 91 } |
| 103 | 92 |
| 104 void InitThreading() {} | 93 void InitThreading() {} |
| 105 | 94 |
| 106 void InitOnThread() {} | |
| 107 | |
| 108 void TerminateOnThread() {} | 95 void TerminateOnThread() {} |
| 109 | 96 |
| 110 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) { | 97 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) { |
| 111 #if !defined(THREAD_SANITIZER) | 98 #if !defined(THREAD_SANITIZER) |
| 112 return 0; | 99 return 0; |
| 113 #else | 100 #else |
| 114 // ThreadSanitizer bloats the stack heavily. Evidence has been that the | 101 // ThreadSanitizer bloats the stack heavily. Evidence has been that the |
| 115 // default stack size isn't enough for some browser tests. | 102 // default stack size isn't enough for some browser tests. |
| 116 return 2 * (1 << 23); // 2 times 8192K (the default stack size on Linux). | 103 return 2 * (1 << 23); // 2 times 8192K (the default stack size on Linux). |
| 117 #endif | 104 #endif |
| 118 } | 105 } |
| 119 | 106 |
| 120 } // namespace base | 107 } // namespace base |
| OLD | NEW |