Set thread scheduling parameters inside the new thread.
This makes it possible to restrict threads from modifying scheduling parameters of another thread in the Chrome Linux sandbox. BUG= R=henrike@webrtc.org Review URL: https://webrtc-codereview.appspot.com/28539004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7324 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@ -178,11 +178,6 @@ bool ThreadPosix::Start(unsigned int& thread_id)
|
|||||||
int result = pthread_attr_setdetachstate(&attr_, PTHREAD_CREATE_DETACHED);
|
int result = pthread_attr_setdetachstate(&attr_, PTHREAD_CREATE_DETACHED);
|
||||||
// Set the stack stack size to 1M.
|
// Set the stack stack size to 1M.
|
||||||
result |= pthread_attr_setstacksize(&attr_, 1024 * 1024);
|
result |= pthread_attr_setstacksize(&attr_, 1024 * 1024);
|
||||||
#ifdef WEBRTC_THREAD_RR
|
|
||||||
const int policy = SCHED_RR;
|
|
||||||
#else
|
|
||||||
const int policy = SCHED_FIFO;
|
|
||||||
#endif
|
|
||||||
event_->Reset();
|
event_->Reset();
|
||||||
// If pthread_create was successful, a thread was created and is running.
|
// If pthread_create was successful, a thread was created and is running.
|
||||||
// Don't return false if it was successful since if there are any other
|
// Don't return false if it was successful since if there are any other
|
||||||
@ -210,26 +205,6 @@ bool ThreadPosix::Start(unsigned int& thread_id)
|
|||||||
#if HAS_THREAD_ID
|
#if HAS_THREAD_ID
|
||||||
thread_id = static_cast<unsigned int>(thread_);
|
thread_id = static_cast<unsigned int>(thread_);
|
||||||
#endif
|
#endif
|
||||||
sched_param param;
|
|
||||||
|
|
||||||
const int min_prio = sched_get_priority_min(policy);
|
|
||||||
const int max_prio = sched_get_priority_max(policy);
|
|
||||||
|
|
||||||
if ((min_prio == EINVAL) || (max_prio == EINVAL)) {
|
|
||||||
WEBRTC_TRACE(kTraceError, kTraceUtility, -1,
|
|
||||||
"unable to retreive min or max priority for threads");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (max_prio - min_prio <= 2) {
|
|
||||||
// There is no room for setting priorities with any granularity.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
param.sched_priority = ConvertToSystemPriority(prio_, min_prio, max_prio);
|
|
||||||
result = pthread_setschedparam(thread_, policy, ¶m);
|
|
||||||
if (result == EINVAL) {
|
|
||||||
WEBRTC_TRACE(kTraceError, kTraceUtility, -1,
|
|
||||||
"unable to set thread priority");
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,6 +301,27 @@ void ThreadPosix::Run() {
|
|||||||
WEBRTC_TRACE(kTraceStateInfo, kTraceUtility, -1,
|
WEBRTC_TRACE(kTraceStateInfo, kTraceUtility, -1,
|
||||||
"Thread without name started");
|
"Thread without name started");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool alive = true;
|
bool alive = true;
|
||||||
bool run = true;
|
bool run = true;
|
||||||
while (alive) {
|
while (alive) {
|
||||||
|
Reference in New Issue
Block a user