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

Side by Side Diff: content/renderer/scheduler/task_queue_manager.h

Issue 681793003: scheduler: Add support for tracing scheduler state (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test. Created 6 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ 5 #ifndef CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_
6 #define CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ 6 #define CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_
7 7
8 #include "base/atomic_sequence_num.h" 8 #include "base/atomic_sequence_num.h"
9 #include "base/debug/task_annotator.h" 9 #include "base/debug/task_annotator.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/pending_task.h" 12 #include "base/pending_task.h"
13 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
14 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
15 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
16 #include "content/common/content_export.h" 16 #include "content/common/content_export.h"
17 17
18 namespace base {
19 namespace debug {
20 class ConvertableToTraceFormat;
21 class TracedValue;
22 }
23 }
24
18 namespace content { 25 namespace content {
19 namespace internal { 26 namespace internal {
20 class TaskQueue; 27 class TaskQueue;
21 } 28 }
22 class TaskQueueSelector; 29 class TaskQueueSelector;
23 30
24 // The task queue manager provides N task queues and a selector interface for 31 // The task queue manager provides N task queues and a selector interface for
25 // choosing which task queue to service next. Each task queue consists of two 32 // choosing which task queue to service next. Each task queue consists of two
26 // sub queues: 33 // sub queues:
27 // 34 //
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 // This function only needs to be called if automatic pumping is disabled 69 // This function only needs to be called if automatic pumping is disabled
63 // for |queue_index|. See |SetQueueAutoPump|. By default automatic pumping is 70 // for |queue_index|. See |SetQueueAutoPump|. By default automatic pumping is
64 // enabled for all queues. 71 // enabled for all queues.
65 void PumpQueue(size_t queue_index); 72 void PumpQueue(size_t queue_index);
66 73
67 // Returns true if there no tasks in either the work or incoming task queue 74 // Returns true if there no tasks in either the work or incoming task queue
68 // identified by |queue_index|. Note that this function involves taking a 75 // identified by |queue_index|. Note that this function involves taking a
69 // lock, so calling it has some overhead. 76 // lock, so calling it has some overhead.
70 bool IsQueueEmpty(size_t queue_index) const; 77 bool IsQueueEmpty(size_t queue_index) const;
71 78
79 // Set the name |queue_index| for tracing purposes. |name| must be a pointer
80 // to a static string.
81 void SetQueueName(size_t queue_index, const char* name);
82
72 private: 83 private:
73 friend class internal::TaskQueue; 84 friend class internal::TaskQueue;
74 85
75 // Called by the task queue to register a new pending task and allocate a 86 // Called by the task queue to register a new pending task and allocate a
76 // sequence number for it. 87 // sequence number for it.
77 void DidQueueTask(base::PendingTask* pending_task); 88 void DidQueueTask(base::PendingTask* pending_task);
78 89
79 // Post a task to call DoWork() on the main task runner. 90 // Post a task to call DoWork() on the main task runner.
80 void PostDoWorkOnMainRunner(); 91 void PostDoWorkOnMainRunner();
81 92
82 // Use the selector to choose a pending task and run it. 93 // Use the selector to choose a pending task and run it.
83 void DoWork(); 94 void DoWork();
84 95
85 // Reloads any empty work queues which have automatic pumping enabled. 96 // Reloads any empty work queues which have automatic pumping enabled.
86 // Returns true if any work queue has tasks after doing this. 97 // Returns true if any work queue has tasks after doing this.
87 bool UpdateWorkQueues(); 98 bool UpdateWorkQueues();
88 99
100 // Chooses the next work queue to service. Returns true if |out_queue_index|
101 // indicates the queue from which the next task should be run, false to
102 // avoid running any tasks.
103 bool SelectWorkQueueToService(size_t* out_queue_index);
104
89 // Runs a single task from the work queue designated by |queue_index|. The 105 // Runs a single task from the work queue designated by |queue_index|. The
90 // queue must not be empty. 106 // queue must not be empty.
91 void RunTaskFromWorkQueue(size_t queue_index); 107 void RunTaskFromWorkQueue(size_t queue_index);
92 108
93 bool RunsTasksOnCurrentThread() const; 109 bool RunsTasksOnCurrentThread() const;
94 bool PostDelayedTask(const tracked_objects::Location& from_here, 110 bool PostDelayedTask(const tracked_objects::Location& from_here,
95 const base::Closure& task, 111 const base::Closure& task,
96 base::TimeDelta delay); 112 base::TimeDelta delay);
97 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 113 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
98 const base::Closure& task, 114 const base::Closure& task,
99 base::TimeDelta delay); 115 base::TimeDelta delay);
100 internal::TaskQueue* Queue(size_t queue_index) const; 116 internal::TaskQueue* Queue(size_t queue_index) const;
101 117
118 scoped_refptr<base::debug::ConvertableToTraceFormat>
119 AsValueWithSelectorResult(bool should_run, size_t selected_queue) const;
120
102 std::vector<scoped_refptr<internal::TaskQueue>> queues_; 121 std::vector<scoped_refptr<internal::TaskQueue>> queues_;
103 base::AtomicSequenceNumber task_sequence_num_; 122 base::AtomicSequenceNumber task_sequence_num_;
104 base::debug::TaskAnnotator task_annotator_; 123 base::debug::TaskAnnotator task_annotator_;
105 124
106 base::ThreadChecker main_thread_checker_; 125 base::ThreadChecker main_thread_checker_;
107 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; 126 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
108 TaskQueueSelector* selector_; 127 TaskQueueSelector* selector_;
109 128
110 base::WeakPtr<TaskQueueManager> task_queue_manager_weak_ptr_; 129 base::WeakPtr<TaskQueueManager> task_queue_manager_weak_ptr_;
111 base::WeakPtrFactory<TaskQueueManager> weak_factory_; 130 base::WeakPtrFactory<TaskQueueManager> weak_factory_;
112 131
113 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); 132 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager);
114 }; 133 };
115 134
116 } // namespace content 135 } // namespace content
117 136
118 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ 137 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_
OLDNEW
« no previous file with comments | « content/renderer/scheduler/renderer_task_queue_selector.cc ('k') | content/renderer/scheduler/task_queue_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698