OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ | |
6 #define BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "base/base_export.h" | |
11 #include "base/macros.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/synchronization/waitable_event.h" | |
14 #include "base/task_runner.h" | |
15 #include "base/task_scheduler/delayed_task_manager.h" | |
16 #include "base/task_scheduler/scheduler_thread_pool_impl.h" | |
17 #include "base/task_scheduler/sequence.h" | |
18 #include "base/task_scheduler/task_scheduler.h" | |
19 #include "base/task_scheduler/task_tracker.h" | |
20 #include "base/task_scheduler/task_traits.h" | |
21 | |
22 namespace base { | |
23 namespace internal { | |
24 | |
25 // Default TaskScheduler implementation. This class is thread-safe. | |
26 class BASE_EXPORT TaskSchedulerImpl : public TaskScheduler { | |
27 public: | |
28 // Destroying a TaskSchedulerImpl is not allowed in production; it is always | |
29 // leaked. In tests, it can only be destroyed after JoinForTesting() has | |
30 // returned. | |
31 ~TaskSchedulerImpl() override; | |
32 | |
33 static std::unique_ptr<TaskSchedulerImpl> Create(); | |
gab
2016/04/27 19:15:28
// Creates and returns an initialized TaskSchedule
fdoray
2016/04/28 18:36:32
Removed this method. Added a similar comment on th
| |
34 | |
35 // TaskScheduler: | |
36 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( | |
37 const TaskTraits& traits, | |
38 ExecutionMode execution_mode) override; | |
39 void Shutdown() override; | |
40 | |
41 // Joins all threads of this scheduler. Tasks that are already running are | |
42 // allowed to complete their execution. This can only be called once. | |
43 void JoinForTesting(); | |
44 | |
45 private: | |
46 TaskSchedulerImpl(); | |
47 | |
48 void Initialize(); | |
49 | |
50 // Returns the thread pool that runs Tasks with |traits|. | |
51 SchedulerThreadPool* GetThreadPoolForTraits(const TaskTraits& traits); | |
52 | |
53 // Callback invoked when a non-single-thread |sequence| isn't empty after a | |
54 // worker thread pops a Task from it. | |
55 void ReEnqueueSequenceCallback(scoped_refptr<Sequence> sequence); | |
56 | |
57 TaskTracker task_tracker_; | |
58 DelayedTaskManager delayed_task_manager_; | |
59 | |
60 // Thread pool for BACKGROUND Tasks without file I/O. | |
61 std::unique_ptr<SchedulerThreadPoolImpl> background_thread_pool_; | |
62 | |
63 // Thread pool for BACKGROUND Tasks with file I/O. | |
64 std::unique_ptr<SchedulerThreadPoolImpl> background_file_io_thread_pool_; | |
65 | |
66 // Thread pool for USER_VISIBLE and USER_BLOCKING Tasks without file I/O. | |
67 std::unique_ptr<SchedulerThreadPoolImpl> normal_thread_pool_; | |
68 | |
69 // Thread pool for USER_VISIBLE and USER_BLOCKING Tasks with file I/O. | |
70 std::unique_ptr<SchedulerThreadPoolImpl> normal_file_io_thread_pool_; | |
71 | |
72 // Signaled once JoinForTesting() has returned. | |
73 WaitableEvent join_for_testing_returned_; | |
gab
2016/04/27 19:15:28
#if DCHECK_IS_ON()
fdoray
2016/04/28 18:36:32
Done.
| |
74 | |
75 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImpl); | |
76 }; | |
77 | |
78 } // namespace internal | |
79 } // namespace base | |
80 | |
81 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ | |
OLD | NEW |