OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "base/threading/worker_pool.h" | 5 #include "base/threading/worker_pool.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/debug/leak_annotations.h" | 9 #include "base/debug/leak_annotations.h" |
10 #include "base/lazy_instance.h" | |
11 #include "base/macros.h" | 10 #include "base/macros.h" |
12 #include "base/task_runner.h" | 11 #include "base/task_runner.h" |
13 #include "base/threading/post_task_and_reply_impl.h" | 12 #include "base/threading/post_task_and_reply_impl.h" |
14 #include "base/tracked_objects.h" | 13 #include "base/tracked_objects.h" |
15 | 14 |
16 namespace base { | 15 namespace base { |
17 | 16 |
18 namespace { | 17 namespace { |
19 | 18 |
20 class PostTaskAndReplyWorkerPool : public internal::PostTaskAndReplyImpl { | 19 class PostTaskAndReplyWorkerPool : public internal::PostTaskAndReplyImpl { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 } | 90 } |
92 | 91 |
93 struct TaskRunnerHolder { | 92 struct TaskRunnerHolder { |
94 TaskRunnerHolder() { | 93 TaskRunnerHolder() { |
95 taskrunners_[0] = new WorkerPoolTaskRunner(false); | 94 taskrunners_[0] = new WorkerPoolTaskRunner(false); |
96 taskrunners_[1] = new WorkerPoolTaskRunner(true); | 95 taskrunners_[1] = new WorkerPoolTaskRunner(true); |
97 } | 96 } |
98 scoped_refptr<TaskRunner> taskrunners_[2]; | 97 scoped_refptr<TaskRunner> taskrunners_[2]; |
99 }; | 98 }; |
100 | 99 |
101 base::LazyInstance<TaskRunnerHolder>::Leaky | |
102 g_taskrunners = LAZY_INSTANCE_INITIALIZER; | |
103 | |
104 } // namespace | 100 } // namespace |
105 | 101 |
106 bool WorkerPool::PostTaskAndReply(const tracked_objects::Location& from_here, | 102 bool WorkerPool::PostTaskAndReply(const tracked_objects::Location& from_here, |
107 const Closure& task, | 103 const Closure& task, |
108 const Closure& reply, | 104 const Closure& reply, |
109 bool task_is_slow) { | 105 bool task_is_slow) { |
110 // Do not report PostTaskAndReplyRelay leaks in tests. There's nothing we can | 106 // Do not report PostTaskAndReplyRelay leaks in tests. There's nothing we can |
111 // do about them because WorkerPool doesn't have a flushing API. | 107 // do about them because WorkerPool doesn't have a flushing API. |
112 // http://crbug.com/248513 | 108 // http://crbug.com/248513 |
113 // http://crbug.com/290897 | 109 // http://crbug.com/290897 |
114 // Note: this annotation does not cover tasks posted through a TaskRunner. | 110 // Note: this annotation does not cover tasks posted through a TaskRunner. |
115 ANNOTATE_SCOPED_MEMORY_LEAK; | 111 ANNOTATE_SCOPED_MEMORY_LEAK; |
116 return PostTaskAndReplyWorkerPool(task_is_slow).PostTaskAndReply( | 112 return PostTaskAndReplyWorkerPool(task_is_slow).PostTaskAndReply( |
117 from_here, task, reply); | 113 from_here, task, reply); |
118 } | 114 } |
119 | 115 |
120 // static | 116 // static |
121 const scoped_refptr<TaskRunner>& | 117 const scoped_refptr<TaskRunner>& |
122 WorkerPool::GetTaskRunner(bool tasks_are_slow) { | 118 WorkerPool::GetTaskRunner(bool tasks_are_slow) { |
123 return g_taskrunners.Get().taskrunners_[tasks_are_slow]; | 119 static auto task_runner_holder = new TaskRunnerHolder(); |
| 120 return task_runner_holder->taskrunners_[tasks_are_slow]; |
124 } | 121 } |
125 | 122 |
126 } // namespace base | 123 } // namespace base |
OLD | NEW |