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

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

Issue 2726523002: Pass Callback to TaskRunner by value and consume it on invocation (1) (Closed)
Patch Set: erase Closure* Created 3 years, 8 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_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>
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 13
14 #include "base/base_export.h" 14 #include "base/base_export.h"
15 #include "base/callback_forward.h" 15 #include "base/callback.h"
16 #include "base/compiler_specific.h" 16 #include "base/compiler_specific.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
19 #include "base/task_runner.h" 19 #include "base/task_runner.h"
20 #include "base/task_scheduler/task_traits.h" 20 #include "base/task_scheduler/task_traits.h"
21 21
22 namespace tracked_objects { 22 namespace tracked_objects {
23 class Location; 23 class Location;
24 } // namespace tracked_objects 24 } // namespace tracked_objects
25 25
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 // tasks. Deleting those tasks before the previous one has completed could 268 // tasks. Deleting those tasks before the previous one has completed could
269 // cause nondeterministic crashes because the task could be keeping some 269 // cause nondeterministic crashes because the task could be keeping some
270 // objects alive which do work in their destructor, which could voilate the 270 // objects alive which do work in their destructor, which could voilate the
271 // assumptions of the running task. 271 // assumptions of the running task.
272 // 272 //
273 // The task will be guaranteed to run to completion before shutdown 273 // The task will be guaranteed to run to completion before shutdown
274 // (BLOCK_SHUTDOWN semantics). 274 // (BLOCK_SHUTDOWN semantics).
275 // 275 //
276 // Returns true if the task was posted successfully. This may fail during 276 // Returns true if the task was posted successfully. This may fail during
277 // shutdown regardless of the specified ShutdownBehavior. 277 // shutdown regardless of the specified ShutdownBehavior.
278 bool PostWorkerTask(const tracked_objects::Location& from_here, 278 bool PostWorkerTask(const tracked_objects::Location& from_here, Closure task);
279 const Closure& task);
280 279
281 // Same as PostWorkerTask but allows a delay to be specified (although doing 280 // Same as PostWorkerTask but allows a delay to be specified (although doing
282 // so changes the shutdown behavior). The task will be run after the given 281 // so changes the shutdown behavior). The task will be run after the given
283 // delay has elapsed. 282 // delay has elapsed.
284 // 283 //
285 // If the delay is nonzero, the task won't be guaranteed to run to completion 284 // If the delay is nonzero, the task won't be guaranteed to run to completion
286 // before shutdown (SKIP_ON_SHUTDOWN semantics) to avoid shutdown hangs. 285 // before shutdown (SKIP_ON_SHUTDOWN semantics) to avoid shutdown hangs.
287 // If the delay is zero, this behaves exactly like PostWorkerTask, i.e. the 286 // If the delay is zero, this behaves exactly like PostWorkerTask, i.e. the
288 // task will be guaranteed to run to completion before shutdown 287 // task will be guaranteed to run to completion before shutdown
289 // (BLOCK_SHUTDOWN semantics). 288 // (BLOCK_SHUTDOWN semantics).
290 bool PostDelayedWorkerTask(const tracked_objects::Location& from_here, 289 bool PostDelayedWorkerTask(const tracked_objects::Location& from_here,
291 const Closure& task, 290 Closure task,
292 TimeDelta delay); 291 TimeDelta delay);
293 292
294 // Same as PostWorkerTask but allows specification of the shutdown behavior. 293 // Same as PostWorkerTask but allows specification of the shutdown behavior.
295 bool PostWorkerTaskWithShutdownBehavior( 294 bool PostWorkerTaskWithShutdownBehavior(
296 const tracked_objects::Location& from_here, 295 const tracked_objects::Location& from_here,
297 const Closure& task, 296 Closure task,
298 WorkerShutdown shutdown_behavior); 297 WorkerShutdown shutdown_behavior);
299 298
300 // Like PostWorkerTask above, but provides sequencing semantics. This means 299 // Like PostWorkerTask above, but provides sequencing semantics. This means
301 // that tasks posted with the same sequence token (see GetSequenceToken()) 300 // that tasks posted with the same sequence token (see GetSequenceToken())
302 // are guaranteed to execute in order. This is useful in cases where you're 301 // are guaranteed to execute in order. This is useful in cases where you're
303 // doing operations that may depend on previous ones, like appending to a 302 // doing operations that may depend on previous ones, like appending to a
304 // file. 303 // file.
305 // 304 //
306 // The task will be guaranteed to run to completion before shutdown 305 // The task will be guaranteed to run to completion before shutdown
307 // (BLOCK_SHUTDOWN semantics). 306 // (BLOCK_SHUTDOWN semantics).
308 // 307 //
309 // Returns true if the task was posted successfully. This may fail during 308 // Returns true if the task was posted successfully. This may fail during
310 // shutdown regardless of the specified ShutdownBehavior. 309 // shutdown regardless of the specified ShutdownBehavior.
311 bool PostSequencedWorkerTask(SequenceToken sequence_token, 310 bool PostSequencedWorkerTask(SequenceToken sequence_token,
312 const tracked_objects::Location& from_here, 311 const tracked_objects::Location& from_here,
313 const Closure& task); 312 Closure task);
314 313
315 // Like PostSequencedWorkerTask above, but allows you to specify a named 314 // Like PostSequencedWorkerTask above, but allows you to specify a named
316 // token, which saves an extra call to GetNamedSequenceToken. 315 // token, which saves an extra call to GetNamedSequenceToken.
317 bool PostNamedSequencedWorkerTask(const std::string& token_name, 316 bool PostNamedSequencedWorkerTask(const std::string& token_name,
318 const tracked_objects::Location& from_here, 317 const tracked_objects::Location& from_here,
319 const Closure& task); 318 Closure task);
320 319
321 // Same as PostSequencedWorkerTask but allows a delay to be specified 320 // Same as PostSequencedWorkerTask but allows a delay to be specified
322 // (although doing so changes the shutdown behavior). The task will be run 321 // (although doing so changes the shutdown behavior). The task will be run
323 // after the given delay has elapsed. 322 // after the given delay has elapsed.
324 // 323 //
325 // If the delay is nonzero, the task won't be guaranteed to run to completion 324 // If the delay is nonzero, the task won't be guaranteed to run to completion
326 // before shutdown (SKIP_ON_SHUTDOWN semantics) to avoid shutdown hangs. 325 // before shutdown (SKIP_ON_SHUTDOWN semantics) to avoid shutdown hangs.
327 // If the delay is zero, this behaves exactly like PostSequencedWorkerTask, 326 // If the delay is zero, this behaves exactly like PostSequencedWorkerTask,
328 // i.e. the task will be guaranteed to run to completion before shutdown 327 // i.e. the task will be guaranteed to run to completion before shutdown
329 // (BLOCK_SHUTDOWN semantics). 328 // (BLOCK_SHUTDOWN semantics).
330 bool PostDelayedSequencedWorkerTask( 329 bool PostDelayedSequencedWorkerTask(
331 SequenceToken sequence_token, 330 SequenceToken sequence_token,
332 const tracked_objects::Location& from_here, 331 const tracked_objects::Location& from_here,
333 const Closure& task, 332 Closure task,
334 TimeDelta delay); 333 TimeDelta delay);
335 334
336 // Same as PostSequencedWorkerTask but allows specification of the shutdown 335 // Same as PostSequencedWorkerTask but allows specification of the shutdown
337 // behavior. 336 // behavior.
338 bool PostSequencedWorkerTaskWithShutdownBehavior( 337 bool PostSequencedWorkerTaskWithShutdownBehavior(
339 SequenceToken sequence_token, 338 SequenceToken sequence_token,
340 const tracked_objects::Location& from_here, 339 const tracked_objects::Location& from_here,
341 const Closure& task, 340 Closure task,
342 WorkerShutdown shutdown_behavior); 341 WorkerShutdown shutdown_behavior);
343 342
344 // TaskRunner implementation. Forwards to PostDelayedWorkerTask(). 343 // TaskRunner implementation. Forwards to PostDelayedWorkerTask().
345 bool PostDelayedTask(const tracked_objects::Location& from_here, 344 bool PostDelayedTask(const tracked_objects::Location& from_here,
346 const Closure& task, 345 Closure task,
347 TimeDelta delay) override; 346 TimeDelta delay) override;
348 bool RunsTasksOnCurrentThread() const override; 347 bool RunsTasksOnCurrentThread() const override;
349 348
350 // Blocks until all pending tasks are complete. This should only be called in 349 // Blocks until all pending tasks are complete. This should only be called in
351 // unit tests when you want to validate something that should have happened. 350 // unit tests when you want to validate something that should have happened.
352 // Does not wait for delayed tasks. If redirection to TaskScheduler is 351 // Does not wait for delayed tasks. If redirection to TaskScheduler is
353 // disabled, delayed tasks are deleted. If redirection to TaskScheduler is 352 // disabled, delayed tasks are deleted. If redirection to TaskScheduler is
354 // enabled, this will wait for all tasks posted to TaskScheduler (not just 353 // enabled, this will wait for all tasks posted to TaskScheduler (not just
355 // tasks posted to this SequencedWorkerPool). 354 // tasks posted to this SequencedWorkerPool).
356 // 355 //
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 // Avoid pulling in too many headers by putting (almost) everything 408 // Avoid pulling in too many headers by putting (almost) everything
410 // into |inner_|. 409 // into |inner_|.
411 const std::unique_ptr<Inner> inner_; 410 const std::unique_ptr<Inner> inner_;
412 411
413 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); 412 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool);
414 }; 413 };
415 414
416 } // namespace base 415 } // namespace base
417 416
418 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ 417 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_
OLDNEW
« no previous file with comments | « base/threading/post_task_and_reply_impl_unittest.cc ('k') | base/threading/sequenced_worker_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698