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

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

Issue 2637843002: Migrate base::TaskRunner from Closure to OnceClosure (Closed)
Patch Set: rebase 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>
(...skipping 257 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, Closure task); 278 bool PostWorkerTask(const tracked_objects::Location& from_here,
279 OnceClosure task);
279 280
280 // Same as PostWorkerTask but allows a delay to be specified (although doing 281 // Same as PostWorkerTask but allows a delay to be specified (although doing
281 // so changes the shutdown behavior). The task will be run after the given 282 // so changes the shutdown behavior). The task will be run after the given
282 // delay has elapsed. 283 // delay has elapsed.
283 // 284 //
284 // If the delay is nonzero, the task won't be guaranteed to run to completion 285 // If the delay is nonzero, the task won't be guaranteed to run to completion
285 // before shutdown (SKIP_ON_SHUTDOWN semantics) to avoid shutdown hangs. 286 // before shutdown (SKIP_ON_SHUTDOWN semantics) to avoid shutdown hangs.
286 // If the delay is zero, this behaves exactly like PostWorkerTask, i.e. the 287 // If the delay is zero, this behaves exactly like PostWorkerTask, i.e. the
287 // task will be guaranteed to run to completion before shutdown 288 // task will be guaranteed to run to completion before shutdown
288 // (BLOCK_SHUTDOWN semantics). 289 // (BLOCK_SHUTDOWN semantics).
289 bool PostDelayedWorkerTask(const tracked_objects::Location& from_here, 290 bool PostDelayedWorkerTask(const tracked_objects::Location& from_here,
290 Closure task, 291 OnceClosure task,
291 TimeDelta delay); 292 TimeDelta delay);
292 293
293 // Same as PostWorkerTask but allows specification of the shutdown behavior. 294 // Same as PostWorkerTask but allows specification of the shutdown behavior.
294 bool PostWorkerTaskWithShutdownBehavior( 295 bool PostWorkerTaskWithShutdownBehavior(
295 const tracked_objects::Location& from_here, 296 const tracked_objects::Location& from_here,
296 Closure task, 297 OnceClosure task,
297 WorkerShutdown shutdown_behavior); 298 WorkerShutdown shutdown_behavior);
298 299
299 // Like PostWorkerTask above, but provides sequencing semantics. This means 300 // Like PostWorkerTask above, but provides sequencing semantics. This means
300 // that tasks posted with the same sequence token (see GetSequenceToken()) 301 // that tasks posted with the same sequence token (see GetSequenceToken())
301 // are guaranteed to execute in order. This is useful in cases where you're 302 // are guaranteed to execute in order. This is useful in cases where you're
302 // doing operations that may depend on previous ones, like appending to a 303 // doing operations that may depend on previous ones, like appending to a
303 // file. 304 // file.
304 // 305 //
305 // The task will be guaranteed to run to completion before shutdown 306 // The task will be guaranteed to run to completion before shutdown
306 // (BLOCK_SHUTDOWN semantics). 307 // (BLOCK_SHUTDOWN semantics).
307 // 308 //
308 // Returns true if the task was posted successfully. This may fail during 309 // Returns true if the task was posted successfully. This may fail during
309 // shutdown regardless of the specified ShutdownBehavior. 310 // shutdown regardless of the specified ShutdownBehavior.
310 bool PostSequencedWorkerTask(SequenceToken sequence_token, 311 bool PostSequencedWorkerTask(SequenceToken sequence_token,
311 const tracked_objects::Location& from_here, 312 const tracked_objects::Location& from_here,
312 Closure task); 313 OnceClosure task);
313 314
314 // Like PostSequencedWorkerTask above, but allows you to specify a named 315 // Like PostSequencedWorkerTask above, but allows you to specify a named
315 // token, which saves an extra call to GetNamedSequenceToken. 316 // token, which saves an extra call to GetNamedSequenceToken.
316 bool PostNamedSequencedWorkerTask(const std::string& token_name, 317 bool PostNamedSequencedWorkerTask(const std::string& token_name,
317 const tracked_objects::Location& from_here, 318 const tracked_objects::Location& from_here,
318 Closure task); 319 OnceClosure task);
319 320
320 // Same as PostSequencedWorkerTask but allows a delay to be specified 321 // Same as PostSequencedWorkerTask but allows a delay to be specified
321 // (although doing so changes the shutdown behavior). The task will be run 322 // (although doing so changes the shutdown behavior). The task will be run
322 // after the given delay has elapsed. 323 // after the given delay has elapsed.
323 // 324 //
324 // If the delay is nonzero, the task won't be guaranteed to run to completion 325 // If the delay is nonzero, the task won't be guaranteed to run to completion
325 // before shutdown (SKIP_ON_SHUTDOWN semantics) to avoid shutdown hangs. 326 // before shutdown (SKIP_ON_SHUTDOWN semantics) to avoid shutdown hangs.
326 // If the delay is zero, this behaves exactly like PostSequencedWorkerTask, 327 // If the delay is zero, this behaves exactly like PostSequencedWorkerTask,
327 // i.e. the task will be guaranteed to run to completion before shutdown 328 // i.e. the task will be guaranteed to run to completion before shutdown
328 // (BLOCK_SHUTDOWN semantics). 329 // (BLOCK_SHUTDOWN semantics).
329 bool PostDelayedSequencedWorkerTask( 330 bool PostDelayedSequencedWorkerTask(
330 SequenceToken sequence_token, 331 SequenceToken sequence_token,
331 const tracked_objects::Location& from_here, 332 const tracked_objects::Location& from_here,
332 Closure task, 333 OnceClosure task,
333 TimeDelta delay); 334 TimeDelta delay);
334 335
335 // Same as PostSequencedWorkerTask but allows specification of the shutdown 336 // Same as PostSequencedWorkerTask but allows specification of the shutdown
336 // behavior. 337 // behavior.
337 bool PostSequencedWorkerTaskWithShutdownBehavior( 338 bool PostSequencedWorkerTaskWithShutdownBehavior(
338 SequenceToken sequence_token, 339 SequenceToken sequence_token,
339 const tracked_objects::Location& from_here, 340 const tracked_objects::Location& from_here,
340 Closure task, 341 OnceClosure task,
341 WorkerShutdown shutdown_behavior); 342 WorkerShutdown shutdown_behavior);
342 343
343 // TaskRunner implementation. Forwards to PostDelayedWorkerTask(). 344 // TaskRunner implementation. Forwards to PostDelayedWorkerTask().
344 bool PostDelayedTask(const tracked_objects::Location& from_here, 345 bool PostDelayedTask(const tracked_objects::Location& from_here,
345 Closure task, 346 OnceClosure task,
346 TimeDelta delay) override; 347 TimeDelta delay) override;
347 bool RunsTasksOnCurrentThread() const override; 348 bool RunsTasksOnCurrentThread() const override;
348 349
349 // Blocks until all pending tasks are complete. This should only be called in 350 // Blocks until all pending tasks are complete. This should only be called in
350 // unit tests when you want to validate something that should have happened. 351 // unit tests when you want to validate something that should have happened.
351 // Does not wait for delayed tasks. If redirection to TaskScheduler is 352 // Does not wait for delayed tasks. If redirection to TaskScheduler is
352 // disabled, delayed tasks are deleted. If redirection to TaskScheduler is 353 // disabled, delayed tasks are deleted. If redirection to TaskScheduler is
353 // enabled, this will wait for all tasks posted to TaskScheduler (not just 354 // enabled, this will wait for all tasks posted to TaskScheduler (not just
354 // tasks posted to this SequencedWorkerPool). 355 // tasks posted to this SequencedWorkerPool).
355 // 356 //
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 // Avoid pulling in too many headers by putting (almost) everything 409 // Avoid pulling in too many headers by putting (almost) everything
409 // into |inner_|. 410 // into |inner_|.
410 const std::unique_ptr<Inner> inner_; 411 const std::unique_ptr<Inner> inner_;
411 412
412 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); 413 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool);
413 }; 414 };
414 415
415 } // namespace base 416 } // namespace base
416 417
417 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ 418 #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