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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 // cause nondeterministic crashes because the task could be keeping some | 245 // cause nondeterministic crashes because the task could be keeping some |
246 // objects alive which do work in their destructor, which could voilate the | 246 // objects alive which do work in their destructor, which could voilate the |
247 // assumptions of the running task. | 247 // assumptions of the running task. |
248 // | 248 // |
249 // The task will be guaranteed to run to completion before shutdown | 249 // The task will be guaranteed to run to completion before shutdown |
250 // (BLOCK_SHUTDOWN semantics). | 250 // (BLOCK_SHUTDOWN semantics). |
251 // | 251 // |
252 // Returns true if the task was posted successfully. This may fail during | 252 // Returns true if the task was posted successfully. This may fail during |
253 // shutdown regardless of the specified ShutdownBehavior. | 253 // shutdown regardless of the specified ShutdownBehavior. |
254 bool PostWorkerTask(const tracked_objects::Location& from_here, | 254 bool PostWorkerTask(const tracked_objects::Location& from_here, |
255 const Closure& task); | 255 OnceClosure task); |
256 | 256 |
257 // Same as PostWorkerTask but allows a delay to be specified (although doing | 257 // Same as PostWorkerTask but allows a delay to be specified (although doing |
258 // so changes the shutdown behavior). The task will be run after the given | 258 // so changes the shutdown behavior). The task will be run after the given |
259 // delay has elapsed. | 259 // delay has elapsed. |
260 // | 260 // |
261 // If the delay is nonzero, the task won't be guaranteed to run to completion | 261 // If the delay is nonzero, the task won't be guaranteed to run to completion |
262 // before shutdown (SKIP_ON_SHUTDOWN semantics) to avoid shutdown hangs. | 262 // before shutdown (SKIP_ON_SHUTDOWN semantics) to avoid shutdown hangs. |
263 // If the delay is zero, this behaves exactly like PostWorkerTask, i.e. the | 263 // If the delay is zero, this behaves exactly like PostWorkerTask, i.e. the |
264 // task will be guaranteed to run to completion before shutdown | 264 // task will be guaranteed to run to completion before shutdown |
265 // (BLOCK_SHUTDOWN semantics). | 265 // (BLOCK_SHUTDOWN semantics). |
266 bool PostDelayedWorkerTask(const tracked_objects::Location& from_here, | 266 bool PostDelayedWorkerTask(const tracked_objects::Location& from_here, |
267 const Closure& task, | 267 OnceClosure task, |
268 TimeDelta delay); | 268 TimeDelta delay); |
269 | 269 |
270 // Same as PostWorkerTask but allows specification of the shutdown behavior. | 270 // Same as PostWorkerTask but allows specification of the shutdown behavior. |
271 bool PostWorkerTaskWithShutdownBehavior( | 271 bool PostWorkerTaskWithShutdownBehavior( |
272 const tracked_objects::Location& from_here, | 272 const tracked_objects::Location& from_here, |
273 const Closure& task, | 273 OnceClosure task, |
274 WorkerShutdown shutdown_behavior); | 274 WorkerShutdown shutdown_behavior); |
275 | 275 |
276 // Like PostWorkerTask above, but provides sequencing semantics. This means | 276 // Like PostWorkerTask above, but provides sequencing semantics. This means |
277 // that tasks posted with the same sequence token (see GetSequenceToken()) | 277 // that tasks posted with the same sequence token (see GetSequenceToken()) |
278 // are guaranteed to execute in order. This is useful in cases where you're | 278 // are guaranteed to execute in order. This is useful in cases where you're |
279 // doing operations that may depend on previous ones, like appending to a | 279 // doing operations that may depend on previous ones, like appending to a |
280 // file. | 280 // file. |
281 // | 281 // |
282 // The task will be guaranteed to run to completion before shutdown | 282 // The task will be guaranteed to run to completion before shutdown |
283 // (BLOCK_SHUTDOWN semantics). | 283 // (BLOCK_SHUTDOWN semantics). |
284 // | 284 // |
285 // Returns true if the task was posted successfully. This may fail during | 285 // Returns true if the task was posted successfully. This may fail during |
286 // shutdown regardless of the specified ShutdownBehavior. | 286 // shutdown regardless of the specified ShutdownBehavior. |
287 bool PostSequencedWorkerTask(SequenceToken sequence_token, | 287 bool PostSequencedWorkerTask(SequenceToken sequence_token, |
288 const tracked_objects::Location& from_here, | 288 const tracked_objects::Location& from_here, |
289 const Closure& task); | 289 OnceClosure task); |
290 | 290 |
291 // Like PostSequencedWorkerTask above, but allows you to specify a named | 291 // Like PostSequencedWorkerTask above, but allows you to specify a named |
292 // token, which saves an extra call to GetNamedSequenceToken. | 292 // token, which saves an extra call to GetNamedSequenceToken. |
293 bool PostNamedSequencedWorkerTask(const std::string& token_name, | 293 bool PostNamedSequencedWorkerTask(const std::string& token_name, |
294 const tracked_objects::Location& from_here, | 294 const tracked_objects::Location& from_here, |
295 const Closure& task); | 295 OnceClosure task); |
296 | 296 |
297 // Same as PostSequencedWorkerTask but allows a delay to be specified | 297 // Same as PostSequencedWorkerTask but allows a delay to be specified |
298 // (although doing so changes the shutdown behavior). The task will be run | 298 // (although doing so changes the shutdown behavior). The task will be run |
299 // after the given delay has elapsed. | 299 // after the given delay has elapsed. |
300 // | 300 // |
301 // If the delay is nonzero, the task won't be guaranteed to run to completion | 301 // If the delay is nonzero, the task won't be guaranteed to run to completion |
302 // before shutdown (SKIP_ON_SHUTDOWN semantics) to avoid shutdown hangs. | 302 // before shutdown (SKIP_ON_SHUTDOWN semantics) to avoid shutdown hangs. |
303 // If the delay is zero, this behaves exactly like PostSequencedWorkerTask, | 303 // If the delay is zero, this behaves exactly like PostSequencedWorkerTask, |
304 // i.e. the task will be guaranteed to run to completion before shutdown | 304 // i.e. the task will be guaranteed to run to completion before shutdown |
305 // (BLOCK_SHUTDOWN semantics). | 305 // (BLOCK_SHUTDOWN semantics). |
306 bool PostDelayedSequencedWorkerTask( | 306 bool PostDelayedSequencedWorkerTask( |
307 SequenceToken sequence_token, | 307 SequenceToken sequence_token, |
308 const tracked_objects::Location& from_here, | 308 const tracked_objects::Location& from_here, |
309 const Closure& task, | 309 OnceClosure task, |
310 TimeDelta delay); | 310 TimeDelta delay); |
311 | 311 |
312 // Same as PostSequencedWorkerTask but allows specification of the shutdown | 312 // Same as PostSequencedWorkerTask but allows specification of the shutdown |
313 // behavior. | 313 // behavior. |
314 bool PostSequencedWorkerTaskWithShutdownBehavior( | 314 bool PostSequencedWorkerTaskWithShutdownBehavior( |
315 SequenceToken sequence_token, | 315 SequenceToken sequence_token, |
316 const tracked_objects::Location& from_here, | 316 const tracked_objects::Location& from_here, |
317 const Closure& task, | 317 OnceClosure task, |
318 WorkerShutdown shutdown_behavior); | 318 WorkerShutdown shutdown_behavior); |
319 | 319 |
320 // TaskRunner implementation. Forwards to PostDelayedWorkerTask(). | 320 // TaskRunner implementation. Forwards to PostDelayedWorkerTask(). |
321 bool PostDelayedTask(const tracked_objects::Location& from_here, | 321 bool PostDelayedTask(const tracked_objects::Location& from_here, |
322 const Closure& task, | 322 OnceClosure task, |
323 TimeDelta delay) override; | 323 TimeDelta delay) override; |
324 bool RunsTasksOnCurrentThread() const override; | 324 bool RunsTasksOnCurrentThread() const override; |
325 | 325 |
326 // Returns true if the current thread is processing a task with the given | 326 // Returns true if the current thread is processing a task with the given |
327 // sequence_token. | 327 // sequence_token. |
328 bool IsRunningSequenceOnCurrentThread(SequenceToken sequence_token) const; | 328 bool IsRunningSequenceOnCurrentThread(SequenceToken sequence_token) const; |
329 | 329 |
330 // Blocks until all pending tasks are complete. This should only be called in | 330 // Blocks until all pending tasks are complete. This should only be called in |
331 // unit tests when you want to validate something that should have happened. | 331 // unit tests when you want to validate something that should have happened. |
332 // This will not flush delayed tasks; delayed tasks get deleted. | 332 // This will not flush delayed tasks; delayed tasks get deleted. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 // Avoid pulling in too many headers by putting (almost) everything | 378 // Avoid pulling in too many headers by putting (almost) everything |
379 // into |inner_|. | 379 // into |inner_|. |
380 const std::unique_ptr<Inner> inner_; | 380 const std::unique_ptr<Inner> inner_; |
381 | 381 |
382 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); | 382 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPool); |
383 }; | 383 }; |
384 | 384 |
385 } // namespace base | 385 } // namespace base |
386 | 386 |
387 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ | 387 #endif // BASE_THREADING_SEQUENCED_WORKER_POOL_H_ |
OLD | NEW |