- Add a SetPriority method to ThreadWrapper
- Remove 'priority' from CreateThread and related member variables from implementations
- Make supplying a name for threads, non-optional
BUG=
R=magjed@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/44729004
Cr-Commit-Position: refs/heads/master@{#8810}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8810 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/system_wrappers/source/thread_posix.cc b/webrtc/system_wrappers/source/thread_posix.cc
index c605411..dc95cbc 100644
--- a/webrtc/system_wrappers/source/thread_posix.cc
+++ b/webrtc/system_wrappers/source/thread_posix.cc
@@ -69,10 +69,9 @@
}
ThreadPosix::ThreadPosix(ThreadRunFunction func, void* obj,
- ThreadPriority prio, const char* thread_name)
+ const char* thread_name)
: run_function_(func),
obj_(obj),
- prio_(prio),
stop_event_(false, false),
name_(thread_name ? thread_name : "webrtc"),
thread_(0) {
@@ -112,6 +111,38 @@
return true;
}
+bool ThreadPosix::SetPriority(ThreadPriority priority) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (!thread_)
+ return false;
+
+#ifdef WEBRTC_THREAD_RR
+ const int policy = SCHED_RR;
+#else
+ const int policy = SCHED_FIFO;
+#endif
+ const int min_prio = sched_get_priority_min(policy);
+ const int max_prio = sched_get_priority_max(policy);
+ if (min_prio == -1 || max_prio == -1) {
+ WEBRTC_TRACE(kTraceError, kTraceUtility, -1,
+ "unable to retreive min or max priority for threads");
+ return false;
+ }
+
+ if (max_prio - min_prio <= 2)
+ return false;
+
+ sched_param param;
+ param.sched_priority = ConvertToSystemPriority(priority, min_prio, max_prio);
+ if (pthread_setschedparam(thread_, policy, ¶m) != 0) {
+ WEBRTC_TRACE(
+ kTraceError, kTraceUtility, -1, "unable to set thread priority");
+ return false;
+ }
+
+ return true;
+}
+
void ThreadPosix::Run() {
if (!name_.empty()) {
// Setting the thread name may fail (harmlessly) if running inside a
@@ -123,27 +154,6 @@
#endif
}
-#ifdef WEBRTC_THREAD_RR
- const int policy = SCHED_RR;
-#else
- const int policy = SCHED_FIFO;
-#endif
- const int min_prio = sched_get_priority_min(policy);
- const int max_prio = sched_get_priority_max(policy);
- if ((min_prio == -1) || (max_prio == -1)) {
- WEBRTC_TRACE(kTraceError, kTraceUtility, -1,
- "unable to retreive min or max priority for threads");
- }
-
- if (max_prio - min_prio > 2) {
- sched_param param;
- param.sched_priority = ConvertToSystemPriority(prio_, min_prio, max_prio);
- if (pthread_setschedparam(pthread_self(), policy, ¶m) != 0) {
- WEBRTC_TRACE(
- kTraceError, kTraceUtility, -1, "unable to set thread priority");
- }
- }
-
// It's a requirement that for successful thread creation that the run
// function be called at least once (see RunFunctionIsCalled unit test),
// so to fullfill that requirement, we use a |do| loop and not |while|.