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

Unified 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, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/platform_thread.cc
diff --git a/webrtc/base/platform_thread.cc b/webrtc/base/platform_thread.cc
index d32311bcea3ac0260111f57d9551cc0b75779393..02ec3af29c99b2f652b2d1490b588da5d4e66ecc 100644
--- a/webrtc/base/platform_thread.cc
+++ b/webrtc/base/platform_thread.cc
@@ -100,31 +100,6 @@ struct ThreadAttributes {
pthread_attr_t* operator&() { return &attr; }
pthread_attr_t attr;
};
-
-int ConvertToSystemPriority(ThreadPriority priority,
- int min_prio,
- int max_prio) {
- RTC_DCHECK(max_prio - min_prio > 2);
- const int top_prio = max_prio - 1;
- const int low_prio = min_prio + 1;
-
- switch (priority) {
- case kLowPriority:
- return low_prio;
- case kNormalPriority:
- // The -1 ensures that the kHighPriority is always greater or equal to
- // kNormalPriority.
- return (low_prio + top_prio - 1) / 2;
- case kHighPriority:
- return std::max(top_prio - 2, low_prio);
- case kHighestPriority:
- return std::max(top_prio - 1, low_prio);
- case kRealtimePriority:
- return top_prio;
- }
- RTC_DCHECK(false);
- return low_prio;
-}
#endif // defined(WEBRTC_WIN)
}
@@ -251,13 +226,30 @@ bool PlatformThread::SetPriority(ThreadPriority priority) {
if (max_prio - min_prio <= 2)
return false;
+ // Convert webrtc priority to system priorities:
sched_param param;
- param.sched_priority = ConvertToSystemPriority(priority, min_prio, max_prio);
- if (pthread_setschedparam(thread_, policy, &param) != 0) {
- return false;
+ const int top_prio = max_prio - 1;
+ const int low_prio = min_prio + 1;
+ switch (priority) {
+ case kLowPriority:
+ param.sched_priority = low_prio;
+ break;
+ case kNormalPriority:
+ // The -1 ensures that the kHighPriority is always greater or equal to
+ // kNormalPriority.
+ param.sched_priority = (low_prio + top_prio - 1) / 2;
+ break;
+ case kHighPriority:
+ param.sched_priority = std::max(top_prio - 2, low_prio);
+ break;
+ case kHighestPriority:
+ param.sched_priority = std::max(top_prio - 1, low_prio);
+ break;
+ case kRealtimePriority:
+ param.sched_priority = top_prio;
+ break;
}
-
- return true;
+ return pthread_setschedparam(thread_, policy, &param) == 0;
#endif // defined(WEBRTC_CHROMIUM_BUILD) && defined(WEBRTC_LINUX)
#endif // defined(WEBRTC_WIN)
}
« 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