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 if (pthread_setschedparam(pthread_self(), SCHED_RR, &sched_param) == 0) { | |
DaleCurtis
2013/05/28 19:15:25
int res = pthread_setschedparam(pthread_self(), SC
dgreid
2013/05/28 20:29:42
There still needs to be a return in the success pa
| |
87 // Got real time priority, no need to set nice level. | |
88 return; | |
89 } else { | |
90 LOG(INFO) << "Failed to set audio thread to real time"; | |
91 #if defined(OS_CHROMEOS) | |
92 return; // This should always work on ChromeOS, return on error. | |
93 #endif | |
94 } | |
95 } | |
96 | |
79 // setpriority(2) will set a thread's priority if it is passed a tid as | 97 // 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 | 98 // 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 | 99 // process. Setting this priority will only succeed if the user has been |
82 // granted permission to adjust nice values on the system. | 100 // granted permission to adjust nice values on the system. |
83 DCHECK_NE(handle.id_, kInvalidThreadId); | 101 DCHECK_NE(handle.id_, kInvalidThreadId); |
84 int kNiceSetting = ThreadNiceValue(priority); | 102 int kNiceSetting = ThreadNiceValue(priority); |
85 if (setpriority(PRIO_PROCESS, handle.id_, kNiceSetting)) | 103 if (setpriority(PRIO_PROCESS, handle.id_, kNiceSetting)) |
86 LOG(ERROR) << "Failed to set nice value of thread to " << kNiceSetting; | 104 LOG(ERROR) << "Failed to set nice value of thread to " << kNiceSetting; |
87 #endif | 105 #endif |
88 } | 106 } |
89 | 107 |
90 void InitThreading() { | 108 void InitThreading() { |
91 } | 109 } |
92 | 110 |
93 void InitOnThread() { | 111 void InitOnThread() { |
94 } | 112 } |
95 | 113 |
96 void TerminateOnThread() { | 114 void TerminateOnThread() { |
97 } | 115 } |
98 | 116 |
99 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) { | 117 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) { |
100 return 0; | 118 return 0; |
101 } | 119 } |
102 | 120 |
103 } // namespace base | 121 } // namespace base |
OLD | NEW |