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, ¶m) != 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, ¶m) == 0; |
#endif // defined(WEBRTC_CHROMIUM_BUILD) && defined(WEBRTC_LINUX) |
#endif // defined(WEBRTC_WIN) |
} |