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

Side by Side Diff: base/task_scheduler/task_scheduler_impl.h

Issue 1701343003: TaskScheduler [13] TaskSchedulerImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@s_6_threadpool
Patch Set: CR gab #13 Created 4 years, 7 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
(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/logging.h"
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/synchronization/waitable_event.h"
15 #include "base/task_runner.h"
16 #include "base/task_scheduler/delayed_task_manager.h"
17 #include "base/task_scheduler/scheduler_thread_pool_impl.h"
18 #include "base/task_scheduler/sequence.h"
19 #include "base/task_scheduler/task_scheduler.h"
20 #include "base/task_scheduler/task_tracker.h"
21 #include "base/task_scheduler/task_traits.h"
22
23 namespace base {
24 namespace internal {
25
26 // Default TaskScheduler implementation. This class is thread-safe.
27 class BASE_EXPORT TaskSchedulerImpl : public TaskScheduler {
28 public:
29 // Creates a TaskSchedulerImpl. CHECKs on failure to do so.
30 TaskSchedulerImpl();
31
32 // Destroying a TaskSchedulerImpl is not allowed in production; it is always
33 // leaked. In tests, it can only be destroyed after JoinForTesting() has
34 // returned.
35 ~TaskSchedulerImpl() override;
36
37 // TaskScheduler:
38 void PostTaskWithTraits(const tracked_objects::Location& from_here,
39 const TaskTraits& traits,
40 const Closure& task) override;
41 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits(
42 const TaskTraits& traits,
43 ExecutionMode execution_mode) override;
44 void Shutdown() override;
45
46 // Joins all threads of this scheduler. Tasks that are already running are
47 // allowed to complete their execution. This can only be called once.
48 void JoinForTesting();
49
50 private:
51 void Initialize();
52
53 // Returns the thread pool that runs Tasks with |traits|.
54 SchedulerThreadPool* GetThreadPoolForTraits(const TaskTraits& traits);
55
56 // Callback invoked when a non-single-thread |sequence| isn't empty after a
57 // worker thread pops a Task from it.
58 void ReEnqueueSequenceCallback(scoped_refptr<Sequence> sequence);
59
60 TaskTracker task_tracker_;
61 DelayedTaskManager delayed_task_manager_;
62
63 // Thread pool for BACKGROUND Tasks without file I/O.
64 std::unique_ptr<SchedulerThreadPoolImpl> background_thread_pool_;
65
66 // Thread pool for BACKGROUND Tasks with file I/O.
67 std::unique_ptr<SchedulerThreadPoolImpl> background_file_io_thread_pool_;
68
69 // Thread pool for USER_VISIBLE and USER_BLOCKING Tasks without file I/O.
70 std::unique_ptr<SchedulerThreadPoolImpl> normal_thread_pool_;
71
72 // Thread pool for USER_VISIBLE and USER_BLOCKING Tasks with file I/O.
73 std::unique_ptr<SchedulerThreadPoolImpl> normal_file_io_thread_pool_;
74
75 #if DCHECK_IS_ON()
76 // Signaled once JoinForTesting() has returned.
77 WaitableEvent join_for_testing_returned_;
78 #endif
79
80 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImpl);
81 };
82
83 } // namespace internal
84 } // namespace base
85
86 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698