Index: base/threading/simple_thread.h |
diff --git a/base/threading/simple_thread.h b/base/threading/simple_thread.h |
index 3deeb1018cb573c3f5e48d2b17b7c16a428aa476..cedd3042795a54a59dfa8dccbef712fc618629e7 100644 |
--- a/base/threading/simple_thread.h |
+++ b/base/threading/simple_thread.h |
@@ -112,6 +112,12 @@ class BASE_EXPORT SimpleThread : public PlatformThread::Delegate { |
// Overridden from PlatformThread::Delegate: |
void ThreadMain() override; |
+ // Set the priority of this thread. |
+ bool SetThreadPriority(ThreadPriority priority); |
+ |
+ // Get the priority of this thread. |
+ ThreadPriority GetThreadPriority() { return priority_; } |
+ |
private: |
const std::string name_prefix_; |
std::string name_; |
@@ -120,6 +126,46 @@ class BASE_EXPORT SimpleThread : public PlatformThread::Delegate { |
WaitableEvent event_; // Signaled if Start() was ever called. |
PlatformThreadId tid_; // The backing thread's id. |
bool joined_; // True if Join has been called. |
+ ThreadPriority priority_; // Stores currently set priority. |
+}; |
+ |
+// This class creates a simple thread with capability of changing priority |
+// when it is scheduled. Thread starts with |default_priority| from |
+// |priorities_| and it must be started to change the priority. |
+class BASE_EXPORT DynamicPriorityThread : public SimpleThread { |
+ public: |
+ struct BASE_EXPORT PrioritySet { |
+ explicit PrioritySet(const ThreadPriority default_prio, |
+ const ThreadPriority lower_prio, |
+ const ThreadPriority higher_prio) |
+ : default_priority(default_prio), |
+ lower_priority(lower_prio), |
+ higher_priority(higher_prio) {} |
+ const ThreadPriority default_priority; |
+ const ThreadPriority lower_priority; |
+ const ThreadPriority higher_priority; |
+ }; |
+ |
+ explicit DynamicPriorityThread(const PrioritySet& priorities, |
+ const std::string& name_prefix, |
+ const Options& options); |
+ |
+ // Sets higher priority from |priorities_|. |
+ bool Speedup(); |
+ // Sets lower priority from |priorities_|. |
+ bool Slowdown(); |
+ // Sets default priority from |priorities_|. |
+ bool RestoreDefaultPriority(); |
+ |
+ // Returns true if thread is having lower and higher priorities different. |
+ bool HasDynamicPriorities() { return dynamic_priorities_; } |
+ |
+ ThreadPriority GetDefaultPriority() { return priorities_.default_priority; } |
+ |
+ private: |
+ const PrioritySet priorities_; |
+ bool dynamic_priorities_; |
+ bool priority_changed_; |
}; |
class BASE_EXPORT DelegateSimpleThread : public SimpleThread { |