Chromium Code Reviews| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 // We expect EPERM failures in sandboxed processes, just ignore those. | 69 // We expect EPERM failures in sandboxed processes, just ignore those. |
| 70 if (err < 0 && errno != EPERM) | 70 if (err < 0 && errno != EPERM) |
| 71 DPLOG(ERROR) << "prctl(PR_SET_NAME)"; | 71 DPLOG(ERROR) << "prctl(PR_SET_NAME)"; |
| 72 #endif | 72 #endif |
| 73 } | 73 } |
| 74 | 74 |
| 75 // static | 75 // static |
| 76 void PlatformThread::SetThreadPriority(PlatformThreadHandle handle, | 76 void PlatformThread::SetThreadPriority(PlatformThreadHandle handle, |
| 77 ThreadPriority priority) { | 77 ThreadPriority priority) { |
| 78 #ifndef OS_NACL | 78 #ifndef OS_NACL |
| 79 if (priority == kThreadPriority_RealtimeAudio) { | |
| 80 const int kRealTimePrio = 8; | |
| 81 | |
| 82 struct sched_param sched_param; | |
| 83 memset(&sched_param, 0, sizeof(sched_param)); | |
| 84 sched_param.sched_priority = kRealTimePrio; | |
| 85 | |
| 86 int res = pthread_setschedparam(pthread_self(), SCHED_RR, &sched_param); | |
| 87 if (res == 0) | |
| 88 // Got real time priority, no need to set nice level. | |
| 89 return; | |
|
piman
2013/05/28 21:58:56
nit: need braces if the clause takes multiple line
dgreid
2013/05/28 22:18:53
Done.
| |
| 90 else | |
| 91 LOG(INFO) << "Failed to set audio thread to real time."; | |
| 92 | |
| 93 #if defined(OS_CHROMEOS) | |
| 94 DCHECK_EQ(res, 0); // RT prio should always work on ChromeOS. | |
|
piman
2013/05/28 21:58:56
This prevents debugging chromeos=1 builds on the d
dgreid
2013/05/28 22:18:53
Good point, switched this back to a return.
| |
| 95 #endif | |
| 96 } | |
| 97 | |
| 79 // setpriority(2) will set a thread's priority if it is passed a tid as | 98 // setpriority(2) will set a thread's priority if it is passed a tid as |
| 80 // the 'process identifier', not affecting the rest of the threads in the | 99 // the 'process identifier', not affecting the rest of the threads in the |
| 81 // process. Setting this priority will only succeed if the user has been | 100 // process. Setting this priority will only succeed if the user has been |
| 82 // granted permission to adjust nice values on the system. | 101 // granted permission to adjust nice values on the system. |
| 83 DCHECK_NE(handle.id_, kInvalidThreadId); | 102 DCHECK_NE(handle.id_, kInvalidThreadId); |
| 84 int kNiceSetting = ThreadNiceValue(priority); | 103 int kNiceSetting = ThreadNiceValue(priority); |
| 85 if (setpriority(PRIO_PROCESS, handle.id_, kNiceSetting)) | 104 if (setpriority(PRIO_PROCESS, handle.id_, kNiceSetting)) |
| 86 LOG(ERROR) << "Failed to set nice value of thread to " << kNiceSetting; | 105 LOG(ERROR) << "Failed to set nice value of thread to " << kNiceSetting; |
| 87 #endif | 106 #endif |
| 88 } | 107 } |
| 89 | 108 |
| 90 void InitThreading() { | 109 void InitThreading() { |
| 91 } | 110 } |
| 92 | 111 |
| 93 void InitOnThread() { | 112 void InitOnThread() { |
| 94 } | 113 } |
| 95 | 114 |
| 96 void TerminateOnThread() { | 115 void TerminateOnThread() { |
| 97 } | 116 } |
| 98 | 117 |
| 99 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) { | 118 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) { |
| 100 return 0; | 119 return 0; |
| 101 } | 120 } |
| 102 | 121 |
| 103 } // namespace base | 122 } // namespace base |
| OLD | NEW |