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

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

Issue 2912073002: Revert of Remove SequencedWorkerPool::PostWorkerTask(). (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « no previous file | base/threading/sequenced_worker_pool.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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
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 PostTask. 58 // You can also post tasks to the pool without ordering using PostWorkerTask.
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
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
258 // Same as PostWorkerTask but allows specification of the shutdown behavior. 281 // Same as PostWorkerTask but allows specification of the shutdown behavior.
259 bool PostWorkerTaskWithShutdownBehavior( 282 bool PostWorkerTaskWithShutdownBehavior(
260 const tracked_objects::Location& from_here, 283 const tracked_objects::Location& from_here,
261 OnceClosure task, 284 OnceClosure task,
262 WorkerShutdown shutdown_behavior); 285 WorkerShutdown shutdown_behavior);
263 286
264 // Like PostWorkerTask above, but provides sequencing semantics. This means 287 // Like PostWorkerTask above, but provides sequencing semantics. This means
265 // that tasks posted with the same sequence token (see GetSequenceToken()) 288 // that tasks posted with the same sequence token (see GetSequenceToken())
266 // are guaranteed to execute in order. This is useful in cases where you're 289 // are guaranteed to execute in order. This is useful in cases where you're
267 // doing operations that may depend on previous ones, like appending to a 290 // doing operations that may depend on previous ones, like appending to a
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 // Avoid pulling in too many headers by putting (almost) everything 396 // Avoid pulling in too many headers by putting (almost) everything
374 // into |inner_|. 397 // into |inner_|.
375 const std::unique_ptr<Inner> inner_; 398 const std::unique_ptr<Inner> inner_;
376 399
377 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); 400 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool);
378 }; 401 };
379 402
380 } // namespace base 403 } // namespace base
381 404
382 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ 405 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_
OLDNEW
« no previous file with comments | « no previous file | base/threading/sequenced_worker_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698