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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 int err = prctl(PR_SET_NAME, name); | 68 int err = prctl(PR_SET_NAME, name); |
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 #if !defined(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) { |
| 87 // Got real time priority, no need to set nice level. |
| 88 return; |
| 89 } |
| 90 } |
| 91 |
79 // setpriority(2) will set a thread's priority if it is passed a tid as | 92 // 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 | 93 // 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 | 94 // process. Setting this priority will only succeed if the user has been |
82 // granted permission to adjust nice values on the system. | 95 // granted permission to adjust nice values on the system. |
83 DCHECK_NE(handle.id_, kInvalidThreadId); | 96 DCHECK_NE(handle.id_, kInvalidThreadId); |
84 int kNiceSetting = ThreadNiceValue(priority); | 97 int kNiceSetting = ThreadNiceValue(priority); |
85 if (setpriority(PRIO_PROCESS, handle.id_, kNiceSetting)) | 98 if (setpriority(PRIO_PROCESS, handle.id_, kNiceSetting)) |
86 LOG(ERROR) << "Failed to set nice value of thread to " << kNiceSetting; | 99 LOG(ERROR) << "Failed to set nice value of thread to " << kNiceSetting; |
87 #endif | 100 #endif // !OS_NACL |
88 } | 101 } |
89 | 102 |
90 void InitThreading() { | 103 void InitThreading() { |
91 } | 104 } |
92 | 105 |
93 void InitOnThread() { | 106 void InitOnThread() { |
94 } | 107 } |
95 | 108 |
96 void TerminateOnThread() { | 109 void TerminateOnThread() { |
97 } | 110 } |
98 | 111 |
99 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) { | 112 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) { |
100 return 0; | 113 return 0; |
101 } | 114 } |
102 | 115 |
103 } // namespace base | 116 } // namespace base |
OLD | NEW |