Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: webrtc/base/platform_thread.cc

Issue 1471073005: Inline ConvertToSystemPriority. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: inline ConvertToSystemPriority Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 void CALLBACK RaiseFlag(ULONG_PTR param) { 93 void CALLBACK RaiseFlag(ULONG_PTR param) {
94 *reinterpret_cast<bool*>(param) = true; 94 *reinterpret_cast<bool*>(param) = true;
95 } 95 }
96 #else 96 #else
97 struct ThreadAttributes { 97 struct ThreadAttributes {
98 ThreadAttributes() { pthread_attr_init(&attr); } 98 ThreadAttributes() { pthread_attr_init(&attr); }
99 ~ThreadAttributes() { pthread_attr_destroy(&attr); } 99 ~ThreadAttributes() { pthread_attr_destroy(&attr); }
100 pthread_attr_t* operator&() { return &attr; } 100 pthread_attr_t* operator&() { return &attr; }
101 pthread_attr_t attr; 101 pthread_attr_t attr;
102 }; 102 };
103
104 int ConvertToSystemPriority(ThreadPriority priority,
105 int min_prio,
106 int max_prio) {
107 RTC_DCHECK(max_prio - min_prio > 2);
108 const int top_prio = max_prio - 1;
109 const int low_prio = min_prio + 1;
110
111 switch (priority) {
112 case kLowPriority:
113 return low_prio;
114 case kNormalPriority:
115 // The -1 ensures that the kHighPriority is always greater or equal to
116 // kNormalPriority.
117 return (low_prio + top_prio - 1) / 2;
118 case kHighPriority:
119 return std::max(top_prio - 2, low_prio);
120 case kHighestPriority:
121 return std::max(top_prio - 1, low_prio);
122 case kRealtimePriority:
123 return top_prio;
124 }
125 RTC_DCHECK(false);
126 return low_prio;
127 }
128 #endif // defined(WEBRTC_WIN) 103 #endif // defined(WEBRTC_WIN)
129 } 104 }
130 105
131 PlatformThread::PlatformThread(ThreadRunFunction func, 106 PlatformThread::PlatformThread(ThreadRunFunction func,
132 void* obj, 107 void* obj,
133 const char* thread_name) 108 const char* thread_name)
134 : run_function_(func), 109 : run_function_(func),
135 obj_(obj), 110 obj_(obj),
136 name_(thread_name ? thread_name : "webrtc"), 111 name_(thread_name ? thread_name : "webrtc"),
137 #if defined(WEBRTC_WIN) 112 #if defined(WEBRTC_WIN)
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 #endif 219 #endif
245 const int min_prio = sched_get_priority_min(policy); 220 const int min_prio = sched_get_priority_min(policy);
246 const int max_prio = sched_get_priority_max(policy); 221 const int max_prio = sched_get_priority_max(policy);
247 if (min_prio == -1 || max_prio == -1) { 222 if (min_prio == -1 || max_prio == -1) {
248 return false; 223 return false;
249 } 224 }
250 225
251 if (max_prio - min_prio <= 2) 226 if (max_prio - min_prio <= 2)
252 return false; 227 return false;
253 228
229 // Convert webrtc priority to system priorities:
254 sched_param param; 230 sched_param param;
255 param.sched_priority = ConvertToSystemPriority(priority, min_prio, max_prio); 231 const int top_prio = max_prio - 1;
256 if (pthread_setschedparam(thread_, policy, &param) != 0) { 232 const int low_prio = min_prio + 1;
257 return false; 233 switch (priority) {
234 case kLowPriority:
235 param.sched_priority = low_prio;
236 break;
237 case kNormalPriority:
238 // The -1 ensures that the kHighPriority is always greater or equal to
239 // kNormalPriority.
240 param.sched_priority = (low_prio + top_prio - 1) / 2;
241 break;
242 case kHighPriority:
243 param.sched_priority = std::max(top_prio - 2, low_prio);
244 break;
245 case kHighestPriority:
246 param.sched_priority = std::max(top_prio - 1, low_prio);
247 break;
248 case kRealtimePriority:
249 param.sched_priority = top_prio;
250 break;
258 } 251 }
259 252 return pthread_setschedparam(thread_, policy, &param) == 0;
260 return true;
261 #endif // defined(WEBRTC_CHROMIUM_BUILD) && defined(WEBRTC_LINUX) 253 #endif // defined(WEBRTC_CHROMIUM_BUILD) && defined(WEBRTC_LINUX)
262 #endif // defined(WEBRTC_WIN) 254 #endif // defined(WEBRTC_WIN)
263 } 255 }
264 256
265 } // namespace webrtc 257 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698