Index: base/task_scheduler/scheduler_worker_thread.h |
diff --git a/base/task_scheduler/scheduler_worker_thread.h b/base/task_scheduler/scheduler_worker_thread.h |
index 912c1c74d6a42c11abd860b3d983f844111b9fac..b153f1dc1e50b4be94cbd6ad29d4ec69f9d83ac9 100644 |
--- a/base/task_scheduler/scheduler_worker_thread.h |
+++ b/base/task_scheduler/scheduler_worker_thread.h |
@@ -10,14 +10,18 @@ |
#include "base/base_export.h" |
#include "base/macros.h" |
#include "base/memory/ref_counted.h" |
+#include "base/single_thread_task_runner.h" |
#include "base/synchronization/waitable_event.h" |
+#include "base/task_scheduler/priority_queue.h" |
#include "base/task_scheduler/scheduler_lock.h" |
+#include "base/task_scheduler/scheduler_task_executor.h" |
#include "base/task_scheduler/sequence.h" |
#include "base/threading/platform_thread.h" |
namespace base { |
namespace internal { |
+class DelayedTaskManager; |
class TaskTracker; |
// A thread that runs Tasks from Sequences returned by a delegate. |
@@ -29,7 +33,8 @@ class TaskTracker; |
// has completed and exits when it has. |
// |
// This class is thread-safe. |
-class BASE_EXPORT SchedulerWorkerThread : public PlatformThread::Delegate { |
+class BASE_EXPORT SchedulerWorkerThread : public PlatformThread::Delegate, |
+ public SchedulerTaskExecutor { |
public: |
// Delegate interface for SchedulerWorkerThread. The methods are always called |
// from the thread managed by the SchedulerWorkerThread instance. |
@@ -41,28 +46,42 @@ class BASE_EXPORT SchedulerWorkerThread : public PlatformThread::Delegate { |
virtual void OnMainEntry() = 0; |
// Called by |worker_thread| to get a Sequence from which to run a Task. |
+ // Sets |is_single_threaded_sequence| to true if the returned Sequence comes |
+ // from |single_threaded_priority_queue|. |
virtual scoped_refptr<Sequence> GetWork( |
- SchedulerWorkerThread* worker_thread) = 0; |
+ SchedulerWorkerThread* worker_thread, |
+ PriorityQueue* single_threaded_priority_queue, |
+ bool* is_single_threaded_sequence) = 0; |
gab
2016/04/18 18:04:02
I don't think the Delegate needs to know that this
fdoray
2016/04/18 19:04:50
Done.
|
- // Called when |sequence| isn't empty after the SchedulerWorkerThread pops a |
- // Task from it. |sequence| is the last Sequence returned by GetWork(). |
+ // Called when a non-single-threaded Sequence returned by GetWork() isn't |
gab
2016/04/18 18:04:02
Idem: re-word without enforcing "single-threaded"
fdoray
2016/04/18 19:04:50
Done.
|
+ // empty after the SchedulerWorkerThread pops a Task from it. |
virtual void EnqueueSequence(scoped_refptr<Sequence> sequence) = 0; |
}; |
// Creates a SchedulerWorkerThread with priority |thread_priority| that runs |
- // Tasks from Sequences returned by |delegate|. |task_tracker| is used to |
- // handle shutdown behavior of Tasks. Returns nullptr if creating the |
- // underlying platform thread fails. |
+ // Tasks from Sequences returned by |delegate|. |task_tracker| handles |
+ // shutdown behavior of Tasks. |delayed_task_manager| handles Tasks posted |
+ // with a delay. |predecessor_priority_queue| is a PriorityQueue for which a |
+ // thread is allowed to have an active Transaction when its creates a |
gab
2016/04/18 18:04:02
s/its creates/it creates/
but also "it" doesn't c
fdoray
2016/04/18 19:04:50
Done.
|
+ // Transaction for this worker thread's single-threaded PriorityQueue. Returns |
+ // nullptr if creating the underlying platform thread fails. |
static std::unique_ptr<SchedulerWorkerThread> CreateSchedulerWorkerThread( |
ThreadPriority thread_priority, |
Delegate* delegate, |
- TaskTracker* task_tracker); |
+ TaskTracker* task_tracker, |
+ DelayedTaskManager* delayed_task_manager, |
+ const PriorityQueue* predecessor_priority_queue); |
// Destroying a SchedulerWorkerThread in production is not allowed; it is |
// always leaked. In tests, it can only be destroyed after JoinForTesting() |
// has returned. |
~SchedulerWorkerThread() override; |
+ // Returns a SingleThreadTaskRunner whose PostTask invocations will result in |
+ // scheduling Tasks with |traits| on this worker thread. |
+ scoped_refptr<SingleThreadTaskRunner> CreateTaskRunnerWithTraits( |
+ const TaskTraits& traits); |
+ |
// Wakes up this SchedulerWorkerThread if it wasn't already awake. After this |
// is called, this SchedulerWorkerThread will run Tasks from Sequences |
// returned by the GetWork() method of its delegate until it returns nullptr. |
@@ -72,10 +91,16 @@ class BASE_EXPORT SchedulerWorkerThread : public PlatformThread::Delegate { |
// allowed to complete its execution. This can only be called once. |
void JoinForTesting(); |
+ // SchedulerTaskExecutor: |
+ void PostTaskWithSequence(std::unique_ptr<Task> task, |
+ scoped_refptr<Sequence> sequence) override; |
+ |
private: |
SchedulerWorkerThread(ThreadPriority thread_priority, |
Delegate* delegate, |
- TaskTracker* task_tracker); |
+ TaskTracker* task_tracker, |
+ DelayedTaskManager* delayed_task_manager, |
+ const PriorityQueue* predecessor_priority_queue); |
// PlatformThread::Delegate: |
void ThreadMain() override; |
@@ -88,8 +113,13 @@ class BASE_EXPORT SchedulerWorkerThread : public PlatformThread::Delegate { |
// Event signaled to wake up this SchedulerWorkerThread. |
WaitableEvent wake_up_event_; |
+ // PriorityQueue for Tasks/Sequences posted through SingleThreadTaskRunners |
+ // returned by CreateTaskRunnerWithTraits. |
+ PriorityQueue single_threaded_priority_queue_; |
+ |
Delegate* const delegate_; |
TaskTracker* const task_tracker_; |
+ DelayedTaskManager* const delayed_task_manager_; |
// Synchronizes access to |should_exit_for_testing_|. |
mutable SchedulerLock should_exit_for_testing_lock_; |