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

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

Issue 673833002: scheduler: Don't access weak pointers on foreign threads (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Ross'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 unified diff | Download patch
« no previous file with comments | « no previous file | content/renderer/scheduler/task_queue_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/scoped_vector.h"
12 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
13 #include "base/pending_task.h" 12 #include "base/pending_task.h"
14 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
15 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
16 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
17 #include "content/common/content_export.h" 16 #include "content/common/content_export.h"
18 17
19 namespace content { 18 namespace content {
20 namespace internal { 19 namespace internal {
21 class TaskRunner; 20 class TaskQueue;
22 struct TaskQueue;
23 } 21 }
24 class TaskQueueSelector; 22 class TaskQueueSelector;
25 23
26 // The task queue manager provides N task queues and a selector interface for 24 // The task queue manager provides N task queues and a selector interface for
27 // choosing which task queue to service next. Each task queue consists of two 25 // choosing which task queue to service next. Each task queue consists of two
28 // sub queues: 26 // sub queues:
29 // 27 //
30 // 1. Incoming task queue. Tasks that are posted get immediately appended here. 28 // 1. Incoming task queue. Tasks that are posted get immediately appended here.
31 // When a task is appended into an empty incoming queue, the task manager 29 // When a task is appended into an empty incoming queue, the task manager
32 // work function (DoWork) is scheduled to run on the main task runner. 30 // work function (DoWork) is scheduled to run on the main task runner.
(...skipping 29 matching lines...) Expand all
62 // scheduled for execution. 60 // scheduled for execution.
63 // 61 //
64 // This function only needs to be called if automatic pumping is disabled 62 // This function only needs to be called if automatic pumping is disabled
65 // for |queue_index|. See |SetQueueAutoPump|. By default automatic pumping is 63 // for |queue_index|. See |SetQueueAutoPump|. By default automatic pumping is
66 // enabled for all queues. 64 // enabled for all queues.
67 void PumpQueue(size_t queue_index); 65 void PumpQueue(size_t queue_index);
68 66
69 // Returns true if there no tasks in either the work or incoming task queue 67 // Returns true if there no tasks in either the work or incoming task queue
70 // identified by |queue_index|. Note that this function involves taking a 68 // identified by |queue_index|. Note that this function involves taking a
71 // lock, so calling it has some overhead. 69 // lock, so calling it has some overhead.
72 bool IsQueueEmpty(size_t queue_index); 70 bool IsQueueEmpty(size_t queue_index) const;
73 71
74 private: 72 private:
75 friend class internal::TaskRunner; 73 friend class internal::TaskQueue;
76 74
77 // Adds a task at the end of the incoming task queue for |queue_index| and 75 // Called by the task queue to register a new pending task and allocate a
78 // schedules a call to DoWork() if the incoming queue was empty and automatic 76 // sequence number for it.
79 // pumping is enabled. Can be called on an arbitrary thread. 77 void DidQueueTask(base::PendingTask* pending_task);
80 void EnqueueTask(size_t queue_index, const base::PendingTask& pending_task);
81 78
82 // Post a task to call DoWork() on the main task runner. 79 // Post a task to call DoWork() on the main task runner.
83 void PostDoWorkOnMainRunner(); 80 void PostDoWorkOnMainRunner();
84 81
85 // Use the selector to choose a pending task and run it. 82 // Use the selector to choose a pending task and run it.
86 void DoWork(); 83 void DoWork();
87 84
88 // Reloads any empty work queues which have automatic pumping enabled. 85 // Reloads any empty work queues which have automatic pumping enabled.
89 // Returns true if any work queue has tasks after doing this. 86 // Returns true if any work queue has tasks after doing this.
90 bool UpdateWorkQueues(); 87 bool UpdateWorkQueues();
91 88
92 // Runs a single task from the work queue designated by |queue_index|. The 89 // Runs a single task from the work queue designated by |queue_index|. The
93 // queue must not be empty. 90 // queue must not be empty.
94 void RunTaskFromWorkQueue(size_t queue_index); 91 void RunTaskFromWorkQueue(size_t queue_index);
95 92
96 bool RunsTasksOnCurrentThread() const; 93 bool RunsTasksOnCurrentThread() const;
97 bool PostDelayedTask(size_t queue_index, 94 bool PostDelayedTask(const tracked_objects::Location& from_here,
98 const tracked_objects::Location& from_here,
99 const base::Closure& task, 95 const base::Closure& task,
100 base::TimeDelta delay); 96 base::TimeDelta delay);
101 bool PostNonNestableDelayedTask(size_t queue_index, 97 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
102 const tracked_objects::Location& from_here,
103 const base::Closure& task, 98 const base::Closure& task,
104 base::TimeDelta delay); 99 base::TimeDelta delay);
105 internal::TaskQueue* Queue(size_t queue_index) const; 100 internal::TaskQueue* Queue(size_t queue_index) const;
106 void PumpQueueLocked(internal::TaskQueue* queue);
107 101
108 ScopedVector<internal::TaskQueue> queues_; 102 std::vector<scoped_refptr<internal::TaskQueue>> queues_;
109 base::AtomicSequenceNumber task_sequence_num_; 103 base::AtomicSequenceNumber task_sequence_num_;
110 base::debug::TaskAnnotator task_annotator_; 104 base::debug::TaskAnnotator task_annotator_;
111 105
112 base::ThreadChecker main_thread_checker_; 106 base::ThreadChecker main_thread_checker_;
113 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; 107 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
114 TaskQueueSelector* selector_; 108 TaskQueueSelector* selector_;
115 109
110 base::WeakPtr<TaskQueueManager> task_queue_manager_weak_ptr_;
116 base::WeakPtrFactory<TaskQueueManager> weak_factory_; 111 base::WeakPtrFactory<TaskQueueManager> weak_factory_;
117 112
118 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); 113 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager);
119 }; 114 };
120 115
121 } // namespace content 116 } // namespace content
122 117
123 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ 118 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | content/renderer/scheduler/task_queue_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698