| 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_export.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/tracked.h" | 11 #include "base/tracked.h" |
| 12 | 12 |
| 13 class Task; | 13 class Task; |
| 14 | 14 |
| 15 namespace base { | 15 namespace base { |
| 16 | 16 |
| 17 // 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 |
| 18 // a message loop. | 18 // a message loop. |
| 19 // | 19 // |
| 20 // 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 |
| 21 // 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 |
| 22 // 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 |
| 23 // (MessageLoops, Singletons, etc). During shutdown these object may no longer | 23 // (MessageLoops, Singletons, etc). During shutdown these object may no longer |
| 24 // exist. | 24 // exist. |
| 25 class BASE_API WorkerPool { | 25 class BASE_EXPORT WorkerPool { |
| 26 public: | 26 public: |
| 27 // 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| |
| 28 // 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 |
| 29 // 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 |
| 30 // return value, ownership of |task| is transferred to the worker pool. | 30 // return value, ownership of |task| is transferred to the worker pool. |
| 31 // | 31 // |
| 32 // TODO(ajwong): Remove the Task* based overload once we've finishsed the | 32 // TODO(ajwong): Remove the Task* based overload once we've finishsed the |
| 33 // Task -> Closure migration. | 33 // Task -> Closure migration. |
| 34 static bool PostTask(const tracked_objects::Location& from_here, | 34 static bool PostTask(const tracked_objects::Location& from_here, |
| 35 Task* task, bool task_is_slow); | 35 Task* task, bool task_is_slow); |
| 36 static bool PostTask(const tracked_objects::Location& from_here, | 36 static bool PostTask(const tracked_objects::Location& from_here, |
| 37 const base::Closure& task, bool task_is_slow); | 37 const base::Closure& task, bool task_is_slow); |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 } // namespace base | 40 } // namespace base |
| 41 | 41 |
| 42 #endif // BASE_THREADING_WORKER_POOL_H_ | 42 #endif // BASE_THREADING_WORKER_POOL_H_ |
| OLD | NEW |