| 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 #ifndef BASE_THREADING_SEQUENCED_WORKER_POOL_H_ | 5 #ifndef BASE_THREADING_SEQUENCED_WORKER_POOL_H_ |
| 6 #define BASE_THREADING_SEQUENCED_WORKER_POOL_H_ | 6 #define BASE_THREADING_SEQUENCED_WORKER_POOL_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <cstddef> | 10 #include <cstddef> |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 // Example: | 48 // Example: |
| 49 // SequencedWorkerPool::SequenceToken token = pool.GetSequenceToken(); | 49 // SequencedWorkerPool::SequenceToken token = pool.GetSequenceToken(); |
| 50 // pool.PostSequencedWorkerTask(token, SequencedWorkerPool::SKIP_ON_SHUTDOWN, | 50 // pool.PostSequencedWorkerTask(token, SequencedWorkerPool::SKIP_ON_SHUTDOWN, |
| 51 // FROM_HERE, base::Bind(...)); | 51 // FROM_HERE, base::Bind(...)); |
| 52 // pool.PostSequencedWorkerTask(token, SequencedWorkerPool::SKIP_ON_SHUTDOWN, | 52 // pool.PostSequencedWorkerTask(token, SequencedWorkerPool::SKIP_ON_SHUTDOWN, |
| 53 // FROM_HERE, base::Bind(...)); | 53 // FROM_HERE, base::Bind(...)); |
| 54 // | 54 // |
| 55 // You can make named sequence tokens to make it easier to share a token | 55 // You can make named sequence tokens to make it easier to share a token |
| 56 // across different components. | 56 // across different components. |
| 57 // | 57 // |
| 58 // You can also post tasks to the pool without ordering using PostWorkerTask. | 58 // You can also post tasks to the pool without ordering using PostTask. |
| 59 // These will be executed in an unspecified order. The order of execution | 59 // These will be executed in an unspecified order. The order of execution |
| 60 // between tasks with different sequence tokens is also unspecified. | 60 // between tasks with different sequence tokens is also unspecified. |
| 61 // | 61 // |
| 62 // You must call EnableForProcess() or | 62 // You must call EnableForProcess() or |
| 63 // EnableWithRedirectionToTaskSchedulerForProcess() before starting to post | 63 // EnableWithRedirectionToTaskSchedulerForProcess() before starting to post |
| 64 // tasks to a process' SequencedWorkerPools. | 64 // tasks to a process' SequencedWorkerPools. |
| 65 // | 65 // |
| 66 // This class may be leaked on shutdown to facilitate fast shutdown. The | 66 // This class may be leaked on shutdown to facilitate fast shutdown. The |
| 67 // expected usage, however, is to call Shutdown(), which correctly accounts | 67 // expected usage, however, is to call Shutdown(), which correctly accounts |
| 68 // for CONTINUE_ON_SHUTDOWN behavior and is required for BLOCK_SHUTDOWN | 68 // for CONTINUE_ON_SHUTDOWN behavior and is required for BLOCK_SHUTDOWN |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 SequenceToken token, | 248 SequenceToken token, |
| 249 WorkerShutdown shutdown_behavior) WARN_UNUSED_RESULT; | 249 WorkerShutdown shutdown_behavior) WARN_UNUSED_RESULT; |
| 250 | 250 |
| 251 // Returns a TaskRunner wrapper which posts to this SequencedWorkerPool using | 251 // Returns a TaskRunner wrapper which posts to this SequencedWorkerPool using |
| 252 // the given shutdown behavior. Tasks with nonzero delay are posted with | 252 // the given shutdown behavior. Tasks with nonzero delay are posted with |
| 253 // SKIP_ON_SHUTDOWN behavior and tasks with zero delay are posted with the | 253 // SKIP_ON_SHUTDOWN behavior and tasks with zero delay are posted with the |
| 254 // given shutdown behavior. | 254 // given shutdown behavior. |
| 255 scoped_refptr<TaskRunner> GetTaskRunnerWithShutdownBehavior( | 255 scoped_refptr<TaskRunner> GetTaskRunnerWithShutdownBehavior( |
| 256 WorkerShutdown shutdown_behavior) WARN_UNUSED_RESULT; | 256 WorkerShutdown shutdown_behavior) WARN_UNUSED_RESULT; |
| 257 | 257 |
| 258 // Posts the given task for execution in the worker pool. Tasks posted with | |
| 259 // this function will execute in an unspecified order on a background thread. | |
| 260 // Returns true if the task was posted. If your tasks have ordering | |
| 261 // requirements, see PostSequencedWorkerTask(). | |
| 262 // | |
| 263 // This class will attempt to delete tasks that aren't run | |
| 264 // (non-block-shutdown semantics) but can't guarantee that this happens. If | |
| 265 // all worker threads are busy running CONTINUE_ON_SHUTDOWN tasks, there | |
| 266 // will be no workers available to delete these tasks. And there may be | |
| 267 // tasks with the same sequence token behind those CONTINUE_ON_SHUTDOWN | |
| 268 // tasks. Deleting those tasks before the previous one has completed could | |
| 269 // cause nondeterministic crashes because the task could be keeping some | |
| 270 // objects alive which do work in their destructor, which could voilate the | |
| 271 // assumptions of the running task. | |
| 272 // | |
| 273 // The task will be guaranteed to run to completion before shutdown | |
| 274 // (BLOCK_SHUTDOWN semantics). | |
| 275 // | |
| 276 // Returns true if the task was posted successfully. This may fail during | |
| 277 // shutdown regardless of the specified ShutdownBehavior. | |
| 278 bool PostWorkerTask(const tracked_objects::Location& from_here, | |
| 279 OnceClosure task); | |
| 280 | |
| 281 // Same as PostWorkerTask but allows specification of the shutdown behavior. | 258 // Same as PostWorkerTask but allows specification of the shutdown behavior. |
| 282 bool PostWorkerTaskWithShutdownBehavior( | 259 bool PostWorkerTaskWithShutdownBehavior( |
| 283 const tracked_objects::Location& from_here, | 260 const tracked_objects::Location& from_here, |
| 284 OnceClosure task, | 261 OnceClosure task, |
| 285 WorkerShutdown shutdown_behavior); | 262 WorkerShutdown shutdown_behavior); |
| 286 | 263 |
| 287 // Like PostWorkerTask above, but provides sequencing semantics. This means | 264 // Like PostWorkerTask above, but provides sequencing semantics. This means |
| 288 // that tasks posted with the same sequence token (see GetSequenceToken()) | 265 // that tasks posted with the same sequence token (see GetSequenceToken()) |
| 289 // are guaranteed to execute in order. This is useful in cases where you're | 266 // are guaranteed to execute in order. This is useful in cases where you're |
| 290 // doing operations that may depend on previous ones, like appending to a | 267 // doing operations that may depend on previous ones, like appending to a |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 // Avoid pulling in too many headers by putting (almost) everything | 373 // Avoid pulling in too many headers by putting (almost) everything |
| 397 // into |inner_|. | 374 // into |inner_|. |
| 398 const std::unique_ptr<Inner> inner_; | 375 const std::unique_ptr<Inner> inner_; |
| 399 | 376 |
| 400 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); | 377 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); |
| 401 }; | 378 }; |
| 402 | 379 |
| 403 } // namespace base | 380 } // namespace base |
| 404 | 381 |
| 405 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ | 382 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ |
| OLD | NEW |