| Index: base/threading/simple_thread.cc
|
| diff --git a/base/threading/simple_thread.cc b/base/threading/simple_thread.cc
|
| index 7059ceab76661428a3a4e9f7eb124e524b162ebe..7496962d099f5e8eafa4d6ffbee7a587449e14ca 100644
|
| --- a/base/threading/simple_thread.cc
|
| +++ b/base/threading/simple_thread.cc
|
| @@ -12,15 +12,24 @@
|
| namespace base {
|
|
|
| SimpleThread::SimpleThread(const std::string& name_prefix)
|
| - : name_prefix_(name_prefix), name_(name_prefix),
|
| - thread_(), event_(true, false), tid_(0), joined_(false) {
|
| -}
|
| + : name_prefix_(name_prefix),
|
| + name_(name_prefix),
|
| + thread_(),
|
| + event_(true, false),
|
| + tid_(0),
|
| + joined_(false),
|
| + priority_(options_.priority()) {}
|
|
|
| SimpleThread::SimpleThread(const std::string& name_prefix,
|
| const Options& options)
|
| - : name_prefix_(name_prefix), name_(name_prefix), options_(options),
|
| - thread_(), event_(true, false), tid_(0), joined_(false) {
|
| -}
|
| + : name_prefix_(name_prefix),
|
| + name_(name_prefix),
|
| + options_(options),
|
| + thread_(),
|
| + event_(true, false),
|
| + tid_(0),
|
| + joined_(false),
|
| + priority_(options_.priority()) {}
|
|
|
| SimpleThread::~SimpleThread() {
|
| DCHECK(HasBeenStarted()) << "SimpleThread was never started.";
|
| @@ -41,6 +50,14 @@ void SimpleThread::Start() {
|
| event_.Wait(); // Wait for the thread to complete initialization.
|
| }
|
|
|
| +bool SimpleThread::SetThreadPriority(ThreadPriority priority) {
|
| + if (PlatformThread::SetThreadPriority(tid_, priority)) {
|
| + priority_ = priority;
|
| + return true;
|
| + }
|
| + return false;
|
| +}
|
| +
|
| void SimpleThread::Join() {
|
| DCHECK(HasBeenStarted()) << "Tried to Join a never-started thread.";
|
| DCHECK(!HasBeenJoined()) << "Tried to Join a thread multiple times.";
|
| @@ -66,6 +83,82 @@ void SimpleThread::ThreadMain() {
|
| Run();
|
| }
|
|
|
| +TestSimpleThread::TestSimpleThread(const PrioritySet& priorities,
|
| + const std::string& name_prefix,
|
| + const Options& options)
|
| + : SimpleThread(name_prefix, options),
|
| + priorities_(priorities),
|
| + dynamic_prio_(false),
|
| + changed_(false) {
|
| + CHECK(priorities_.high_prio == priorities_.default_prio ||
|
| + priorities_.low_prio == priorities_.default_prio);
|
| + dynamic_prio_ = priorities_.high_prio != priorities_.low_prio;
|
| +}
|
| +
|
| +bool TestSimpleThread::Speedup() {
|
| + if (dynamic_prio_ && (GetThreadPriority() != priorities_.high_prio)) {
|
| + SetThreadPriority(priorities_.high_prio);
|
| + changed_ = true;
|
| + return true;
|
| + }
|
| + return false;
|
| +}
|
| +
|
| +bool TestSimpleThread::Slowdown() {
|
| + if (dynamic_prio_ && (GetThreadPriority() != priorities_.low_prio)) {
|
| + SetThreadPriority(priorities_.low_prio);
|
| + changed_ = true;
|
| + return true;
|
| + }
|
| + return false;
|
| +}
|
| +
|
| +bool TestSimpleThread::Restore() {
|
| + if (dynamic_prio_ && changed_) {
|
| + changed_ = false;
|
| + SetThreadPriority(priorities_.default_prio);
|
| + // LOG(ERROR) << "\nPRAS:: [" << std::hex << this << "] "
|
| + // << GetPrioritySetForDebugging() << ". Restored to default.";
|
| + return true;
|
| + }
|
| + return false;
|
| +}
|
| +
|
| +std::string GetPriorityString(ThreadPriority prio) {
|
| + std::string str;
|
| + if (prio == base::ThreadPriority::BACKGROUND)
|
| + str = "background";
|
| + else if (prio == base::ThreadPriority::NORMAL)
|
| + str = "normal";
|
| + else if (prio == base::ThreadPriority::DISPLAY)
|
| + str = "display";
|
| + else if (prio == base::ThreadPriority::REALTIME_AUDIO)
|
| + str = "audio";
|
| + else
|
| + str = "WRONG";
|
| +
|
| + return str;
|
| +}
|
| +
|
| +std::string TestSimpleThread::GetPrioritySetForDebugging() {
|
| + static bool once = true;
|
| +
|
| + if (once) {
|
| + std::ostringstream stream;
|
| + stream << "{ Default = " << GetPriorityString(priorities_.default_prio)
|
| + << ", Low = " << GetPriorityString(priorities_.low_prio)
|
| + << ", High = " << GetPriorityString(priorities_.high_prio) << "}";
|
| + priorities_str_ = stream.str();
|
| + }
|
| +
|
| + std::string str = "Current = ";
|
| + str += GetPriorityString(GetThreadPriority());
|
| + str += ", ";
|
| + str += priorities_str_;
|
| +
|
| + return str;
|
| +}
|
| +
|
| DelegateSimpleThread::DelegateSimpleThread(Delegate* delegate,
|
| const std::string& name_prefix)
|
| : SimpleThread(name_prefix),
|
|
|