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

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

Issue 2726523002: Pass Callback to TaskRunner by value and consume it on invocation (1) (Closed)
Patch Set: s/base::ResetAndReturn/std::move/ Created 3 years, 9 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 #ifndef BASE_THREADING_WORKER_POOL_H_ 5 #ifndef BASE_THREADING_WORKER_POOL_H_
6 #define BASE_THREADING_WORKER_POOL_H_ 6 #define BASE_THREADING_WORKER_POOL_H_
7 7
8 #include "base/base_export.h" 8 #include "base/base_export.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 14 matching lines...) Expand all
25 // inside the pool must be extremely careful about other objects they access 25 // inside the pool must be extremely careful about other objects they access
26 // (MessageLoops, Singletons, etc). During shutdown these object may no longer 26 // (MessageLoops, Singletons, etc). During shutdown these object may no longer
27 // exist. 27 // exist.
28 class BASE_EXPORT WorkerPool { 28 class BASE_EXPORT WorkerPool {
29 public: 29 public:
30 // This function posts |task| to run on a worker thread. |task_is_slow| 30 // This function posts |task| to run on a worker thread. |task_is_slow|
31 // should be used for tasks that will take a long time to execute. Returns 31 // should be used for tasks that will take a long time to execute. Returns
32 // false if |task| could not be posted to a worker thread. Regardless of 32 // false if |task| could not be posted to a worker thread. Regardless of
33 // return value, ownership of |task| is transferred to the worker pool. 33 // return value, ownership of |task| is transferred to the worker pool.
34 static bool PostTask(const tracked_objects::Location& from_here, 34 static bool PostTask(const tracked_objects::Location& from_here,
35 const base::Closure& task, bool task_is_slow); 35 Closure task,
36 bool task_is_slow);
36 37
37 // Just like TaskRunner::PostTaskAndReply, except the destination 38 // Just like TaskRunner::PostTaskAndReply, except the destination
38 // for |task| is a worker thread and you can specify |task_is_slow| just 39 // for |task| is a worker thread and you can specify |task_is_slow| just
39 // like you can for PostTask above. 40 // like you can for PostTask above.
40 static bool PostTaskAndReply(const tracked_objects::Location& from_here, 41 static bool PostTaskAndReply(const tracked_objects::Location& from_here,
41 Closure task, 42 Closure task,
42 Closure reply, 43 Closure reply,
43 bool task_is_slow); 44 bool task_is_slow);
44 45
45 // Return true if the current thread is one that this WorkerPool runs tasks 46 // Return true if the current thread is one that this WorkerPool runs tasks
46 // on. (Note that if the Windows worker pool is used without going through 47 // on. (Note that if the Windows worker pool is used without going through
47 // this WorkerPool interface, RunsTasksOnCurrentThread would return false on 48 // this WorkerPool interface, RunsTasksOnCurrentThread would return false on
48 // those threads.) 49 // those threads.)
49 static bool RunsTasksOnCurrentThread(); 50 static bool RunsTasksOnCurrentThread();
50 51
51 // Get a TaskRunner wrapper which posts to the WorkerPool using the given 52 // Get a TaskRunner wrapper which posts to the WorkerPool using the given
52 // |task_is_slow| behavior. 53 // |task_is_slow| behavior.
53 static const scoped_refptr<TaskRunner>& GetTaskRunner(bool task_is_slow); 54 static const scoped_refptr<TaskRunner>& GetTaskRunner(bool task_is_slow);
54 }; 55 };
55 56
56 } // namespace base 57 } // namespace base
57 58
58 #endif // BASE_THREADING_WORKER_POOL_H_ 59 #endif // BASE_THREADING_WORKER_POOL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698