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

Unified Diff: content/renderer/scheduler/task_queue_manager.h

Issue 637303003: content: Add task queue manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Carlos's comments. Created 6 years, 2 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
« no previous file with comments | « content/content_tests.gypi ('k') | content/renderer/scheduler/task_queue_manager.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/scheduler/task_queue_manager.h
diff --git a/content/renderer/scheduler/task_queue_manager.h b/content/renderer/scheduler/task_queue_manager.h
new file mode 100644
index 0000000000000000000000000000000000000000..eba6ccc7ea86f050c97dd25a8f573d1e810233a2
--- /dev/null
+++ b/content/renderer/scheduler/task_queue_manager.h
@@ -0,0 +1,123 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_
+#define CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_
+
+#include "base/atomic_sequence_num.h"
+#include "base/debug/task_annotator.h"
+#include "base/macros.h"
+#include "base/memory/scoped_vector.h"
+#include "base/memory/weak_ptr.h"
+#include "base/pending_task.h"
+#include "base/single_thread_task_runner.h"
+#include "base/synchronization/lock.h"
+#include "base/threading/thread_checker.h"
+#include "content/common/content_export.h"
+
+namespace content {
+namespace internal {
+class TaskRunner;
+struct TaskQueue;
+}
+class TaskQueueSelector;
+
+// The task queue manager provides N task queues and a selector interface for
+// choosing which task queue to service next. Each task queue consists of two
+// sub queues:
+//
+// 1. Incoming task queue. Tasks that are posted get immediately appended here.
+// When a task is appended into an empty incoming queue, the task manager
+// work function (DoWork) is scheduled to run on the main task runner.
+//
+// 2. Work queue. If a work queue is empty when DoWork() is entered, tasks from
+// the incoming task queue (if any) are moved here. The work queues are
+// registered with the selector as input to the scheduling decision.
+//
+class CONTENT_EXPORT TaskQueueManager {
+ public:
+ // Create a task queue manager with |task_queue_count| task queues.
+ // |main_task_runner| identifies the thread on which where the tasks are
+ // eventually run. |selector| is used to choose which task queue to service.
+ // It should outlive this class.
+ TaskQueueManager(size_t task_queue_count,
+ scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
+ TaskQueueSelector* selector);
+ ~TaskQueueManager();
+
+ // Returns the task runner which targets the queue selected by |queue_index|.
+ scoped_refptr<base::SingleThreadTaskRunner> TaskRunnerForQueue(
+ size_t queue_index) const;
+
+ // If |auto_pump| is false, tasks posted to the given incoming queue will not
+ // be automatically scheduled for execution or transferred to the work queue.
+ // Instead, the selector should call PumpQueue() when necessary to bring in
+ // new tasks for execution.
+ void SetAutoPump(size_t queue_index, bool auto_pump);
+
+ // Reloads new tasks from the incoming queue for |queue_index| into the work
+ // queue, regardless of whether the work queue is empty or not. After this,
+ // this function ensures that the tasks in the work queue, if any, are
+ // scheduled for execution.
+ //
+ // This function only needs to be called if automatic pumping is disabled
+ // for |queue_index|. See |SetQueueAutoPump|. By default automatic pumping is
+ // enabled for all queues.
+ void PumpQueue(size_t queue_index);
+
+ // Returns true if there no tasks in either the work or incoming task queue
+ // identified by |queue_index|. Note that this function involves taking a
+ // lock, so calling it has some overhead.
+ bool IsQueueEmpty(size_t queue_index);
+
+ private:
+ friend class internal::TaskRunner;
+
+ // Adds a task at the end of the incoming task queue for |queue_index| and
+ // schedules a call to DoWork() if the incoming queue was empty and automatic
+ // pumping is enabled. Can be called on an arbitrary thread.
+ void EnqueueTask(size_t queue_index, const base::PendingTask& pending_task);
+
+ // Post a task to call DoWork() on the main task runner.
+ void PostDoWorkOnMainRunner();
+
+ // Use the selector to choose a pending task and run it.
+ void DoWork();
+
+ // Reloads any empty work queues which have automatic pumping enabled.
+ // Returns true if any work queue has tasks after doing this.
+ bool UpdateWorkQueues();
+
+ // Runs a single task from the work queue designated by |queue_index|. The
+ // queue must not be empty.
+ void RunTaskFromWorkQueue(size_t queue_index);
+
+ bool RunsTasksOnCurrentThread() const;
+ bool PostDelayedTask(size_t queue_index,
+ const tracked_objects::Location& from_here,
+ const base::Closure& task,
+ base::TimeDelta delay);
+ bool PostNonNestableDelayedTask(size_t queue_index,
+ const tracked_objects::Location& from_here,
+ const base::Closure& task,
+ base::TimeDelta delay);
+ internal::TaskQueue* Queue(size_t queue_index) const;
jar (doing other things) 2014/10/29 21:14:07 I found this declaration, and its use, but didn't
Sami 2014/10/30 10:43:00 It's at line 113 of task_queue_manager.cc in this
+ void PumpQueueLocked(internal::TaskQueue* queue);
+
+ ScopedVector<internal::TaskQueue> queues_;
+ base::AtomicSequenceNumber task_sequence_num_;
+ base::debug::TaskAnnotator task_annotator_;
+
+ base::ThreadChecker main_thread_checker_;
+ scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
+ TaskQueueSelector* selector_;
+
+ base::WeakPtrFactory<TaskQueueManager> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(TaskQueueManager);
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_
« no previous file with comments | « content/content_tests.gypi ('k') | content/renderer/scheduler/task_queue_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698