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

Side by Side Diff: base/threading/worker_pool.cc

Issue 2180953002: Support PostTaskAndReply from a sequenced task. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
OLDNEW
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" 10 #include "base/lazy_instance.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/task_runner.h" 12 #include "base/task_runner.h"
13 #include "base/threading/post_task_and_reply_impl.h" 13 #include "base/threading/post_task_and_reply_impl.h"
14 #include "base/tracked_objects.h" 14 #include "base/tracked_objects.h"
15 15
16 namespace base { 16 namespace base {
17 17
18 namespace { 18 namespace {
19 19
20 class PostTaskAndReplyWorkerPool : public internal::PostTaskAndReplyImpl {
21 public:
22 explicit PostTaskAndReplyWorkerPool(bool task_is_slow)
23 : task_is_slow_(task_is_slow) {
24 }
25 ~PostTaskAndReplyWorkerPool() override = default;
26
27 private:
28 bool PostTask(const tracked_objects::Location& from_here,
29 const Closure& task) override {
30 return WorkerPool::PostTask(from_here, task, task_is_slow_);
31 }
32
33 bool task_is_slow_;
34 };
35
36 // WorkerPoolTaskRunner --------------------------------------------- 20 // WorkerPoolTaskRunner ---------------------------------------------
37 // A TaskRunner which posts tasks to a WorkerPool with a 21 // A TaskRunner which posts tasks to a WorkerPool with a
38 // fixed ShutdownBehavior. 22 // fixed ShutdownBehavior.
39 // 23 //
40 // Note that this class is RefCountedThreadSafe (inherited from TaskRunner). 24 // Note that this class is RefCountedThreadSafe (inherited from TaskRunner).
41 class WorkerPoolTaskRunner : public TaskRunner { 25 class WorkerPoolTaskRunner : public TaskRunner {
42 public: 26 public:
43 explicit WorkerPoolTaskRunner(bool tasks_are_slow); 27 explicit WorkerPoolTaskRunner(bool tasks_are_slow);
44 28
45 // TaskRunner implementation 29 // TaskRunner implementation
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 bool WorkerPool::PostTaskAndReply(const tracked_objects::Location& from_here, 90 bool WorkerPool::PostTaskAndReply(const tracked_objects::Location& from_here,
107 const Closure& task, 91 const Closure& task,
108 const Closure& reply, 92 const Closure& reply,
109 bool task_is_slow) { 93 bool task_is_slow) {
110 // Do not report PostTaskAndReplyRelay leaks in tests. There's nothing we can 94 // Do not report PostTaskAndReplyRelay leaks in tests. There's nothing we can
111 // do about them because WorkerPool doesn't have a flushing API. 95 // do about them because WorkerPool doesn't have a flushing API.
112 // http://crbug.com/248513 96 // http://crbug.com/248513
113 // http://crbug.com/290897 97 // http://crbug.com/290897
114 // Note: this annotation does not cover tasks posted through a TaskRunner. 98 // Note: this annotation does not cover tasks posted through a TaskRunner.
115 ANNOTATE_SCOPED_MEMORY_LEAK; 99 ANNOTATE_SCOPED_MEMORY_LEAK;
116 return PostTaskAndReplyWorkerPool(task_is_slow).PostTaskAndReply( 100 return internal::PostTaskAndReply(
117 from_here, task, reply); 101 from_here, task, reply,
102 Bind(
103 [](bool task_is_slow, const tracked_objects::Location& from_here,
gab 2016/07/25 17:57:44 I think you can bind |task_is_slow| by value in th
fdoray 2016/07/25 20:40:04 I think this code https://cs.chromium.org/chromium
104 const Closure& task) {
105 return WorkerPool::PostTask(from_here, task, task_is_slow);
106 },
107 task_is_slow));
118 } 108 }
119 109
120 // static 110 // static
121 const scoped_refptr<TaskRunner>& 111 const scoped_refptr<TaskRunner>&
122 WorkerPool::GetTaskRunner(bool tasks_are_slow) { 112 WorkerPool::GetTaskRunner(bool tasks_are_slow) {
123 return g_taskrunners.Get().taskrunners_[tasks_are_slow]; 113 return g_taskrunners.Get().taskrunners_[tasks_are_slow];
124 } 114 }
125 115
126 } // namespace base 116 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698