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

Unified Diff: base/task_scheduler/scheduler_worker_thread.h

Issue 1876363004: TaskScheduler [11] Support ExecutionMode::SINGLE_THREADED. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@8_delayed
Patch Set: rebase Created 4 years, 8 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/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..6721309180ca56ae0fdb26b4cff7a6989f77b3e9 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,43 @@ 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.
+ // |alternate_priority_queue| will be considered as an alternate source of
+ // work. |alternate_priority_queue_used| is set to true if the returned
+ // Sequence was selected from it.
virtual scoped_refptr<Sequence> GetWork(
- SchedulerWorkerThread* worker_thread) = 0;
+ SchedulerWorkerThread* worker_thread,
+ PriorityQueue* alternate_priority_queue,
+ bool* alternate_priority_queue_used) = 0;
- // 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 Sequence returned by GetWork() that wasn't selected from
+ // the alternate priority queue isn't 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 whose
+ // transactions may overlap this thread's PriorityQueue's transactions.
+ // 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 +92,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 +114,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_;

Powered by Google App Engine
This is Rietveld 408576698