| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_TASK_SCHEDULER_TASK_TRACKER_H_ | 5 #ifndef BASE_TASK_SCHEDULER_TASK_TRACKER_H_ |
| 6 #define BASE_TASK_SCHEDULER_TASK_TRACKER_H_ | 6 #define BASE_TASK_SCHEDULER_TASK_TRACKER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
| 11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/metrics/histogram_base.h" | 13 #include "base/metrics/histogram_base.h" |
| 14 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
| 15 #include "base/task_scheduler/scheduler_lock.h" | 15 #include "base/task_scheduler/scheduler_lock.h" |
| 16 #include "base/task_scheduler/sequence.h" |
| 16 #include "base/task_scheduler/task.h" | 17 #include "base/task_scheduler/task.h" |
| 17 #include "base/task_scheduler/task_traits.h" | 18 #include "base/task_scheduler/task_traits.h" |
| 18 | 19 |
| 19 namespace base { | 20 namespace base { |
| 20 namespace internal { | 21 namespace internal { |
| 21 | 22 |
| 22 // All tasks go through the scheduler's TaskTracker when they are posted and | 23 // All tasks go through the scheduler's TaskTracker when they are posted and |
| 23 // when they are executed. The TaskTracker enforces shutdown semantics and takes | 24 // when they are executed. The TaskTracker enforces shutdown semantics and takes |
| 24 // care of tracing and profiling. This class is thread-safe. | 25 // care of tracing and profiling. This class is thread-safe. |
| 25 class BASE_EXPORT TaskTracker { | 26 class BASE_EXPORT TaskTracker { |
| 26 public: | 27 public: |
| 27 TaskTracker(); | 28 TaskTracker(); |
| 28 ~TaskTracker(); | 29 ~TaskTracker(); |
| 29 | 30 |
| 30 // Synchronously shuts down the scheduler. Once this is called, only tasks | 31 // Synchronously shuts down the scheduler. Once this is called, only tasks |
| 31 // posted with the BLOCK_SHUTDOWN behavior will be run. Returns when: | 32 // posted with the BLOCK_SHUTDOWN behavior will be run. Returns when: |
| 32 // - All SKIP_ON_SHUTDOWN tasks that were already running have completed their | 33 // - All SKIP_ON_SHUTDOWN tasks that were already running have completed their |
| 33 // execution. | 34 // execution. |
| 34 // - All posted BLOCK_SHUTDOWN tasks have completed their execution. | 35 // - All posted BLOCK_SHUTDOWN tasks have completed their execution. |
| 35 // CONTINUE_ON_SHUTDOWN tasks still may be running after Shutdown returns. | 36 // CONTINUE_ON_SHUTDOWN tasks still may be running after Shutdown returns. |
| 36 // This can only be called once. | 37 // This can only be called once. |
| 37 void Shutdown(); | 38 void Shutdown(); |
| 38 | 39 |
| 39 // Informs this TaskTracker that |task| is about to be posted. Returns true if | 40 // Informs this TaskTracker that |task| is about to be posted. Returns true if |
| 40 // this operation is allowed (|task| should be posted if-and-only-if it is). | 41 // this operation is allowed (|task| should be posted if-and-only-if it is). |
| 41 bool WillPostTask(const Task* task); | 42 bool WillPostTask(const Task* task); |
| 42 | 43 |
| 43 // Runs |task| unless the current shutdown state prevents that. WillPostTask() | 44 // Runs the next Task in |sequence| unless the current shutdown state prevents |
| 44 // must have allowed |task| to be posted. | 45 // that. WillPostTask() must have allowed the Task to be posted. |
| 45 void RunTask(const Task* task); | 46 void RunNextTaskInSequence(const Sequence* sequence); |
| 46 | 47 |
| 47 // Returns true if shutdown has completed. | 48 // Returns true if shutdown has completed. |
| 48 bool IsShutdownComplete() const; | 49 bool IsShutdownComplete() const; |
| 49 | 50 |
| 50 // Returns true while shutdown is in progress (i.e. Shutdown() has been called | 51 // Returns true while shutdown is in progress (i.e. Shutdown() has been called |
| 51 // but hasn't returned). | 52 // but hasn't returned). |
| 52 bool IsShuttingDownForTesting() const; | 53 bool IsShuttingDownForTesting() const; |
| 53 | 54 |
| 54 private: | 55 private: |
| 55 class State; | 56 class State; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 // Number of BLOCK_SHUTDOWN tasks posted during shutdown. | 88 // Number of BLOCK_SHUTDOWN tasks posted during shutdown. |
| 88 HistogramBase::Sample num_block_shutdown_tasks_posted_during_shutdown_ = 0; | 89 HistogramBase::Sample num_block_shutdown_tasks_posted_during_shutdown_ = 0; |
| 89 | 90 |
| 90 DISALLOW_COPY_AND_ASSIGN(TaskTracker); | 91 DISALLOW_COPY_AND_ASSIGN(TaskTracker); |
| 91 }; | 92 }; |
| 92 | 93 |
| 93 } // namespace internal | 94 } // namespace internal |
| 94 } // namespace base | 95 } // namespace base |
| 95 | 96 |
| 96 #endif // BASE_TASK_SCHEDULER_TASK_TRACKER_H_ | 97 #endif // BASE_TASK_SCHEDULER_TASK_TRACKER_H_ |
| OLD | NEW |