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

Unified Diff: base/threading/simple_thread.cc

Issue 1739993004: content: Implement dynamic priorities for raster threads. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: preparing for checkin. Created 4 years, 9 months 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
Index: base/threading/simple_thread.cc
diff --git a/base/threading/simple_thread.cc b/base/threading/simple_thread.cc
index 7059ceab76661428a3a4e9f7eb124e524b162ebe..3e8ff97853657bb7859ca2f2b9522ded0aeb6dce 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.";
@@ -66,6 +75,63 @@ void SimpleThread::ThreadMain() {
Run();
}
+bool SimpleThread::SetThreadPriority(ThreadPriority priority) {
+ DCHECK(HasBeenStarted())
+ << "Tried to set a priority of never-started thread.";
+
+ if (PlatformThread::SetChildThreadPriorityInCurrentProcess(thread_, tid_,
+ priority)) {
+ priority_ = priority;
+ return true;
+ }
+ return false;
+}
+
+// Must have default priority either equal to higher or lower priority.
+DynamicPriorityThread::DynamicPriorityThread(const PrioritySet& priorities,
+ const std::string& name_prefix,
+ const Options& options)
+ : SimpleThread(name_prefix, options),
+ priorities_(priorities),
+ dynamic_priorities_(false),
+ priority_changed_(false) {
+ CHECK(priorities_.higher_priority == priorities_.default_priority ||
+ priorities_.lower_priority == priorities_.default_priority);
+ dynamic_priorities_ =
+ priorities_.higher_priority != priorities_.lower_priority;
+}
+
+bool DynamicPriorityThread::Speedup() {
+ if (dynamic_priorities_ &&
+ (GetThreadPriority() != priorities_.higher_priority)) {
+ SetThreadPriority(priorities_.higher_priority);
+ priority_changed_ = true;
+ return true;
+ }
+ return false;
+}
+
+bool DynamicPriorityThread::Slowdown() {
+ if (dynamic_priorities_ &&
+ (GetThreadPriority() != priorities_.lower_priority)) {
+ SetThreadPriority(priorities_.lower_priority);
+ priority_changed_ = true;
+ return true;
+ }
+ return false;
+}
+
+bool DynamicPriorityThread::RestoreDefaultPriority() {
+ if (dynamic_priorities_ && priority_changed_) {
+ priority_changed_ = false;
+ SetThreadPriority(priorities_.default_priority);
+ // LOG(ERROR) << "\nPRAS:: [" << std::hex << this << "] "
+ // << GetPrioritySetForDebugging() << ". Restored to default.";
+ return true;
+ }
+ return false;
+}
+
DelegateSimpleThread::DelegateSimpleThread(Delegate* delegate,
const std::string& name_prefix)
: SimpleThread(name_prefix),

Powered by Google App Engine
This is Rietveld 408576698