OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/base_api.h" | 9 #include "base/base_api.h" |
| 10 #include "base/callback.h" |
10 #include "base/tracked.h" | 11 #include "base/tracked.h" |
11 | 12 |
12 class Task; | 13 class Task; |
13 | 14 |
14 namespace base { | 15 namespace base { |
15 | 16 |
16 // This is a facility that runs tasks that don't require a specific thread or | 17 // This is a facility that runs tasks that don't require a specific thread or |
17 // a message loop. | 18 // a message loop. |
18 // | 19 // |
19 // WARNING: This shouldn't be used unless absolutely necessary. We don't wait | 20 // WARNING: This shouldn't be used unless absolutely necessary. We don't wait |
20 // for the worker pool threads to finish on shutdown, so the tasks running | 21 // for the worker pool threads to finish on shutdown, so the tasks running |
21 // inside the pool must be extremely careful about other objects they access | 22 // inside the pool must be extremely careful about other objects they access |
22 // (MessageLoops, Singletons, etc). During shutdown these object may no longer | 23 // (MessageLoops, Singletons, etc). During shutdown these object may no longer |
23 // exist. | 24 // exist. |
24 class BASE_API WorkerPool { | 25 class BASE_API WorkerPool { |
25 public: | 26 public: |
26 // This function posts |task| to run on a worker thread. |task_is_slow| | 27 // This function posts |task| to run on a worker thread. |task_is_slow| |
27 // should be used for tasks that will take a long time to execute. Returns | 28 // should be used for tasks that will take a long time to execute. Returns |
28 // false if |task| could not be posted to a worker thread. Regardless of | 29 // false if |task| could not be posted to a worker thread. Regardless of |
29 // return value, ownership of |task| is transferred to the worker pool. | 30 // return value, ownership of |task| is transferred to the worker pool. |
| 31 // |
| 32 // TODO(ajwong): Remove the Task* based overload once we've finishsed the |
| 33 // Task -> Closure migration. |
30 static bool PostTask(const tracked_objects::Location& from_here, | 34 static bool PostTask(const tracked_objects::Location& from_here, |
31 Task* task, bool task_is_slow); | 35 Task* task, bool task_is_slow); |
| 36 static bool PostTask(const tracked_objects::Location& from_here, |
| 37 const base::Closure& task, bool task_is_slow); |
32 }; | 38 }; |
33 | 39 |
34 } // namespace base | 40 } // namespace base |
35 | 41 |
36 #endif // BASE_THREADING_WORKER_POOL_H_ | 42 #endif // BASE_THREADING_WORKER_POOL_H_ |
OLD | NEW |